diff options
| author | mat <git@matdoes.dev> | 2026-05-08 17:20:24 -0100 |
|---|---|---|
| committer | mat <git@matdoes.dev> | 2026-05-08 17:20:24 -0100 |
| commit | c963b0a5fbe57423ccda0c3b2bfe108439dd895c (patch) | |
| tree | 0fd5bf9afe338be979048d492ec18332cb4a222a | |
| parent | 5e0484c925bd7dd7c1d05fdfaf9cee2e66c07dea (diff) | |
| download | azalea-drasl-c963b0a5fbe57423ccda0c3b2bfe108439dd895c.tar.xz | |
several stability fixes for pathfinder when doing long paths
| -rw-r--r-- | azalea/src/pathfinder/astar/mod.rs | 6 | ||||
| -rw-r--r-- | azalea/src/pathfinder/execute/mod.rs | 4 | ||||
| -rw-r--r-- | azalea/src/pathfinder/mod.rs | 17 | ||||
| -rw-r--r-- | azalea/src/pathfinder/moves/parkour.rs | 6 |
4 files changed, 22 insertions, 11 deletions
diff --git a/azalea/src/pathfinder/astar/mod.rs b/azalea/src/pathfinder/astar/mod.rs index 077ce13a..b2b914b8 100644 --- a/azalea/src/pathfinder/astar/mod.rs +++ b/azalea/src/pathfinder/astar/mod.rs @@ -29,8 +29,10 @@ where } // used for better results when timing out -// see https://github.com/cabaletta/baritone/blob/1.19.4/src/main/java/baritone/pathing/calc/AbstractNodeCostSearch.java#L68 -const COEFFICIENTS: [f32; 7] = [1.5, 2., 2.5, 3., 4., 5., 10.]; +// based on Baritone's implementation (with tweaks), see +// https://github.com/cabaletta/baritone/blob/1.19.4/src/main/java/baritone/pathing/calc/AbstractNodeCostSearch.java#L68 +// for more info +const COEFFICIENTS: [f32; 7] = [1.5, 2., 2.5, 3., 4., 5., 15.]; const MIN_IMPROVEMENT: f32 = 0.01; diff --git a/azalea/src/pathfinder/execute/mod.rs b/azalea/src/pathfinder/execute/mod.rs index a06d1c0f..9e169a91 100644 --- a/azalea/src/pathfinder/execute/mod.rs +++ b/azalea/src/pathfinder/execute/mod.rs @@ -427,12 +427,14 @@ pub fn recalculate_near_end_of_path( if (executing_path.path.len() == 50 || executing_path.path.len() < 5) && !pathfinder.is_calculating && executing_path.is_path_partial + // don't recalculate if we're already planning on switching to a different path + && executing_path.queued_path.is_none() { match pathfinder.goal.as_ref().cloned() { Some(goal) => { debug!("Recalculating path because it's empty or ends soon"); debug!( - "recalculate_near_end_of_path executing_path.is_path_partial: {}", + " executing_path.is_path_partial: {}", executing_path.is_path_partial ); diff --git a/azalea/src/pathfinder/mod.rs b/azalea/src/pathfinder/mod.rs index e5d1912d..5160a4bd 100644 --- a/azalea/src/pathfinder/mod.rs +++ b/azalea/src/pathfinder/mod.rs @@ -34,8 +34,7 @@ use std::{ Arc, atomic::{self, AtomicBool, AtomicUsize}, }, - thread, - time::{Duration, Instant}, + time::Instant, }; use astar::Edge; @@ -435,6 +434,8 @@ pub fn goto_listener( executing_path.path ) } + } else { + debug!("Couldn't find path instantly..."); } if !executing_path.path.is_empty() { @@ -445,6 +446,9 @@ pub fn goto_listener( // truncate the executing path so we can cleanly combine the two paths later executing_path.path.truncate(executing_path_limit); + // TODO: this should probably have better handling when we have a queued path + // (since it can result in skipped nodes which is very bad). you should probably + // write a test for this before trying to fix it, though. start = executing_path .path .back() @@ -552,8 +556,6 @@ pub fn calculate_path(ctx: CalculatePathCtx) -> Option<PathFoundEvent> { } else { info!("Pathfinder took {duration:?} (incomplete path)"); } - // wait a bit so it's not a busy loop - thread::sleep(Duration::from_millis(100)); } else { info!("Pathfinder took {duration:?}"); } @@ -692,7 +694,8 @@ pub fn path_found_listener( first_node_of_new_path.movement.target, ); - if successors(last_target_of_current_path) + let successors = successors(last_target_of_current_path); + if successors .iter() .any(|edge| edge.movement.target == first_target_of_new_path) { @@ -706,6 +709,10 @@ pub fn path_found_listener( found_path.iter().take(10).collect::<Vec<_>>() ); new_path.extend(executing_path.path.iter().cloned()); + } else { + debug!( + "failed to combine old and new paths. first_target_of_new_path: {first_target_of_new_path:?}, successors: {successors:?}" + ) } } else { new_path.extend(executing_path.path.iter().cloned()); diff --git a/azalea/src/pathfinder/moves/parkour.rs b/azalea/src/pathfinder/moves/parkour.rs index c95d436b..80bc4e7c 100644 --- a/azalea/src/pathfinder/moves/parkour.rs +++ b/azalea/src/pathfinder/moves/parkour.rs @@ -236,13 +236,13 @@ fn execute_parkour_move(mut ctx: ExecuteCtx) { // it's possible to hit our heads on a block when doing certain jumps (which // resets our horizontal velocity), but we can avoid that by sneaking - if !ctx.physics.on_ground() && ctx.physics.velocity.y.abs() < 0.1 { + if !ctx.physics.on_ground() && ctx.physics.velocity.y.abs() < 0.25 { let should_sneak = { let world = ctx.world.read(); - let pos_above = ctx.position.up(1.8 + 0.1); + let pos_above = ctx.position.up(1.8 + 0.25); let block_pos_above = BlockPos::from(pos_above); let block_pos_above_plus_velocity = - BlockPos::from(pos_above + ctx.physics.velocity.with_y(0.) * 4.); + BlockPos::from(pos_above + ctx.physics.velocity.with_y(0.) * 5.); let block_above = world.get_block_state(block_pos_above).unwrap_or_default(); let block_above_plus_velocity = world |
