aboutsummaryrefslogtreecommitdiff
path: root/azalea/src
diff options
context:
space:
mode:
authormat <27899617+mat-1@users.noreply.github.com>2023-03-07 14:14:36 -0600
committerGitHub <noreply@github.com>2023-03-07 14:14:36 -0600
commit719379a8a76ab0685f2bd14bebe2f0cd1e97f06b (patch)
treece5d6c62bc36fb1d1ec31083bc8e81a0109c12df /azalea/src
parentbf4ff517890cad3ff4e36b4b78959504192e5374 (diff)
downloadazalea-drasl-719379a8a76ab0685f2bd14bebe2f0cd1e97f06b.tar.xz
Bevy 0.10 (#79)
* replace 0.9.1 with 0.10.0 * start migrating to bevy .10 * well it compiles * doesn't immediately panic * remove unused imports * fmt * delete azalea-ecs * make RelativeEntityUpdate an EntityCommand * fix a doc test * explain what FixedUpdate does
Diffstat (limited to 'azalea/src')
-rw-r--r--azalea/src/bot.rs26
-rw-r--r--azalea/src/lib.rs15
-rw-r--r--azalea/src/pathfinder/mod.rs20
-rw-r--r--azalea/src/pathfinder/moves.rs20
-rw-r--r--azalea/src/prelude.rs4
-rw-r--r--azalea/src/swarm/chat.rs18
-rw-r--r--azalea/src/swarm/events.rs8
-rw-r--r--azalea/src/swarm/mod.rs11
8 files changed, 60 insertions, 62 deletions
diff --git a/azalea/src/bot.rs b/azalea/src/bot.rs
index ce5b9fdc..a45ae28d 100644
--- a/azalea/src/bot.rs
+++ b/azalea/src/bot.rs
@@ -1,14 +1,14 @@
-use azalea_core::Vec3;
-use azalea_ecs::{
- app::{App, Plugin, PluginGroup, PluginGroupBuilder},
+use crate::app::{App, CoreSchedule, IntoSystemAppConfig, Plugin, PluginGroup, PluginGroupBuilder};
+use crate::ecs::{
component::Component,
entity::Entity,
event::EventReader,
query::{With, Without},
- schedule::IntoSystemDescriptor,
+ schedule::IntoSystemConfig,
system::{Commands, Query},
- AppTickExt,
};
+use azalea_core::Vec3;
+use azalea_physics::{force_jump_listener, PhysicsSet};
use azalea_world::entity::{metadata::Player, set_rotation, Jumping, Local, Physics, Position};
use std::f64::consts::PI;
@@ -20,14 +20,14 @@ impl Plugin for BotPlugin {
fn build(&self, app: &mut App) {
app.add_event::<LookAtEvent>()
.add_event::<JumpEvent>()
- .add_system(insert_bot)
- .add_system(
- look_at_listener
- .before("force_jump_listener")
- .before(azalea_world::entity::update_bounding_box),
- )
- .add_system(jump_listener.label("jump_listener"))
- .add_tick_system(stop_jumping.after("ai_step"));
+ .add_systems((
+ insert_bot,
+ look_at_listener.before(force_jump_listener),
+ jump_listener,
+ stop_jumping
+ .in_schedule(CoreSchedule::FixedUpdate)
+ .after(PhysicsSet),
+ ));
}
}
diff --git a/azalea/src/lib.rs b/azalea/src/lib.rs
index 827c3904..c58ca7b1 100644
--- a/azalea/src/lib.rs
+++ b/azalea/src/lib.rs
@@ -6,18 +6,15 @@ pub mod pathfinder;
pub mod prelude;
pub mod swarm;
+use app::{App, Plugin, PluginGroup};
pub use azalea_block as blocks;
pub use azalea_client::*;
pub use azalea_core::{BlockPos, Vec3};
-use azalea_ecs::{
- app::{App, Plugin},
- component::Component,
-};
pub use azalea_protocol as protocol;
pub use azalea_registry::EntityKind;
-pub use azalea_world::{entity, World};
+pub use azalea_world::{entity, Instance};
use bot::DefaultBotPlugins;
-use ecs::app::PluginGroup;
+use ecs::component::Component;
use futures::Future;
use protocol::{
resolver::{self, ResolverError},
@@ -26,7 +23,10 @@ use protocol::{
use thiserror::Error;
use tokio::sync::mpsc;
-pub type HandleFn<Fut, S> = fn(Client, Event, S) -> Fut;
+pub use bevy_app as app;
+pub use bevy_ecs as ecs;
+
+pub type HandleFn<Fut, S> = fn(Client, azalea_client::Event, S) -> Fut;
#[derive(Error, Debug)]
pub enum StartError {
@@ -142,6 +142,7 @@ where
// An event that causes the schedule to run. This is only used internally.
let (run_schedule_sender, run_schedule_receiver) = mpsc::unbounded_channel();
+
let ecs_lock = start_ecs(self.app, run_schedule_receiver, run_schedule_sender.clone());
let (bot, mut rx) = Client::start_client(
diff --git a/azalea/src/pathfinder/mod.rs b/azalea/src/pathfinder/mod.rs
index 8289d9c4..61a92038 100644
--- a/azalea/src/pathfinder/mod.rs
+++ b/azalea/src/pathfinder/mod.rs
@@ -4,18 +4,18 @@ mod mtdstarlite;
use crate::bot::{JumpEvent, LookAtEvent};
use crate::{SprintDirection, WalkDirection};
-use azalea_client::{StartSprintEvent, StartWalkEvent};
-use azalea_core::{BlockPos, CardinalDirection};
-use azalea_ecs::{
- app::{App, Plugin},
+use crate::app::{App, CoreSchedule, IntoSystemAppConfig, Plugin};
+use crate::ecs::{
component::Component,
entity::Entity,
event::{EventReader, EventWriter},
query::{With, Without},
- schedule::IntoSystemDescriptor,
+ schedule::IntoSystemConfig,
system::{Commands, Query, Res},
- AppTickExt,
};
+use azalea_client::{StartSprintEvent, StartWalkEvent};
+use azalea_core::{BlockPos, CardinalDirection};
+use azalea_physics::PhysicsSet;
use azalea_world::entity::metadata::Player;
use azalea_world::entity::Local;
use azalea_world::{
@@ -36,7 +36,13 @@ impl Plugin for PathfinderPlugin {
fn build(&self, app: &mut App) {
app.add_event::<GotoEvent>()
.add_event::<PathFoundEvent>()
- .add_tick_system(tick_execute_path.before("ai_step"))
+ .add_system(
+ // Adding `.in_schedule(CoreSchedule::FixedUpdate)` makes a system run every
+ // Minecraft tick (every 50 milliseconds).
+ tick_execute_path
+ .in_schedule(CoreSchedule::FixedUpdate)
+ .before(PhysicsSet),
+ )
.add_system(goto_listener)
.add_system(add_default_pathfinder)
.add_system(handle_tasks.before(path_found_listener))
diff --git a/azalea/src/pathfinder/moves.rs b/azalea/src/pathfinder/moves.rs
index 011d8349..3639c091 100644
--- a/azalea/src/pathfinder/moves.rs
+++ b/azalea/src/pathfinder/moves.rs
@@ -1,10 +1,10 @@
use super::{Node, VerticalVel};
use azalea_core::{BlockPos, CardinalDirection};
use azalea_physics::collision::{self, BlockWithShape};
-use azalea_world::World;
+use azalea_world::Instance;
/// whether this block is passable
-fn is_block_passable(pos: &BlockPos, world: &World) -> bool {
+fn is_block_passable(pos: &BlockPos, world: &Instance) -> bool {
if let Some(block) = world.chunks.get_block_state(pos) {
block.shape() == &collision::empty_shape()
} else {
@@ -13,7 +13,7 @@ fn is_block_passable(pos: &BlockPos, world: &World) -> bool {
}
/// whether this block has a solid hitbox (i.e. we can stand on it)
-fn is_block_solid(pos: &BlockPos, world: &World) -> bool {
+fn is_block_solid(pos: &BlockPos, world: &Instance) -> bool {
if let Some(block) = world.chunks.get_block_state(pos) {
block.shape() == &collision::block_shape()
} else {
@@ -22,14 +22,14 @@ fn is_block_solid(pos: &BlockPos, world: &World) -> bool {
}
/// Whether this block and the block above are passable
-fn is_passable(pos: &BlockPos, world: &World) -> bool {
+fn is_passable(pos: &BlockPos, world: &Instance) -> bool {
is_block_passable(pos, world) && is_block_passable(&pos.up(1), world)
}
/// Whether we can stand in this position. Checks if the block below is solid,
/// and that the two blocks above that are passable.
-fn is_standable(pos: &BlockPos, world: &World) -> bool {
+fn is_standable(pos: &BlockPos, world: &Instance) -> bool {
is_block_solid(&pos.down(1), world) && is_passable(pos, world)
}
@@ -37,7 +37,7 @@ const JUMP_COST: f32 = 0.5;
const WALK_ONE_BLOCK_COST: f32 = 1.0;
pub trait Move: Send + Sync {
- fn cost(&self, world: &World, node: &Node) -> f32;
+ fn cost(&self, world: &Instance, node: &Node) -> f32;
/// Returns by how much the entity's position should be changed when this
/// move is executed.
fn offset(&self) -> BlockPos;
@@ -51,7 +51,7 @@ pub trait Move: Send + Sync {
pub struct ForwardMove(pub CardinalDirection);
impl Move for ForwardMove {
- fn cost(&self, world: &World, node: &Node) -> f32 {
+ fn cost(&self, world: &Instance, node: &Node) -> f32 {
if is_standable(&(node.pos + self.offset()), world)
&& node.vertical_vel == VerticalVel::None
{
@@ -67,7 +67,7 @@ impl Move for ForwardMove {
pub struct AscendMove(pub CardinalDirection);
impl Move for AscendMove {
- fn cost(&self, world: &World, node: &Node) -> f32 {
+ fn cost(&self, world: &Instance, node: &Node) -> f32 {
if node.vertical_vel == VerticalVel::None
&& is_block_passable(&node.pos.up(2), world)
&& is_standable(&(node.pos + self.offset()), world)
@@ -89,7 +89,7 @@ impl Move for AscendMove {
}
pub struct DescendMove(pub CardinalDirection);
impl Move for DescendMove {
- fn cost(&self, world: &World, node: &Node) -> f32 {
+ fn cost(&self, world: &Instance, node: &Node) -> f32 {
// check whether 3 blocks vertically forward are passable
if node.vertical_vel == VerticalVel::None
&& is_standable(&(node.pos + self.offset()), world)
@@ -112,7 +112,7 @@ impl Move for DescendMove {
}
pub struct DiagonalMove(pub CardinalDirection);
impl Move for DiagonalMove {
- fn cost(&self, world: &World, node: &Node) -> f32 {
+ fn cost(&self, world: &Instance, node: &Node) -> f32 {
if node.vertical_vel != VerticalVel::None {
return f32::INFINITY;
}
diff --git a/azalea/src/prelude.rs b/azalea/src/prelude.rs
index a9ae6093..b1a1fed3 100644
--- a/azalea/src/prelude.rs
+++ b/azalea/src/prelude.rs
@@ -3,4 +3,6 @@
pub use crate::{bot::BotClientExt, pathfinder::PathfinderClientExt, ClientBuilder};
pub use azalea_client::{Account, Client, Event};
-pub use azalea_ecs::{component::Component, system::Resource};
+// this is necessary to make the macros that reference bevy_ecs work
+pub use crate::ecs as bevy_ecs;
+pub use crate::ecs::{component::Component, system::Resource};
diff --git a/azalea/src/swarm/chat.rs b/azalea/src/swarm/chat.rs
index 18c27cd6..303ce35b 100644
--- a/azalea/src/swarm/chat.rs
+++ b/azalea/src/swarm/chat.rs
@@ -13,14 +13,14 @@
// in Swarm that's set to the smallest index of all the bots, and we remove all
// messages from the queue that are before that index.
-use azalea_client::chat::{ChatPacket, ChatReceivedEvent};
-use azalea_ecs::{
- app::{App, Plugin},
+use crate::ecs::{
component::Component,
event::{EventReader, EventWriter},
- schedule::IntoSystemDescriptor,
+ schedule::IntoSystemConfigs,
system::{Commands, Query, Res, ResMut, Resource},
};
+use azalea_client::chat::{ChatPacket, ChatReceivedEvent};
+use bevy_app::{App, Plugin};
use std::collections::VecDeque;
use super::{Swarm, SwarmEvent};
@@ -30,8 +30,7 @@ pub struct SwarmChatPlugin;
impl Plugin for SwarmChatPlugin {
fn build(&self, app: &mut App) {
app.add_event::<NewChatMessageEvent>()
- .add_system(chat_listener.label("chat_listener"))
- .add_system(update_min_index_and_shrink_queue.after("chat_listener"))
+ .add_systems((chat_listener, update_min_index_and_shrink_queue).chain())
.insert_resource(GlobalChatState {
chat_queue: VecDeque::new(),
chat_min_index: 0,
@@ -151,7 +150,7 @@ fn update_min_index_and_shrink_queue(
#[cfg(test)]
mod tests {
- use azalea_ecs::{ecs::Ecs, event::Events, system::SystemState};
+ use bevy_ecs::{event::Events, prelude::World, system::SystemState};
use super::*;
@@ -161,8 +160,7 @@ mod tests {
// event mangement in drain_events
app.init_resource::<Events<ChatReceivedEvent>>()
.init_resource::<Events<NewChatMessageEvent>>()
- .add_system(chat_listener.label("chat_listener"))
- .add_system(update_min_index_and_shrink_queue.after("chat_listener"))
+ .add_systems((chat_listener, update_min_index_and_shrink_queue).chain())
.insert_resource(GlobalChatState {
chat_queue: VecDeque::new(),
chat_min_index: 0,
@@ -170,7 +168,7 @@ mod tests {
app
}
- fn drain_events(ecs: &mut Ecs) -> Vec<ChatPacket> {
+ fn drain_events(ecs: &mut World) -> Vec<ChatPacket> {
let mut system_state: SystemState<ResMut<Events<NewChatMessageEvent>>> =
SystemState::new(ecs);
let mut events = system_state.get_mut(ecs);
diff --git a/azalea/src/swarm/events.rs b/azalea/src/swarm/events.rs
index 81d8c731..62593029 100644
--- a/azalea/src/swarm/events.rs
+++ b/azalea/src/swarm/events.rs
@@ -1,11 +1,7 @@
use azalea_client::LocalPlayer;
-use azalea_ecs::{
- app::{App, Plugin},
- event::EventWriter,
- query::With,
- system::{Query, ResMut, Resource},
-};
use azalea_world::entity::MinecraftEntityId;
+use bevy_app::{App, Plugin};
+use bevy_ecs::prelude::*;
use derive_more::{Deref, DerefMut};
pub struct SwarmPlugin;
diff --git a/azalea/src/swarm/mod.rs b/azalea/src/swarm/mod.rs
index c0d9cb56..97020153 100644
--- a/azalea/src/swarm/mod.rs
+++ b/azalea/src/swarm/mod.rs
@@ -6,19 +6,14 @@ pub mod prelude;
use crate::{bot::DefaultBotPlugins, HandleFn};
use azalea_client::{chat::ChatPacket, init_ecs_app, start_ecs, Account, Client, Event, JoinError};
-use azalea_ecs::{
- app::{App, Plugin, PluginGroup, PluginGroupBuilder},
- component::Component,
- ecs::Ecs,
- entity::Entity,
- system::Resource,
-};
use azalea_protocol::{
connect::ConnectionError,
resolver::{self, ResolverError},
ServerAddress,
};
use azalea_world::WorldContainer;
+use bevy_app::{App, Plugin, PluginGroup, PluginGroupBuilder};
+use bevy_ecs::{component::Component, entity::Entity, system::Resource, world::World};
use futures::future::join_all;
use log::error;
use parking_lot::{Mutex, RwLock};
@@ -35,7 +30,7 @@ use tokio::sync::mpsc;
/// It's used to make the [`Swarm::add`] function work.
#[derive(Clone, Resource)]
pub struct Swarm {
- pub ecs_lock: Arc<Mutex<Ecs>>,
+ pub ecs_lock: Arc<Mutex<World>>,
bots: Arc<Mutex<HashMap<Entity, Client>>>,