aboutsummaryrefslogtreecommitdiff
path: root/azalea
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
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')
-rw-r--r--azalea/Cargo.toml28
-rwxr-xr-xazalea/examples/pvp.rs2
-rw-r--r--azalea/examples/testbot.rs18
-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
11 files changed, 84 insertions, 86 deletions
diff --git a/azalea/Cargo.toml b/azalea/Cargo.toml
index f64959ed..dd2bb46c 100644
--- a/azalea/Cargo.toml
+++ b/azalea/Cargo.toml
@@ -8,31 +8,31 @@ version = "0.6.0"
[package.metadata.release]
pre-release-replacements = [
- {file = "README.md", search = "`azalea = \"[a-z0-9\\.-]+\"`", replace = "`azalea = \"{{version}}\"`"},
+ { file = "README.md", search = "`azalea = \"[a-z0-9\\.-]+\"`", replace = "`azalea = \"{{version}}\"`" },
]
[dependencies]
anyhow = "^1.0.65"
async-trait = "0.1.58"
-azalea-block = {version = "0.6.0", path = "../azalea-block"}
-azalea-chat = {version = "0.6.0", path = "../azalea-chat"}
-azalea-client = {version = "0.6.0", path = "../azalea-client"}
-azalea-core = {version = "0.6.0", path = "../azalea-core"}
-azalea-ecs = {version = "0.6.0", path = "../azalea-ecs"}
-azalea-physics = {version = "0.6.0", path = "../azalea-physics"}
-azalea-protocol = {version = "0.6.0", path = "../azalea-protocol"}
-azalea-registry = {version = "0.6.0", path = "../azalea-registry"}
-azalea-world = {version = "0.6.0", path = "../azalea-world"}
-bevy_tasks = "0.9.1"
-derive_more = {version = "0.99.17", features = ["deref", "deref_mut"]}
+azalea-block = { version = "0.6.0", path = "../azalea-block" }
+azalea-chat = { version = "0.6.0", path = "../azalea-chat" }
+azalea-client = { version = "0.6.0", path = "../azalea-client" }
+azalea-core = { version = "0.6.0", path = "../azalea-core" }
+azalea-physics = { version = "0.6.0", path = "../azalea-physics" }
+azalea-protocol = { version = "0.6.0", path = "../azalea-protocol" }
+azalea-registry = { version = "0.6.0", path = "../azalea-registry" }
+azalea-world = { version = "0.6.0", path = "../azalea-world" }
+bevy_app = "0.10.0"
+bevy_ecs = "0.10.0"
+bevy_tasks = "0.10.0"
+derive_more = { version = "0.99.17", features = ["deref", "deref_mut"] }
futures = "0.3.25"
futures-lite = "1.12.0"
log = "0.4.17"
nohash-hasher = "0.2.0"
num-traits = "0.2.15"
-parking_lot = {version = "^0.12.1", features = ["deadlock_detection"]}
+parking_lot = { version = "^0.12.1", features = ["deadlock_detection"] }
priority-queue = "1.3.0"
thiserror = "^1.0.37"
tokio = "^1.24.2"
uuid = "1.2.2"
-
diff --git a/azalea/examples/pvp.rs b/azalea/examples/pvp.rs
index 180b6577..fb5a768d 100755
--- a/azalea/examples/pvp.rs
+++ b/azalea/examples/pvp.rs
@@ -1,9 +1,9 @@
use std::time::Duration;
+use azalea::ecs::query::With;
use azalea::entity::metadata::Player;
use azalea::{pathfinder, Account, Client, Event, GameProfileComponent};
use azalea::{prelude::*, swarm::prelude::*};
-use azalea_ecs::query::With;
#[tokio::main]
async fn main() {
diff --git a/azalea/examples/testbot.rs b/azalea/examples/testbot.rs
index dd1629ae..7b7b32b0 100644
--- a/azalea/examples/testbot.rs
+++ b/azalea/examples/testbot.rs
@@ -52,17 +52,17 @@ async fn main() -> anyhow::Result<()> {
}
loop {
- let e = SwarmBuilder::new()
- .add_accounts(accounts.clone())
- .set_handler(handle)
- .set_swarm_handler(swarm_handle)
- .join_delay(Duration::from_millis(1000))
- .start("localhost")
- .await;
- // let e = azalea::ClientBuilder::new()
+ // let e = SwarmBuilder::new()
+ // .add_accounts(accounts.clone())
// .set_handler(handle)
- // .start(Account::offline("bot"), "localhost")
+ // .set_swarm_handler(swarm_handle)
+ // .join_delay(Duration::from_millis(1000))
+ // .start("localhost")
// .await;
+ let e = azalea::ClientBuilder::new()
+ .set_handler(handle)
+ .start(Account::offline("bot"), "localhost")
+ .await;
eprintln!("{e:?}");
}
}
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>>>,