diff options
| author | mat <git@matdoes.dev> | 2026-01-14 06:26:29 -1200 |
|---|---|---|
| committer | mat <git@matdoes.dev> | 2026-01-14 06:26:29 -1200 |
| commit | 14b9166afb5d6563774bf7a4336d4e6807e01ebb (patch) | |
| tree | e201cdcd883d09f9fdf3dce335f186d9cc4f6d03 | |
| parent | f4b6943e88d6e704bfe2ef34b2ef24e143c58ae1 (diff) | |
| download | azalea-drasl-14b9166afb5d6563774bf7a4336d4e6807e01ebb.tar.xz | |
update pathfinder last_node_reached timeout to be based on ticks rather than real time
| -rw-r--r-- | azalea-protocol/src/packets/game/c_server_links.rs | 1 | ||||
| -rw-r--r-- | azalea/src/pathfinder/mod.rs | 31 |
2 files changed, 21 insertions, 11 deletions
diff --git a/azalea-protocol/src/packets/game/c_server_links.rs b/azalea-protocol/src/packets/game/c_server_links.rs index 433254d6..42d2ad71 100644 --- a/azalea-protocol/src/packets/game/c_server_links.rs +++ b/azalea-protocol/src/packets/game/c_server_links.rs @@ -18,7 +18,6 @@ mod tests { #[test] fn test_read_server_links() { - tracing_subscriber::fmt::try_init().ok(); let contents = [ 1, 0, 10, 8, 0, 5, 99, 111, 108, 111, 114, 0, 7, 35, 48, 48, 70, 66, 57, 65, 8, 0, 4, 116, 101, 120, 116, 0, 15, 65, 98, 111, 117, 116, 32, 86, 101, 108, 111, 99, 105, 116, diff --git a/azalea/src/pathfinder/mod.rs b/azalea/src/pathfinder/mod.rs index 96de98da..cab30f7a 100644 --- a/azalea/src/pathfinder/mod.rs +++ b/azalea/src/pathfinder/mod.rs @@ -137,7 +137,9 @@ pub struct ExecutingPath { pub path: VecDeque<astar::Edge<BlockPos, moves::MoveData>>, pub queued_path: Option<VecDeque<astar::Edge<BlockPos, moves::MoveData>>>, pub last_reached_node: BlockPos, - pub last_node_reached_at: Instant, + // count ticks instead of using real time to make our timeouts more consistent, in case we lag + // and our ticks take a while + pub ticks_since_last_node_reached: usize, pub is_path_partial: bool, } @@ -649,7 +651,7 @@ pub fn path_found_listener( path: path.to_owned(), queued_path: None, last_reached_node: event.start, - last_node_reached_at: Instant::now(), + ticks_since_last_node_reached: 0, is_path_partial: event.is_partial, }); debug!("set path to {:?}", path.iter().take(10).collect::<Vec<_>>()); @@ -697,14 +699,14 @@ pub fn timeout_movement( if let Some(mining) = mining { // also make sure we're close enough to the block that's being mined if mining.pos.distance_squared_to(position.into()) < 6_i32.pow(2) { - // also reset the last_node_reached_at so we don't timeout after we finish - // mining - executing_path.last_node_reached_at = Instant::now(); + // also reset the ticks_since_last_node_reached so we don't timeout after we + // finish mining + executing_path.ticks_since_last_node_reached = 0; continue; } } - if executing_path.last_node_reached_at.elapsed() > Duration::from_secs(2) + if executing_path.ticks_since_last_node_reached > (2 * 20) && !pathfinder.is_calculating && !executing_path.path.is_empty() { @@ -739,7 +741,7 @@ pub fn timeout_movement( opts, ); // reset last_node_reached_at so we don't immediately try to patch again - executing_path.last_node_reached_at = Instant::now(); + executing_path.ticks_since_last_node_reached = 0 } } } @@ -824,7 +826,7 @@ pub fn check_node_reached( if (movement.data.is_reached)(is_reached_ctx) && extra_check { executing_path.path = executing_path.path.split_off(i + 1); executing_path.last_reached_node = movement.target; - executing_path.last_node_reached_at = Instant::now(); + executing_path.ticks_since_last_node_reached = 0; trace!("reached node {}", movement.target); if let Some(new_path) = executing_path.queued_path.take() { @@ -1153,9 +1155,18 @@ pub fn tick_execute_path( mut jump_events: MessageWriter<JumpEvent>, mut start_mining_events: MessageWriter<StartMiningBlockEvent>, ) { - for (entity, executing_path, position, physics, mining, world_holder, inventory_component) in - &mut query + for ( + entity, + mut executing_path, + position, + physics, + mining, + world_holder, + inventory_component, + ) in &mut query { + executing_path.ticks_since_last_node_reached += 1; + if let Some(edge) = executing_path.path.front() { let ctx = ExecuteCtx { entity, |
