aboutsummaryrefslogtreecommitdiff
path: root/azalea/src
diff options
context:
space:
mode:
Diffstat (limited to 'azalea/src')
-rw-r--r--azalea/src/pathfinder/goals.rs24
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