mirror of
https://github.com/mat-1/azalea.git
synced 2025-08-02 06:16:04 +00:00
add distance param for ReachBlockPosGoal (#220)
* add distance param for ReachBlockPosGoal * add new impl for ReachBlockPosGoal and optimize slightly
This commit is contained in:
parent
6a5a88700c
commit
b35904a0b5
1 changed files with 19 additions and 5 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Reference in a new issue