1
2
Fork 0
mirror of https://github.com/mat-1/azalea.git synced 2025-08-02 14:26:04 +00:00

add new impl for ReachBlockPosGoal and optimize slightly

This commit is contained in:
xosc 2025-05-09 18:22:22 +12:00
parent f1b4ea876e
commit 21c15a2dc2

View file

@ -194,8 +194,24 @@ impl<T: Goal> Goal for AndGoals<T> {
#[derive(Clone, Debug)]
pub struct ReachBlockPosGoal {
pub pos: BlockPos,
pub distance: f32,
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 {
@ -203,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 = (self.distance + 2.).ceil() as i32;
let actual_pick_range = self.distance.into();
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;
}
@ -217,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