aboutsummaryrefslogtreecommitdiff
path: root/azalea/src
diff options
context:
space:
mode:
Diffstat (limited to 'azalea/src')
-rw-r--r--azalea/src/pathfinder/mod.rs22
1 files changed, 20 insertions, 2 deletions
diff --git a/azalea/src/pathfinder/mod.rs b/azalea/src/pathfinder/mod.rs
index 9237aa81..58b59fd4 100644
--- a/azalea/src/pathfinder/mod.rs
+++ b/azalea/src/pathfinder/mod.rs
@@ -24,10 +24,11 @@ use azalea_physics::PhysicsSet;
use azalea_world::{InstanceContainer, InstanceName};
use bevy_app::{FixedUpdate, Update};
use bevy_ecs::prelude::Event;
+use bevy_ecs::query::Changed;
use bevy_ecs::schedule::IntoSystemConfigs;
use bevy_tasks::{AsyncComputeTaskPool, Task};
use futures_lite::future;
-use log::{debug, error};
+use log::{debug, error, trace};
use std::collections::VecDeque;
use std::sync::Arc;
@@ -49,6 +50,7 @@ impl Plugin for PathfinderPlugin {
goto_listener,
add_default_pathfinder,
(handle_tasks, path_found_listener).chain(),
+ stop_pathfinding_on_instance_change,
),
);
}
@@ -249,7 +251,7 @@ fn tick_execute_path(
entity,
position: center,
});
- debug!(
+ trace!(
"tick: pathfinder {entity:?}; going to {:?}; currently at {position:?}",
target.pos
);
@@ -280,6 +282,22 @@ fn tick_execute_path(
}
}
+fn stop_pathfinding_on_instance_change(
+ mut query: Query<(Entity, &mut Pathfinder), Changed<InstanceName>>,
+ mut walk_events: EventWriter<StartWalkEvent>,
+) {
+ for (entity, mut pathfinder) in &mut query {
+ if !pathfinder.path.is_empty() {
+ debug!("instance changed, clearing path");
+ pathfinder.path.clear();
+ walk_events.send(StartWalkEvent {
+ entity,
+ direction: WalkDirection::None,
+ });
+ }
+ }
+}
+
/// Information about our vertical velocity
#[derive(Eq, PartialEq, Hash, Clone, Copy, Debug)]
pub enum VerticalVel {