diff options
Diffstat (limited to 'azalea/src')
| -rw-r--r-- | azalea/src/auto_respawn.rs | 3 | ||||
| -rw-r--r-- | azalea/src/bot.rs | 29 | ||||
| -rw-r--r-- | azalea/src/container.rs | 4 | ||||
| -rw-r--r-- | azalea/src/lib.rs | 12 | ||||
| -rw-r--r-- | azalea/src/pathfinder/mod.rs | 31 | ||||
| -rw-r--r-- | azalea/src/swarm/chat.rs | 15 | ||||
| -rw-r--r-- | azalea/src/swarm/events.rs | 5 | ||||
| -rw-r--r-- | azalea/src/swarm/mod.rs | 14 |
8 files changed, 61 insertions, 52 deletions
diff --git a/azalea/src/auto_respawn.rs b/azalea/src/auto_respawn.rs index d2973a2f..77a75b4b 100644 --- a/azalea/src/auto_respawn.rs +++ b/azalea/src/auto_respawn.rs @@ -1,6 +1,7 @@ use crate::app::{App, Plugin}; use azalea_client::packet_handling::DeathEvent; use azalea_client::respawn::{perform_respawn, PerformRespawnEvent}; +use bevy_app::Update; use bevy_ecs::prelude::*; /// A plugin that makes [`DeathEvent`]s send [`PerformRespawnEvent`]s. @@ -8,7 +9,7 @@ use bevy_ecs::prelude::*; pub struct AutoRespawnPlugin; impl Plugin for AutoRespawnPlugin { fn build(&self, app: &mut App) { - app.add_system(auto_respawn.before(perform_respawn)); + app.add_systems(Update, auto_respawn.before(perform_respawn)); } } diff --git a/azalea/src/bot.rs b/azalea/src/bot.rs index 13b33bb0..47c825ca 100644 --- a/azalea/src/bot.rs +++ b/azalea/src/bot.rs @@ -1,4 +1,4 @@ -use crate::app::{App, CoreSchedule, IntoSystemAppConfig, Plugin, PluginGroup, PluginGroupBuilder}; +use crate::app::{App, Plugin, PluginGroup, PluginGroupBuilder}; use crate::auto_respawn::AutoRespawnPlugin; use crate::container::ContainerPlugin; use crate::ecs::{ @@ -6,13 +6,15 @@ use crate::ecs::{ entity::Entity, event::EventReader, query::{With, Without}, - schedule::IntoSystemConfig, system::{Commands, Query}, }; use azalea_core::Vec3; use azalea_physics::{force_jump_listener, PhysicsSet}; use azalea_world::entity::{clamp_look_direction, EyeHeight, LookDirection}; use azalea_world::entity::{metadata::Player, Jumping, Local, Position}; +use bevy_app::{FixedUpdate, Update}; +use bevy_ecs::prelude::Event; +use bevy_ecs::schedule::IntoSystemConfigs; use std::f64::consts::PI; use crate::pathfinder::PathfinderPlugin; @@ -23,16 +25,17 @@ impl Plugin for BotPlugin { fn build(&self, app: &mut App) { app.add_event::<LookAtEvent>() .add_event::<JumpEvent>() - .add_systems(( - insert_bot, - look_at_listener - .before(force_jump_listener) - .before(clamp_look_direction), - jump_listener, - stop_jumping - .in_schedule(CoreSchedule::FixedUpdate) - .after(PhysicsSet), - )); + .add_systems( + Update, + ( + insert_bot, + look_at_listener + .before(force_jump_listener) + .before(clamp_look_direction), + jump_listener, + ), + ) + .add_systems(FixedUpdate, stop_jumping.after(PhysicsSet)); } } @@ -85,6 +88,7 @@ impl BotClientExt for azalea_client::Client { } /// Event to jump once. +#[derive(Event)] pub struct JumpEvent(pub Entity); fn jump_listener(mut query: Query<(&mut Jumping, &mut Bot)>, mut events: EventReader<JumpEvent>) { @@ -97,6 +101,7 @@ fn jump_listener(mut query: Query<(&mut Jumping, &mut Bot)>, mut events: EventRe } /// Make an entity look towards a certain position in the world. +#[derive(Event)] pub struct LookAtEvent { pub entity: Entity, /// The position we want the entity to be looking at. diff --git a/azalea/src/container.rs b/azalea/src/container.rs index fefcf189..dc0ba169 100644 --- a/azalea/src/container.rs +++ b/azalea/src/container.rs @@ -8,14 +8,14 @@ use azalea_client::{ use azalea_core::BlockPos; use azalea_inventory::{operations::ClickOperation, ItemSlot, Menu}; use azalea_protocol::packets::game::ClientboundGamePacket; -use bevy_app::{App, Plugin}; +use bevy_app::{App, Plugin, Update}; use bevy_ecs::{component::Component, prelude::EventReader, system::Commands}; use std::fmt::Debug; pub struct ContainerPlugin; impl Plugin for ContainerPlugin { fn build(&self, app: &mut App) { - app.add_system(handle_menu_opened_event); + app.add_systems(Update, handle_menu_opened_event); } } diff --git a/azalea/src/lib.rs b/azalea/src/lib.rs index ec967708..1c6966c5 100644 --- a/azalea/src/lib.rs +++ b/azalea/src/lib.rs @@ -10,7 +10,7 @@ pub mod pathfinder; pub mod prelude; pub mod swarm; -use app::{App, Plugin, PluginGroup}; +use app::{App, Plugins}; pub use azalea_auth as auth; pub use azalea_block as blocks; pub use azalea_brigadier as brigadier; @@ -148,16 +148,10 @@ where self.state = state; self } - /// Add a plugin to the client. - #[must_use] - pub fn add_plugin<T: Plugin>(mut self, plugin: T) -> Self { - self.app.add_plugin(plugin); - self - } /// Add a group of plugins to the client. #[must_use] - pub fn add_plugins<T: PluginGroup>(mut self, plugin_group: T) -> Self { - self.app.add_plugins(plugin_group); + pub fn add_plugins<M>(mut self, plugins: impl Plugins<M>) -> Self { + self.app.add_plugins(plugins); self } diff --git a/azalea/src/pathfinder/mod.rs b/azalea/src/pathfinder/mod.rs index b7ed222d..9547d263 100644 --- a/azalea/src/pathfinder/mod.rs +++ b/azalea/src/pathfinder/mod.rs @@ -5,13 +5,12 @@ use crate::bot::{JumpEvent, LookAtEvent}; use crate::pathfinder::astar::a_star; use crate::{SprintDirection, WalkDirection}; -use crate::app::{App, CoreSchedule, IntoSystemAppConfig, Plugin}; +use crate::app::{App, Plugin}; use crate::ecs::{ component::Component, entity::Entity, event::{EventReader, EventWriter}, query::{With, Without}, - schedule::IntoSystemConfig, system::{Commands, Query, Res}, }; use astar::Edge; @@ -24,6 +23,9 @@ use azalea_world::{ entity::{Physics, Position, WorldName}, InstanceContainer, }; +use bevy_app::{FixedUpdate, Update}; +use bevy_ecs::prelude::Event; +use bevy_ecs::schedule::IntoSystemConfigs; use bevy_tasks::{AsyncComputeTaskPool, Task}; use futures_lite::future; use log::{debug, error}; @@ -36,17 +38,20 @@ impl Plugin for PathfinderPlugin { fn build(&self, app: &mut App) { app.add_event::<GotoEvent>() .add_event::<PathFoundEvent>() - .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_systems( + FixedUpdate, + // putting systems in the FixedUpdate schedule makes them run every Minecraft tick + // (every 50 milliseconds). + tick_execute_path.before(PhysicsSet), ) - .add_system(goto_listener) - .add_system(add_default_pathfinder) - .add_system(handle_tasks.before(path_found_listener)) - .add_system(path_found_listener); + .add_systems( + Update, + ( + goto_listener, + add_default_pathfinder, + (handle_tasks, path_found_listener).chain(), + ), + ); } } @@ -84,10 +89,12 @@ impl PathfinderClientExt for azalea_client::Client { }); } } +#[derive(Event)] pub struct GotoEvent { pub entity: Entity, pub goal: Arc<dyn Goal + Send + Sync>, } +#[derive(Event)] pub struct PathFoundEvent { pub entity: Entity, pub path: VecDeque<Node>, diff --git a/azalea/src/swarm/chat.rs b/azalea/src/swarm/chat.rs index 303ce35b..6cf4d6b6 100644 --- a/azalea/src/swarm/chat.rs +++ b/azalea/src/swarm/chat.rs @@ -20,7 +20,8 @@ use crate::ecs::{ system::{Commands, Query, Res, ResMut, Resource}, }; use azalea_client::chat::{ChatPacket, ChatReceivedEvent}; -use bevy_app::{App, Plugin}; +use bevy_app::{App, Plugin, Update}; +use bevy_ecs::prelude::Event; use std::collections::VecDeque; use super::{Swarm, SwarmEvent}; @@ -30,7 +31,10 @@ pub struct SwarmChatPlugin; impl Plugin for SwarmChatPlugin { fn build(&self, app: &mut App) { app.add_event::<NewChatMessageEvent>() - .add_systems((chat_listener, update_min_index_and_shrink_queue).chain()) + .add_systems( + Update, + (chat_listener, update_min_index_and_shrink_queue).chain(), + ) .insert_resource(GlobalChatState { chat_queue: VecDeque::new(), chat_min_index: 0, @@ -44,7 +48,7 @@ pub struct ClientChatState { } /// A chat message that no other bots have seen yet was received by a bot. -#[derive(Debug)] +#[derive(Event, Debug)] pub struct NewChatMessageEvent(ChatPacket); #[derive(Resource)] @@ -160,7 +164,10 @@ mod tests { // event mangement in drain_events app.init_resource::<Events<ChatReceivedEvent>>() .init_resource::<Events<NewChatMessageEvent>>() - .add_systems((chat_listener, update_min_index_and_shrink_queue).chain()) + .add_systems( + Update, + (chat_listener, update_min_index_and_shrink_queue).chain(), + ) .insert_resource(GlobalChatState { chat_queue: VecDeque::new(), chat_min_index: 0, diff --git a/azalea/src/swarm/events.rs b/azalea/src/swarm/events.rs index 62593029..b4752abf 100644 --- a/azalea/src/swarm/events.rs +++ b/azalea/src/swarm/events.rs @@ -1,6 +1,6 @@ use azalea_client::LocalPlayer; use azalea_world::entity::MinecraftEntityId; -use bevy_app::{App, Plugin}; +use bevy_app::{App, Plugin, Update}; use bevy_ecs::prelude::*; use derive_more::{Deref, DerefMut}; @@ -8,12 +8,13 @@ pub struct SwarmPlugin; impl Plugin for SwarmPlugin { fn build(&self, app: &mut App) { app.add_event::<SwarmReadyEvent>() - .add_system(check_ready) + .add_systems(Update, check_ready) .init_resource::<IsSwarmReady>(); } } /// All the bots from the swarm are now in the world. +#[derive(Event)] pub struct SwarmReadyEvent; #[derive(Default, Resource, Deref, DerefMut)] diff --git a/azalea/src/swarm/mod.rs b/azalea/src/swarm/mod.rs index ed70dacd..13741aa0 100644 --- a/azalea/src/swarm/mod.rs +++ b/azalea/src/swarm/mod.rs @@ -14,7 +14,7 @@ use azalea_protocol::{ ServerAddress, }; use azalea_world::InstanceContainer; -use bevy_app::{App, Plugin, PluginGroup, PluginGroupBuilder}; +use bevy_app::{App, PluginGroup, PluginGroupBuilder, Plugins}; use bevy_ecs::{component::Component, entity::Entity, system::Resource, world::World}; use futures::future::join_all; use log::error; @@ -234,16 +234,10 @@ where self } - /// Add a plugin to the swarm. + /// Add one or more plugins to this swarm. #[must_use] - pub fn add_plugin<T: Plugin>(mut self, plugin: T) -> Self { - self.app.add_plugin(plugin); - self - } - /// Add a group of plugins to the swarm. - #[must_use] - pub fn add_plugins<T: PluginGroup>(mut self, plugin_group: T) -> Self { - self.app.add_plugins(plugin_group); + pub fn add_plugins<M>(mut self, plugins: impl Plugins<M>) -> Self { + self.app.add_plugins(plugins); self } |
