diff options
| author | x-osc <58891676+x-osc@users.noreply.github.com> | 2025-05-10 15:12:59 +1200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-05-09 22:12:59 -0500 |
| commit | b35904a0b563648e4fa7366004bced29c69aa841 (patch) | |
| tree | dba700d8fe873a6210c8819a2a703e94760bc578 /azalea/src | |
| parent | 6a5a88700c3f649fab1abc4a51f6fac9281db874 (diff) | |
| download | azalea-drasl-b35904a0b563648e4fa7366004bced29c69aa841.tar.xz | |
add distance param for ReachBlockPosGoal (#220)
* add distance param for ReachBlockPosGoal
* add new impl for ReachBlockPosGoal and optimize slightly
Diffstat (limited to 'azalea/src')
| -rw-r--r-- | azalea/src/pathfinder/goals.rs | 24 |
1 files changed, 19 insertions, 5 deletions
diff --git a/azalea/src/pathfinder/goals.rs b/azalea/src/pathfinder/goals.rs index 3ef45993..5ab969c9 100644 --- a/azalea/src/pathfinder/goals.rs +++ b/azalea/src/pathfinder/goals.rs @@ -194,7 +194,24 @@ impl<T: Goal> Goal for AndGoals<T> { #[derive(Clone, Debug)] pub struct ReachBlockPosGoal { pub pos: BlockPos, + pub distance: f64, pub chunk_storage: ChunkStorage, + + max_check_distance: i32, +} +impl ReachBlockPosGoal { + pub fn new(pos: BlockPos, chunk_storage: ChunkStorage) -> Self { + Self::new_with_distance(pos, 4.5, chunk_storage) + } + + pub fn new_with_distance(pos: BlockPos, distance: f64, chunk_storage: ChunkStorage) -> Self { + Self { + pos, + distance, + chunk_storage, + max_check_distance: (distance + 2.).ceil() as i32, + } + } } impl Goal for ReachBlockPosGoal { fn heuristic(&self, n: BlockPos) -> f32 { @@ -202,11 +219,8 @@ impl Goal for ReachBlockPosGoal { } fn success(&self, n: BlockPos) -> bool { // only do the expensive check if we're close enough - let max_pick_range = 6; - let actual_pick_range = 4.5; - let distance = (self.pos - n).length_squared(); - if distance > max_pick_range * max_pick_range { + if distance > self.max_check_distance * self.max_check_distance { return false; } @@ -216,7 +230,7 @@ impl Goal for ReachBlockPosGoal { &look_direction, &eye_position, &self.chunk_storage, - actual_pick_range, + self.distance, ); block_hit_result.block_pos == self.pos |
