diff options
| author | mat <git@matdoes.dev> | 2023-12-10 00:47:43 -0600 |
|---|---|---|
| committer | mat <git@matdoes.dev> | 2023-12-10 00:47:43 -0600 |
| commit | 929cb95db437640b97899550e6fe3aa37ed3ca0f (patch) | |
| tree | 12efd3308660f5833852ad0b81e2efc08b3566cc /azalea/src/pathfinder | |
| parent | 348c71b97b2dfc45d7412ec33f6131e20592bb14 (diff) | |
| download | azalea-drasl-929cb95db437640b97899550e6fe3aa37ed3ca0f.tar.xz | |
more reliable StopPathfindingEvent
Diffstat (limited to 'azalea/src/pathfinder')
| -rw-r--r-- | azalea/src/pathfinder/mod.rs | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/azalea/src/pathfinder/mod.rs b/azalea/src/pathfinder/mod.rs index 789efb07..525f982d 100644 --- a/azalea/src/pathfinder/mod.rs +++ b/azalea/src/pathfinder/mod.rs @@ -292,7 +292,7 @@ fn goto_listener( }) }); - commands.spawn(ComputePath(task)); + commands.entity(event.entity).insert(ComputePath(task)); } } @@ -675,6 +675,9 @@ fn handle_stop_pathfinding_event( mut commands: Commands, ) { for event in events.read() { + // stop computing any path that's being computed + commands.entity(event.entity).remove::<ComputePath>(); + let Ok((mut pathfinder, mut executing_path)) = query.get_mut(event.entity) else { continue; }; @@ -682,13 +685,19 @@ fn handle_stop_pathfinding_event( if event.force { executing_path.path.clear(); executing_path.queued_path = None; + } else { + // switch to an empty path as soon as it can + executing_path.queued_path = Some(VecDeque::new()); + // make sure it doesn't recalculate + executing_path.is_path_partial = false; + } + + if executing_path.path.is_empty() { walk_events.send(StartWalkEvent { entity: event.entity, direction: WalkDirection::None, }); commands.entity(event.entity).remove::<ExecutingPath>(); - } else { - executing_path.queued_path = Some(VecDeque::new()); } } } |
