aboutsummaryrefslogtreecommitdiff
path: root/azalea/src/pathfinder
diff options
context:
space:
mode:
authormat <git@matdoes.dev>2025-09-28 13:10:04 -0545
committermat <git@matdoes.dev>2025-09-28 13:10:04 -0545
commit2c8b7c5c2c9297273abfba8f7743f1bc25f166b1 (patch)
tree3d3aded400100c136287fa59293ce26c61644d00 /azalea/src/pathfinder
parente2ed19c1ed92f0dccc881d835d9ac6e0f7f834c0 (diff)
downloadazalea-drasl-2c8b7c5c2c9297273abfba8f7743f1bc25f166b1.tar.xz
upgrade bevy to 0.17.0-rc.2
Diffstat (limited to 'azalea/src/pathfinder')
-rw-r--r--azalea/src/pathfinder/debug.rs6
-rw-r--r--azalea/src/pathfinder/goto_event.rs4
-rw-r--r--azalea/src/pathfinder/mod.rs55
-rw-r--r--azalea/src/pathfinder/moves/mod.rs14
-rw-r--r--azalea/src/pathfinder/simulation.rs5
-rw-r--r--azalea/src/pathfinder/tests.rs4
6 files changed, 44 insertions, 44 deletions
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()