diff options
| author | mat <git@matdoes.dev> | 2025-09-28 13:10:04 -0545 |
|---|---|---|
| committer | mat <git@matdoes.dev> | 2025-09-28 13:10:04 -0545 |
| commit | 2c8b7c5c2c9297273abfba8f7743f1bc25f166b1 (patch) | |
| tree | 3d3aded400100c136287fa59293ce26c61644d00 /azalea | |
| parent | e2ed19c1ed92f0dccc881d835d9ac6e0f7f834c0 (diff) | |
| download | azalea-drasl-2c8b7c5c2c9297273abfba8f7743f1bc25f166b1.tar.xz | |
upgrade bevy to 0.17.0-rc.2
Diffstat (limited to 'azalea')
| -rw-r--r-- | azalea/examples/nearest_entity.rs | 4 | ||||
| -rw-r--r-- | azalea/examples/testbot/commands/debug.rs | 24 | ||||
| -rw-r--r-- | azalea/src/accept_resource_packs.rs | 2 | ||||
| -rw-r--r-- | azalea/src/auto_respawn.rs | 4 | ||||
| -rw-r--r-- | azalea/src/auto_tool.rs | 12 | ||||
| -rw-r--r-- | azalea/src/bot.rs | 17 | ||||
| -rw-r--r-- | azalea/src/container.rs | 15 | ||||
| -rw-r--r-- | azalea/src/nearest_entity.rs | 4 | ||||
| -rw-r--r-- | azalea/src/pathfinder/debug.rs | 6 | ||||
| -rw-r--r-- | azalea/src/pathfinder/goto_event.rs | 4 | ||||
| -rw-r--r-- | azalea/src/pathfinder/mod.rs | 55 | ||||
| -rw-r--r-- | azalea/src/pathfinder/moves/mod.rs | 14 | ||||
| -rw-r--r-- | azalea/src/pathfinder/simulation.rs | 5 | ||||
| -rw-r--r-- | azalea/src/pathfinder/tests.rs | 4 | ||||
| -rw-r--r-- | azalea/src/swarm/chat.rs | 53 | ||||
| -rw-r--r-- | azalea/src/swarm/events.rs | 6 |
16 files changed, 113 insertions, 116 deletions
diff --git a/azalea/examples/nearest_entity.rs b/azalea/examples/nearest_entity.rs index 80bb544d..51aa26f6 100644 --- a/azalea/examples/nearest_entity.rs +++ b/azalea/examples/nearest_entity.rs @@ -12,7 +12,7 @@ use azalea_entity::{ }; use bevy_app::Plugin; use bevy_ecs::{ - prelude::{Entity, EventWriter}, + prelude::{Entity, MessageWriter}, query::With, system::Query, }; @@ -39,7 +39,7 @@ fn look_at_everything( bots: Query<Entity, (With<LocalEntity>, With<Player>)>, entities: EntityFinder, entity_positions: Query<(&Position, Option<&EntityDimensions>)>, - mut look_at_event: EventWriter<LookAtEvent>, + mut look_at_event: MessageWriter<LookAtEvent>, ) { for bot_id in bots.iter() { let Some(entity) = entities.nearest_to_entity(bot_id, 16.0) else { diff --git a/azalea/examples/testbot/commands/debug.rs b/azalea/examples/testbot/commands/debug.rs index 3cdf4cf2..b98d737f 100644 --- a/azalea/examples/testbot/commands/debug.rs +++ b/azalea/examples/testbot/commands/debug.rs @@ -18,7 +18,7 @@ use azalea_entity::{EntityKindComponent, EntityUuid, metadata}; use azalea_inventory::components::MaxStackSize; use azalea_world::InstanceContainer; use bevy_app::AppExit; -use bevy_ecs::{event::Events, query::With}; +use bevy_ecs::{message::Messages, query::With, world::EntityRef}; use parking_lot::Mutex; use super::{CommandSource, Ctx}; @@ -246,21 +246,23 @@ pub fn register(commands: &mut CommandDispatcher<Mutex<CommandSource>>) { thread::sleep(Duration::from_secs(1)); // dump the ecs - let ecs = ecs.lock(); + let mut ecs = ecs.lock(); let report_path = env::temp_dir().join("azalea-ecs-leak-report.txt"); let mut report = File::create(&report_path).unwrap(); - for entity in ecs.iter_entities() { + let mut query = ecs.query::<EntityRef>(); + for entity in query.iter(& ecs) { writeln!(report, "Entity: {}", entity.id()).unwrap(); let archetype = entity.archetype(); let component_count = archetype.component_count(); let component_names = archetype .components() - .map(|c| ecs.components().get_info(c).unwrap().name()) + .iter() + .map(|c| ecs.components().get_info(*c).unwrap().name().to_string()) .collect::<Vec<_>>(); writeln!( report, @@ -274,12 +276,12 @@ pub fn register(commands: &mut CommandDispatcher<Mutex<CommandSource>>) { for (info, _) in ecs.iter_resources() { - let name = info.name(); + let name = info.name().to_string(); writeln!(report, "Resource: {name}").unwrap(); // writeln!(report, "- Size: {} bytes", // info.layout().size()).unwrap(); - match name { + match name.as_ref() { "azalea_world::container::InstanceContainer" => { let instance_container = ecs.resource::<InstanceContainer>(); @@ -311,12 +313,12 @@ pub fn register(commands: &mut CommandDispatcher<Mutex<CommandSource>>) { } } } - "bevy_ecs::event::collections::Events<azalea_client::packet::game::ReceivePacketEvent>" => { - let events = ecs.resource::<Events<game::ReceiveGamePacketEvent>>(); + "bevy_ecs::message::Messages<azalea_client::packet::game::ReceivePacketEvent>" => { + let events = ecs.resource::<Messages<game::ReceiveGamePacketEvent>>(); writeln!(report, "- Event count: {}", events.len()).unwrap(); } - "bevy_ecs::event::collections::Events<azalea_client::chunks::ReceiveChunkEvent>" => { - let events = ecs.resource::<Events<ReceiveChunkEvent>>(); + "bevy_ecs::message::Messages<azalea_client::chunks::ReceiveChunkEvent>" => { + let events = ecs.resource::<Messages<ReceiveChunkEvent>>(); writeln!(report, "- Event count: {}", events.len()).unwrap(); } @@ -340,7 +342,7 @@ pub fn register(commands: &mut CommandDispatcher<Mutex<CommandSource>>) { thread::spawn(move || { thread::sleep(Duration::from_secs(1)); - source.lock().bot.ecs.lock().send_event(AppExit::Success); + source.lock().bot.ecs.lock().write_message(AppExit::Success); }); 1 diff --git a/azalea/src/accept_resource_packs.rs b/azalea/src/accept_resource_packs.rs index f211f532..d67ada18 100644 --- a/azalea/src/accept_resource_packs.rs +++ b/azalea/src/accept_resource_packs.rs @@ -37,7 +37,7 @@ impl Plugin for AcceptResourcePacksPlugin { } fn accept_resource_pack( - mut events: EventReader<ResourcePackEvent>, + mut events: MessageReader<ResourcePackEvent>, mut commands: Commands, query_in_config_state: Query<Option<&InConfigState>>, ) { diff --git a/azalea/src/auto_respawn.rs b/azalea/src/auto_respawn.rs index 6e970a71..1b74418f 100644 --- a/azalea/src/auto_respawn.rs +++ b/azalea/src/auto_respawn.rs @@ -22,8 +22,8 @@ impl Plugin for AutoRespawnPlugin { } fn auto_respawn( - mut events: EventReader<DeathEvent>, - mut perform_respawn_events: EventWriter<PerformRespawnEvent>, + mut events: MessageReader<DeathEvent>, + mut perform_respawn_events: MessageWriter<PerformRespawnEvent>, ) { for event in events.read() { perform_respawn_events.write(PerformRespawnEvent { diff --git a/azalea/src/auto_tool.rs b/azalea/src/auto_tool.rs index 3d8d6e36..e7eb614d 100644 --- a/azalea/src/auto_tool.rs +++ b/azalea/src/auto_tool.rs @@ -19,12 +19,12 @@ pub trait AutoToolClientExt { impl AutoToolClientExt for Client { fn best_tool_in_hotbar_for_block(&self, block: BlockState) -> BestToolResult { - let mut ecs = self.ecs.lock(); - let (inventory, physics, fluid_on_eyes) = - self.query::<(&Inventory, &Physics, &FluidOnEyes)>(&mut ecs); - let menu = &inventory.inventory_menu; - - accurate_best_tool_in_hotbar_for_block(block, menu, physics, fluid_on_eyes) + self.query_self::<(&Inventory, &Physics, &FluidOnEyes), _>( + |(inventory, physics, fluid_on_eyes)| { + let menu = &inventory.inventory_menu; + accurate_best_tool_in_hotbar_for_block(block, menu, physics, fluid_on_eyes) + }, + ) } async fn mine_with_auto_tool(&self, block_pos: BlockPos) { diff --git a/azalea/src/bot.rs b/azalea/src/bot.rs index b037ed14..5523b7b2 100644 --- a/azalea/src/bot.rs +++ b/azalea/src/bot.rs @@ -26,7 +26,6 @@ use crate::{ ecs::{ component::Component, entity::Entity, - event::EventReader, query::{With, Without}, system::{Commands, Query}, }, @@ -37,8 +36,8 @@ use crate::{ pub struct BotPlugin; impl Plugin for BotPlugin { fn build(&self, app: &mut App) { - app.add_event::<LookAtEvent>() - .add_event::<JumpEvent>() + app.add_message::<LookAtEvent>() + .add_message::<JumpEvent>() .add_systems( Update, ( @@ -108,14 +107,14 @@ pub trait BotClientExt { impl BotClientExt for azalea_client::Client { fn jump(&self) { let mut ecs = self.ecs.lock(); - ecs.send_event(JumpEvent { + ecs.write_message(JumpEvent { entity: self.entity, }); } fn look_at(&self, position: Vec3) { let mut ecs = self.ecs.lock(); - ecs.send_event(LookAtEvent { + ecs.write_message(LookAtEvent { entity: self.entity, position, }); @@ -200,14 +199,14 @@ impl BotClientExt for azalea_client::Client { } /// Event to jump once. -#[derive(Event)] +#[derive(Message)] pub struct JumpEvent { pub entity: Entity, } pub fn jump_listener( mut query: Query<(&mut Jumping, &mut Bot)>, - mut events: EventReader<JumpEvent>, + mut events: MessageReader<JumpEvent>, ) { for event in events.read() { if let Ok((mut jumping, mut bot)) = query.get_mut(event.entity) { @@ -218,14 +217,14 @@ pub fn jump_listener( } /// Make an entity look towards a certain position in the world. -#[derive(Event)] +#[derive(Message)] pub struct LookAtEvent { pub entity: Entity, /// The position we want the entity to be looking at. pub position: Vec3, } fn look_at_listener( - mut events: EventReader<LookAtEvent>, + mut events: MessageReader<LookAtEvent>, mut query: Query<(&Position, &EntityDimensions, &mut LookDirection)>, ) { for event in events.read() { diff --git a/azalea/src/container.rs b/azalea/src/container.rs index b3e3bb65..cd11b7c2 100644 --- a/azalea/src/container.rs +++ b/azalea/src/container.rs @@ -13,7 +13,7 @@ use azalea_inventory::{ use azalea_physics::collision::BlockWithShape; use azalea_protocol::packets::game::ClientboundGamePacket; use bevy_app::{App, Plugin, Update}; -use bevy_ecs::{component::Component, prelude::EventReader, system::Commands}; +use bevy_ecs::{component::Component, prelude::MessageReader, system::Commands}; use derive_more::Deref; use futures_lite::Future; @@ -126,14 +126,11 @@ impl ContainerClientExt for Client { } fn get_inventory(&self) -> ContainerHandleRef { - let ecs = self.ecs.lock(); - let inventory = ecs.get::<Inventory>(self.entity).expect("no inventory"); - ContainerHandleRef::new(inventory.id, self.clone()) + self.query_self::<&Inventory, _>(|inv| ContainerHandleRef::new(inv.id, self.clone())) } fn get_held_item(&self) -> ItemStack { - self.map_get_component::<Inventory, _>(|inventory| inventory.held_item()) - .expect("no inventory") + self.query_self::<&Inventory, _>(|inv| inv.held_item()) } } @@ -156,7 +153,7 @@ impl ContainerHandleRef { } pub fn close(&self) { - self.client.ecs.lock().send_event(CloseContainerEvent { + self.client.ecs.lock().trigger(CloseContainerEvent { entity: self.client.entity, id: self.id, }); @@ -228,7 +225,7 @@ impl ContainerHandleRef { /// action. pub fn click(&self, operation: impl Into<ClickOperation>) { let operation = operation.into(); - self.client.ecs.lock().send_event(ContainerClickEvent { + self.client.ecs.lock().trigger(ContainerClickEvent { entity: self.client.entity, window_id: self.id, operation, @@ -269,7 +266,7 @@ pub struct WaitingForInventoryOpen; pub fn handle_menu_opened_event( mut commands: Commands, - mut events: EventReader<ReceiveGamePacketEvent>, + mut events: MessageReader<ReceiveGamePacketEvent>, ) { for event in events.read() { if let ClientboundGamePacket::ContainerSetContent { .. } = event.packet.as_ref() { diff --git a/azalea/src/nearest_entity.rs b/azalea/src/nearest_entity.rs index df54273a..2c01e5df 100644 --- a/azalea/src/nearest_entity.rs +++ b/azalea/src/nearest_entity.rs @@ -21,7 +21,7 @@ use bevy_ecs::{ /// metadata::{AbstractMonster, Player}, /// }; /// use bevy_ecs::{ -/// prelude::{Entity, EventWriter}, +/// prelude::{Entity, MessageWriter}, /// query::With, /// system::Query, /// }; @@ -30,7 +30,7 @@ use bevy_ecs::{ /// pub fn bots_near_aggressive_mobs( /// bots: Query<Entity, (With<LocalEntity>, With<Player>)>, /// entity_finder: EntityFinder<With<AbstractMonster>>, -/// mut chat_events: EventWriter<SendChatEvent>, +/// mut chat_events: MessageWriter<SendChatEvent>, /// ) { /// for bot_id in bots.iter() { /// let Some(nearest) = entity_finder.nearest_to_entity(bot_id, 16.0) else { diff --git a/azalea/src/pathfinder/debug.rs b/azalea/src/pathfinder/debug.rs index d0d264d3..4b241e5d 100644 --- a/azalea/src/pathfinder/debug.rs +++ b/azalea/src/pathfinder/debug.rs @@ -37,8 +37,8 @@ pub struct PathfinderDebugParticles; pub fn debug_render_path_with_particles( mut query: Query<(Entity, &ExecutingPath, &InstanceHolder), With<PathfinderDebugParticles>>, // chat_events is Option because the tests don't have SendChatEvent - // and we have to use ResMut<Events> because bevy doesn't support Option<EventWriter> - chat_events: Option<ResMut<Events<SendChatEvent>>>, + // and we have to use ResMut<Messages> because bevy doesn't support Option<MessageWriter> + chat_events: Option<ResMut<Messages<SendChatEvent>>>, mut tick_count: Local<usize>, ) { let Some(mut chat_events) = chat_events else { @@ -104,7 +104,7 @@ pub fn debug_render_path_with_particles( delta_z = 0, count = 1 ); - chat_events.send(SendChatEvent { + chat_events.write(SendChatEvent { entity, content: particle_command, }); diff --git a/azalea/src/pathfinder/goto_event.rs b/azalea/src/pathfinder/goto_event.rs index bd0e1540..379c61d0 100644 --- a/azalea/src/pathfinder/goto_event.rs +++ b/azalea/src/pathfinder/goto_event.rs @@ -1,6 +1,6 @@ use std::{sync::Arc, time::Duration}; -use bevy_ecs::{entity::Entity, event::Event}; +use bevy_ecs::prelude::*; use crate::pathfinder::{ astar::PathfinderTimeout, @@ -16,7 +16,7 @@ use crate::pathfinder::{ /// /// [`goto_listener`]: crate::pathfinder::goto_listener /// [`PathfinderClientExt::goto`]: crate::pathfinder::PathfinderClientExt::goto -#[derive(Event)] +#[derive(Message)] #[non_exhaustive] pub struct GotoEvent { /// The local bot entity that will do the pathfinding and execute the path. diff --git a/azalea/src/pathfinder/mod.rs b/azalea/src/pathfinder/mod.rs index 6fbf0de4..118a13ee 100644 --- a/azalea/src/pathfinder/mod.rs +++ b/azalea/src/pathfinder/mod.rs @@ -68,7 +68,6 @@ use crate::{ ecs::{ component::Component, entity::Entity, - event::{EventReader, EventWriter}, query::{With, Without}, system::{Commands, Query, Res}, }, @@ -79,9 +78,9 @@ use crate::{ pub struct PathfinderPlugin; impl Plugin for PathfinderPlugin { fn build(&self, app: &mut App) { - app.add_event::<GotoEvent>() - .add_event::<PathFoundEvent>() - .add_event::<StopPathfindingEvent>() + app.add_message::<GotoEvent>() + .add_message::<PathFoundEvent>() + .add_message::<StopPathfindingEvent>() .add_systems( // putting systems in the GameTick schedule makes them run every Minecraft tick // (every 50 milliseconds). @@ -138,7 +137,7 @@ pub struct ExecutingPath { pub is_path_partial: bool, } -#[derive(Event, Clone, Debug)] +#[derive(Message, Clone, Debug)] #[non_exhaustive] pub struct PathFoundEvent { pub entity: Entity, @@ -240,16 +239,16 @@ impl PathfinderClientExt for azalea_client::Client { fn start_goto_with_opts(&self, goal: impl Goal + 'static, opts: PathfinderOpts) { self.ecs .lock() - .send_event(GotoEvent::new(self.entity, goal, opts)); + .write_message(GotoEvent::new(self.entity, goal, opts)); } fn stop_pathfinding(&self) { - self.ecs.lock().send_event(StopPathfindingEvent { + self.ecs.lock().write_message(StopPathfindingEvent { entity: self.entity, force: false, }); } fn force_stop_pathfinding(&self) { - self.ecs.lock().send_event(StopPathfindingEvent { + self.ecs.lock().write_message(StopPathfindingEvent { entity: self.entity, force: true, }); @@ -270,8 +269,10 @@ impl PathfinderClientExt for azalea_client::Client { } } fn is_goto_target_reached(&self) -> bool { - self.map_get_component::<Pathfinder, _>(|p| p.goal.is_none() && !p.is_calculating) - .unwrap_or(true) + self.query_self::<Option<&Pathfinder>, _>(|p| { + p.map(|p| p.goal.is_none() && !p.is_calculating) + .unwrap_or(true) + }) } } @@ -281,7 +282,7 @@ pub struct ComputePath(Task<Option<PathFoundEvent>>); #[allow(clippy::type_complexity)] pub fn goto_listener( mut commands: Commands, - mut events: EventReader<GotoEvent>, + mut events: MessageReader<GotoEvent>, mut query: Query<( &mut Pathfinder, Option<&ExecutingPath>, @@ -499,7 +500,7 @@ pub fn calculate_path(ctx: CalculatePathCtx) -> Option<PathFoundEvent> { pub fn handle_tasks( mut commands: Commands, mut transform_tasks: Query<(Entity, &mut ComputePath)>, - mut path_found_events: EventWriter<PathFoundEvent>, + mut path_found_events: MessageWriter<PathFoundEvent>, ) { for (entity, mut task) in &mut transform_tasks { if let Some(optional_path_found_event) = future::block_on(future::poll_once(&mut task.0)) { @@ -516,7 +517,7 @@ pub fn handle_tasks( // set the path for the target entity when we get the PathFoundEvent #[allow(clippy::type_complexity)] pub fn path_found_listener( - mut events: EventReader<PathFoundEvent>, + mut events: MessageReader<PathFoundEvent>, mut query: Query<( &mut Pathfinder, Option<&mut ExecutingPath>, @@ -709,7 +710,7 @@ pub fn check_node_reached( &Position, &Physics, )>, - mut walk_events: EventWriter<StartWalkEvent>, + mut walk_events: MessageWriter<StartWalkEvent>, mut commands: Commands, ) { for (entity, mut pathfinder, mut executing_path, position, physics) in &mut query { @@ -991,8 +992,8 @@ fn patch_path( pub fn recalculate_near_end_of_path( mut query: Query<(Entity, &mut Pathfinder, &mut ExecutingPath)>, - mut walk_events: EventWriter<StartWalkEvent>, - mut goto_events: EventWriter<GotoEvent>, + mut walk_events: MessageWriter<StartWalkEvent>, + mut goto_events: MessageWriter<GotoEvent>, mut commands: Commands, ) { for (entity, mut pathfinder, mut executing_path) in &mut query { @@ -1072,12 +1073,12 @@ pub fn tick_execute_path( &InstanceHolder, &Inventory, )>, - mut look_at_events: EventWriter<LookAtEvent>, - mut sprint_events: EventWriter<StartSprintEvent>, - mut walk_events: EventWriter<StartWalkEvent>, - mut jump_events: EventWriter<JumpEvent>, - mut start_mining_events: EventWriter<StartMiningBlockEvent>, - mut set_selected_hotbar_slot_events: EventWriter<SetSelectedHotbarSlotEvent>, + mut look_at_events: MessageWriter<LookAtEvent>, + mut sprint_events: MessageWriter<StartSprintEvent>, + mut walk_events: MessageWriter<StartWalkEvent>, + mut jump_events: MessageWriter<JumpEvent>, + mut start_mining_events: MessageWriter<StartMiningBlockEvent>, + mut set_selected_hotbar_slot_events: MessageWriter<SetSelectedHotbarSlotEvent>, ) { for (entity, executing_path, position, physics, mining, instance_holder, inventory_component) in &mut query @@ -1111,7 +1112,7 @@ pub fn tick_execute_path( pub fn recalculate_if_has_goal_but_no_path( mut query: Query<(Entity, &mut Pathfinder), Without<ExecutingPath>>, - mut goto_events: EventWriter<GotoEvent>, + mut goto_events: MessageWriter<GotoEvent>, ) { for (entity, mut pathfinder) in &mut query { if pathfinder.goal.is_some() @@ -1126,7 +1127,7 @@ pub fn recalculate_if_has_goal_but_no_path( } } -#[derive(Event)] +#[derive(Message)] pub struct StopPathfindingEvent { pub entity: Entity, /// If false, then let the current movement finish before stopping. If true, @@ -1136,9 +1137,9 @@ pub struct StopPathfindingEvent { } pub fn handle_stop_pathfinding_event( - mut events: EventReader<StopPathfindingEvent>, + mut events: MessageReader<StopPathfindingEvent>, mut query: Query<(&mut Pathfinder, &mut ExecutingPath)>, - mut walk_events: EventWriter<StartWalkEvent>, + mut walk_events: MessageWriter<StartWalkEvent>, mut commands: Commands, ) { for event in events.read() { @@ -1171,7 +1172,7 @@ pub fn handle_stop_pathfinding_event( pub fn stop_pathfinding_on_instance_change( mut query: Query<(Entity, &mut ExecutingPath), Changed<InstanceName>>, - mut stop_pathfinding_events: EventWriter<StopPathfindingEvent>, + mut stop_pathfinding_events: MessageWriter<StopPathfindingEvent>, ) { for (entity, mut executing_path) in &mut query { if !executing_path.path.is_empty() { diff --git a/azalea/src/pathfinder/moves/mod.rs b/azalea/src/pathfinder/moves/mod.rs index 3111516d..1e22f683 100644 --- a/azalea/src/pathfinder/moves/mod.rs +++ b/azalea/src/pathfinder/moves/mod.rs @@ -14,7 +14,7 @@ use azalea_client::{ use azalea_core::position::{BlockPos, Vec3}; use azalea_inventory::Menu; use azalea_world::Instance; -use bevy_ecs::{entity::Entity, event::EventWriter}; +use bevy_ecs::{entity::Entity, message::MessageWriter}; use parking_lot::RwLock; use super::{ @@ -66,12 +66,12 @@ pub struct ExecuteCtx<'w1, 'w2, 'w3, 'w4, 'w5, 'w6, 'a> { pub instance: Arc<RwLock<Instance>>, pub menu: Menu, - pub look_at_events: &'a mut EventWriter<'w1, LookAtEvent>, - pub sprint_events: &'a mut EventWriter<'w2, StartSprintEvent>, - pub walk_events: &'a mut EventWriter<'w3, StartWalkEvent>, - pub jump_events: &'a mut EventWriter<'w4, JumpEvent>, - pub start_mining_events: &'a mut EventWriter<'w5, StartMiningBlockEvent>, - pub set_selected_hotbar_slot_events: &'a mut EventWriter<'w6, SetSelectedHotbarSlotEvent>, + pub look_at_events: &'a mut MessageWriter<'w1, LookAtEvent>, + pub sprint_events: &'a mut MessageWriter<'w2, StartSprintEvent>, + pub walk_events: &'a mut MessageWriter<'w3, StartWalkEvent>, + pub jump_events: &'a mut MessageWriter<'w4, JumpEvent>, + pub start_mining_events: &'a mut MessageWriter<'w5, StartMiningBlockEvent>, + pub set_selected_hotbar_slot_events: &'a mut MessageWriter<'w6, SetSelectedHotbarSlotEvent>, } impl ExecuteCtx<'_, '_, '_, '_, '_, '_, '_> { diff --git a/azalea/src/pathfinder/simulation.rs b/azalea/src/pathfinder/simulation.rs index 78de1642..94836d3b 100644 --- a/azalea/src/pathfinder/simulation.rs +++ b/azalea/src/pathfinder/simulation.rs @@ -4,7 +4,7 @@ use std::sync::Arc; use azalea_client::{ PhysicsState, interact::BlockStatePredictionHandler, inventory::Inventory, - local_player::LocalGameMode, mining::MineBundle, packet::game::SendPacketEvent, + local_player::LocalGameMode, mining::MineBundle, }; use azalea_core::{ game_type::GameMode, position::Vec3, resource_location::ResourceLocation, tick::GameTick, @@ -76,8 +76,7 @@ fn create_simulation_instance(chunks: ChunkStorage) -> (App, Arc<RwLock<Instance .iter() .cloned() .collect(), - }) - .add_event::<SendPacketEvent>(); + }); app.edit_schedule(bevy_app::Main, |schedule| { schedule.set_executor_kind(bevy_ecs::schedule::ExecutorKind::SingleThreaded); diff --git a/azalea/src/pathfinder/tests.rs b/azalea/src/pathfinder/tests.rs index 4f9d2296..7b33ca18 100644 --- a/azalea/src/pathfinder/tests.rs +++ b/azalea/src/pathfinder/tests.rs @@ -33,7 +33,7 @@ fn setup_blockposgoal_simulation( // ..Default::default() // }); - simulation.app.world_mut().send_event(GotoEvent { + simulation.app.world_mut().write_message(GotoEvent { entity: simulation.entity, goal: Arc::new(BlockPosGoal(end_pos)), opts: PathfinderOpts { @@ -299,7 +299,7 @@ fn test_mine_through_non_colliding_block() { ], ); - simulation.app.world_mut().send_event(GotoEvent { + simulation.app.world_mut().write_message(GotoEvent { entity: simulation.entity, goal: Arc::new(BlockPosGoal(BlockPos::new(0, 69, 0))), opts: PathfinderOpts::new() diff --git a/azalea/src/swarm/chat.rs b/azalea/src/swarm/chat.rs index 21db2fd8..46741be6 100644 --- a/azalea/src/swarm/chat.rs +++ b/azalea/src/swarm/chat.rs @@ -17,7 +17,6 @@ use std::collections::VecDeque; use azalea_client::chat::{ChatPacket, ChatReceivedEvent}; use bevy_app::{App, Plugin, Update}; -use bevy_ecs::prelude::Event; use super::{Swarm, SwarmEvent}; use crate::ecs::prelude::*; @@ -26,7 +25,7 @@ use crate::ecs::prelude::*; pub struct SwarmChatPlugin; impl Plugin for SwarmChatPlugin { fn build(&self, app: &mut App) { - app.add_event::<NewChatMessageEvent>() + app.add_message::<NewChatMessageEvent>() .add_systems( Update, (chat_listener, update_min_index_and_shrink_queue).chain(), @@ -44,7 +43,7 @@ pub struct ClientChatState { } /// A chat message that no other bots have seen yet was received by a bot. -#[derive(Event, Debug)] +#[derive(Message, Debug)] pub struct NewChatMessageEvent(ChatPacket); #[derive(Resource)] @@ -56,9 +55,9 @@ pub struct GlobalChatState { fn chat_listener( mut commands: Commands, mut query: Query<&mut ClientChatState>, - mut events: EventReader<ChatReceivedEvent>, + mut events: MessageReader<ChatReceivedEvent>, mut global_chat_state: ResMut<GlobalChatState>, - mut new_chat_messages_events: EventWriter<NewChatMessageEvent>, + mut new_chat_messages_events: MessageWriter<NewChatMessageEvent>, ) { for event in events.read() { let mut client_chat_state = query.get_mut(event.entity); @@ -112,7 +111,7 @@ fn chat_listener( fn update_min_index_and_shrink_queue( query: Query<&ClientChatState>, mut global_chat_state: ResMut<GlobalChatState>, - mut events: EventReader<NewChatMessageEvent>, + mut events: MessageReader<NewChatMessageEvent>, swarm: Option<Res<Swarm>>, ) { for event in events.read() { @@ -150,16 +149,16 @@ fn update_min_index_and_shrink_queue( #[cfg(test)] mod tests { - use bevy_ecs::{event::Events, prelude::World, system::SystemState}; + use bevy_ecs::{prelude::World, system::SystemState}; use super::*; fn make_test_app() -> App { let mut app = App::new(); - // we add the events like this instead of with .add_event so we can have our own - // event management in drain_events - app.init_resource::<Events<ChatReceivedEvent>>() - .init_resource::<Events<NewChatMessageEvent>>() + // we add the events like this instead of with .add_message so we can have our + // own event management in drain_messages + app.init_resource::<Messages<ChatReceivedEvent>>() + .init_resource::<Messages<NewChatMessageEvent>>() .add_systems( Update, (chat_listener, update_min_index_and_shrink_queue).chain(), @@ -171,12 +170,12 @@ mod tests { app } - fn drain_events(ecs: &mut World) -> Vec<ChatPacket> { - let mut system_state: SystemState<ResMut<Events<NewChatMessageEvent>>> = + fn drain_messages(ecs: &mut World) -> Vec<ChatPacket> { + let mut system_state: SystemState<ResMut<Messages<NewChatMessageEvent>>> = SystemState::new(ecs); - let mut events = system_state.get_mut(ecs); + let mut messages = system_state.get_mut(ecs); - events.drain().map(|e| e.0.clone()).collect::<Vec<_>>() + messages.drain().map(|e| e.0.clone()).collect::<Vec<_>>() } #[tokio::test] @@ -186,46 +185,46 @@ mod tests { let bot0 = app.world_mut().spawn_empty().id(); let bot1 = app.world_mut().spawn_empty().id(); - app.world_mut().send_event(ChatReceivedEvent { + app.world_mut().write_message(ChatReceivedEvent { entity: bot0, packet: ChatPacket::new("a"), }); app.update(); // the swarm should get the event immediately after the bot gets it - assert_eq!(drain_events(app.world_mut()), vec![ChatPacket::new("a")]); + assert_eq!(drain_messages(app.world_mut()), vec![ChatPacket::new("a")]); assert_eq!( app.world().get::<ClientChatState>(bot0).unwrap().chat_index, 1 ); // and a second bot sending the event shouldn't do anything - app.world_mut().send_event(ChatReceivedEvent { + app.world_mut().write_message(ChatReceivedEvent { entity: bot1, packet: ChatPacket::new("a"), }); app.update(); - assert_eq!(drain_events(app.world_mut()), vec![]); + assert_eq!(drain_messages(app.world_mut()), vec![]); assert_eq!( app.world().get::<ClientChatState>(bot1).unwrap().chat_index, 1 ); // but if the first one gets it again, it should sent it again - app.world_mut().send_event(ChatReceivedEvent { + app.world_mut().write_message(ChatReceivedEvent { entity: bot0, packet: ChatPacket::new("a"), }); app.update(); - assert_eq!(drain_events(app.world_mut()), vec![ChatPacket::new("a")]); + assert_eq!(drain_messages(app.world_mut()), vec![ChatPacket::new("a")]); // alright and now the second bot got a different chat message and it should be // sent - app.world_mut().send_event(ChatReceivedEvent { + app.world_mut().write_message(ChatReceivedEvent { entity: bot1, packet: ChatPacket::new("b"), }); app.update(); - assert_eq!(drain_events(app.world_mut()), vec![ChatPacket::new("b")]); + assert_eq!(drain_messages(app.world_mut()), vec![ChatPacket::new("b")]); } #[tokio::test] @@ -235,18 +234,18 @@ mod tests { let bot0 = app.world_mut().spawn_empty().id(); // bot0 gets a chat message - app.world_mut().send_event(ChatReceivedEvent { + app.world_mut().write_message(ChatReceivedEvent { entity: bot0, packet: ChatPacket::new("a"), }); app.update(); - assert_eq!(drain_events(app.world_mut()), vec![ChatPacket::new("a")]); + assert_eq!(drain_messages(app.world_mut()), vec![ChatPacket::new("a")]); let bot1 = app.world_mut().spawn_empty().id(); - app.world_mut().send_event(ChatReceivedEvent { + app.world_mut().write_message(ChatReceivedEvent { entity: bot1, packet: ChatPacket::new("b"), }); app.update(); - assert_eq!(drain_events(app.world_mut()), vec![ChatPacket::new("b")]); + assert_eq!(drain_messages(app.world_mut()), vec![ChatPacket::new("b")]); } } diff --git a/azalea/src/swarm/events.rs b/azalea/src/swarm/events.rs index aff578a3..78fb6127 100644 --- a/azalea/src/swarm/events.rs +++ b/azalea/src/swarm/events.rs @@ -7,14 +7,14 @@ use derive_more::{Deref, DerefMut}; pub struct SwarmPlugin; impl Plugin for SwarmPlugin { fn build(&self, app: &mut App) { - app.add_event::<SwarmReadyEvent>() + app.add_message::<SwarmReadyEvent>() .add_systems(Update, check_ready) .init_resource::<IsSwarmReady>(); } } /// All the bots from the swarm are now in the world. -#[derive(Event)] +#[derive(Message)] pub struct SwarmReadyEvent; #[derive(Default, Resource, Deref, DerefMut)] @@ -23,7 +23,7 @@ struct IsSwarmReady(bool); fn check_ready( query: Query<Option<&MinecraftEntityId>, With<InstanceHolder>>, mut is_swarm_ready: ResMut<IsSwarmReady>, - mut ready_events: EventWriter<SwarmReadyEvent>, + mut ready_events: MessageWriter<SwarmReadyEvent>, ) { // if we already know the swarm is ready, do nothing if **is_swarm_ready { |
