diff options
| author | mat <git@matdoes.dev> | 2024-12-24 08:48:36 +0000 |
|---|---|---|
| committer | mat <git@matdoes.dev> | 2024-12-24 08:48:36 +0000 |
| commit | f03e0c22355778a9863cccb5a59d852278d60701 (patch) | |
| tree | f02e7ca3d1e975d486071934a6322d372b7c9a02 /azalea/src | |
| parent | de5a53ce08de5b9d77bce99dd9ecde3171ebd74e (diff) | |
| download | azalea-drasl-f03e0c22355778a9863cccb5a59d852278d60701.tar.xz | |
fix parsing Dust particle and treat waterlogged blocks as liquid in pathfinder
Diffstat (limited to 'azalea/src')
| -rw-r--r-- | azalea/src/pathfinder/mining.rs | 11 | ||||
| -rw-r--r-- | azalea/src/pathfinder/mod.rs | 12 |
2 files changed, 17 insertions, 6 deletions
diff --git a/azalea/src/pathfinder/mining.rs b/azalea/src/pathfinder/mining.rs index 31b37b49..049e974a 100644 --- a/azalea/src/pathfinder/mining.rs +++ b/azalea/src/pathfinder/mining.rs @@ -1,6 +1,7 @@ use std::{cell::UnsafeCell, ops::RangeInclusive}; -use azalea_block::{BlockState, BlockStates}; +use azalea_block::{properties::Waterlogged, BlockState, BlockStates}; +use azalea_core::bitset::BitSet; use azalea_inventory::Menu; use nohash_hasher::IntMap; @@ -96,8 +97,12 @@ impl MiningCache { } pub fn is_liquid(&self, block: BlockState) -> bool { + // this already runs in about 1 nanosecond, so if you wanna try optimizing it at + // least run the benchmarks (in benches/checks.rs) + self.water_block_state_range.contains(&block.id) || self.lava_block_state_range.contains(&block.id) + || is_waterlogged(block) } pub fn is_falling_block(&self, block: BlockState) -> bool { @@ -106,3 +111,7 @@ impl MiningCache { .is_ok() } } + +pub fn is_waterlogged(block: BlockState) -> bool { + block.property::<Waterlogged>().unwrap_or_default() +} diff --git a/azalea/src/pathfinder/mod.rs b/azalea/src/pathfinder/mod.rs index b82b5f84..8ad0b1d0 100644 --- a/azalea/src/pathfinder/mod.rs +++ b/azalea/src/pathfinder/mod.rs @@ -594,7 +594,7 @@ pub fn check_node_reached( 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(); - trace!("reached node {:?}", movement.target); + trace!("reached node {}", movement.target); if let Some(new_path) = executing_path.queued_path.take() { debug!( @@ -696,7 +696,7 @@ pub fn recalculate_near_end_of_path( && executing_path.is_path_partial { if let Some(goal) = pathfinder.goal.as_ref().cloned() { - debug!("Recalculating path because it ends soon"); + 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 @@ -953,7 +953,7 @@ mod tests { goal: Arc::new(BlockPosGoal(end_pos)), successors_fn: moves::default_move, allow_mining: false, - deterministic_timeout: false, + deterministic_timeout: true, }); simulation } @@ -1161,7 +1161,7 @@ mod tests { let mut simulation = setup_blockposgoal_simulation( &mut partial_chunks, BlockPos::new(0, 71, 0), - BlockPos::new(2, 74, 9), + BlockPos::new(4, 74, 9), vec![ BlockPos::new(0, 70, 0), BlockPos::new(0, 70, 1), @@ -1169,9 +1169,11 @@ mod tests { BlockPos::new(0, 71, 3), BlockPos::new(0, 72, 6), BlockPos::new(0, 73, 9), + // this is the point where the bot might fall if it has too much momentum BlockPos::new(2, 73, 9), + BlockPos::new(4, 73, 9), ], ); - assert_simulation_reaches(&mut simulation, 80, BlockPos::new(2, 74, 9)); + assert_simulation_reaches(&mut simulation, 80, BlockPos::new(4, 74, 9)); } } |
