mirror of
https://github.com/mat-1/azalea.git
synced 2025-08-02 23:44:38 +00:00
more reliable StopPathfindingEvent
This commit is contained in:
parent
348c71b97b
commit
929cb95db4
1 changed files with 12 additions and 3 deletions
|
@ -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,
|
mut commands: Commands,
|
||||||
) {
|
) {
|
||||||
for event in events.read() {
|
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 {
|
let Ok((mut pathfinder, mut executing_path)) = query.get_mut(event.entity) else {
|
||||||
continue;
|
continue;
|
||||||
};
|
};
|
||||||
|
@ -682,13 +685,19 @@ fn handle_stop_pathfinding_event(
|
||||||
if event.force {
|
if event.force {
|
||||||
executing_path.path.clear();
|
executing_path.path.clear();
|
||||||
executing_path.queued_path = None;
|
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 {
|
walk_events.send(StartWalkEvent {
|
||||||
entity: event.entity,
|
entity: event.entity,
|
||||||
direction: WalkDirection::None,
|
direction: WalkDirection::None,
|
||||||
});
|
});
|
||||||
commands.entity(event.entity).remove::<ExecutingPath>();
|
commands.entity(event.entity).remove::<ExecutingPath>();
|
||||||
} else {
|
|
||||||
executing_path.queued_path = Some(VecDeque::new());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue