1
2
Fork 0
mirror of https://github.com/mat-1/azalea.git synced 2025-08-02 23:44:38 +00:00

add Client::force_stop_pathfinding

This commit is contained in:
mat 2025-07-24 21:26:49 +11:00
commit 9719d00526

View file

@ -167,6 +167,7 @@ pub trait PathfinderClientExt {
fn start_goto(&self, goal: impl Goal + 'static); fn start_goto(&self, goal: impl Goal + 'static);
fn start_goto_without_mining(&self, goal: impl Goal + 'static); fn start_goto_without_mining(&self, goal: impl Goal + 'static);
fn stop_pathfinding(&self); fn stop_pathfinding(&self);
fn force_stop_pathfinding(&self);
fn wait_until_goto_target_reached(&self) -> impl Future<Output = ()>; fn wait_until_goto_target_reached(&self) -> impl Future<Output = ()>;
fn is_goto_target_reached(&self) -> bool; fn is_goto_target_reached(&self) -> bool;
} }
@ -212,6 +213,13 @@ impl PathfinderClientExt for azalea_client::Client {
.send_event(GotoEvent::new(self.entity, goal).with_allow_mining(false)); .send_event(GotoEvent::new(self.entity, goal).with_allow_mining(false));
} }
/// Stop calculating a path, and stop moving once the current movement is
/// finished.
///
/// This behavior exists to prevent the bot from taking damage if
/// `stop_pathfinding` was called while executing a parkour jump, but if
/// it's undesirable then you may want to consider using
/// [`Self::force_stop_pathfinding`] instead.
fn stop_pathfinding(&self) { fn stop_pathfinding(&self) {
self.ecs.lock().send_event(StopPathfindingEvent { self.ecs.lock().send_event(StopPathfindingEvent {
entity: self.entity, entity: self.entity,
@ -219,6 +227,15 @@ impl PathfinderClientExt for azalea_client::Client {
}); });
} }
/// Stop calculating a path and stop executing the current movement
/// immediately.
fn force_stop_pathfinding(&self) {
self.ecs.lock().send_event(StopPathfindingEvent {
entity: self.entity,
force: true,
});
}
/// Waits forever until the bot no longer has a pathfinder goal. /// Waits forever until the bot no longer has a pathfinder goal.
async fn wait_until_goto_target_reached(&self) { async fn wait_until_goto_target_reached(&self) {
// we do this to make sure the event got handled before we start checking // we do this to make sure the event got handled before we start checking