aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormat <git@matdoes.dev>2025-10-04 16:38:55 -1345
committermat <git@matdoes.dev>2025-10-04 16:38:55 -1345
commitb77d030f718d6a681a09e36d620f1c596cf58a4e (patch)
treef2d978eeb21037d67881af3ece26155c64d59f3e
parent682f3c0e95966c39b3d135fc6364f891f3dfb30a (diff)
downloadazalea-drasl-b77d030f718d6a681a09e36d620f1c596cf58a4e.tar.xz
fix wrong pathfinding when we start calculating a new path and the current executing path is long
-rw-r--r--azalea-client/src/client.rs4
-rw-r--r--azalea/src/pathfinder/mod.rs17
2 files changed, 14 insertions, 7 deletions
diff --git a/azalea-client/src/client.rs b/azalea-client/src/client.rs
index efc911c0..bb827838 100644
--- a/azalea-client/src/client.rs
+++ b/azalea-client/src/client.rs
@@ -373,7 +373,9 @@ impl Client {
/// This is a shortcut for
/// `bot.position().up(bot.dimensions().eye_height)`.
pub fn eye_position(&self) -> Vec3 {
- self.position().up(self.dimensions().eye_height as f64)
+ self.query_self::<(&Position, &EntityDimensions), _>(|(pos, dim)| {
+ pos.up(dim.eye_height as f64)
+ })
}
/// Get the health of this client.
diff --git a/azalea/src/pathfinder/mod.rs b/azalea/src/pathfinder/mod.rs
index 54fd7a59..d6a16f69 100644
--- a/azalea/src/pathfinder/mod.rs
+++ b/azalea/src/pathfinder/mod.rs
@@ -285,7 +285,7 @@ pub fn goto_listener(
mut events: MessageReader<GotoEvent>,
mut query: Query<(
&mut Pathfinder,
- Option<&ExecutingPath>,
+ Option<&mut ExecutingPath>,
&Position,
&InstanceName,
&Inventory,
@@ -317,14 +317,19 @@ pub fn goto_listener(
pathfinder.opts = Some(event.opts.clone());
pathfinder.is_calculating = true;
- let start = if let Some(executing_path) = executing_path
- && let Some(final_node) = executing_path.path.back()
+ let start = if let Some(mut executing_path) = executing_path
+ && { !executing_path.path.is_empty() }
{
// if we're currently pathfinding and got a goto event, start a little ahead
+
+ let executing_path_limit = 50;
+ // truncate the executing path so we can cleanly combine the two paths later
+ executing_path.path.truncate(executing_path_limit);
+
executing_path
.path
- .get(50)
- .unwrap_or(final_node)
+ .back()
+ .expect("path was just checked to not be empty")
.movement
.target
} else {
@@ -1220,7 +1225,7 @@ where
// if the node that we're currently executing was obstructed then it's often too
// late to change the path, so it's usually better to just ignore this case :/
if i == 0 {
- warn!("path obstructed at index 0, ignoring");
+ warn!("path obstructed at index 0 ({edge:?}), ignoring");
continue;
}