From 11d14c74c53c07231c8ca33b622380df99bf9a59 Mon Sep 17 00:00:00 2001 From: mat <27899617+mat-1@users.noreply.github.com> Date: Thu, 24 Aug 2023 22:59:40 -0500 Subject: Support properly switching instances (#106) * start implementing switching dimensions * fix removeentity in shared worlds * also store entity ids per local player * uncomment a trace in pathfinder * cleanup --------- Co-authored-by: mat --- azalea/src/pathfinder/mod.rs | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) (limited to 'azalea/src') 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>, + mut walk_events: EventWriter, +) { + 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 { -- cgit v1.2.3