mirror of
https://github.com/mat-1/azalea.git
synced 2025-08-02 06:16:04 +00:00
add BlockPos::center_bottom
This commit is contained in:
parent
f3a5e91a8c
commit
1edb9d3448
2 changed files with 13 additions and 3 deletions
|
@ -358,6 +358,16 @@ impl BlockPos {
|
|||
}
|
||||
}
|
||||
|
||||
/// Get the center of the bottom of a block position by adding 0.5 to the x
|
||||
/// and z coordinates.
|
||||
pub fn center_bottom(&self) -> Vec3 {
|
||||
Vec3 {
|
||||
x: self.x as f64 + 0.5,
|
||||
y: self.y as f64,
|
||||
z: self.z as f64 + 0.5,
|
||||
}
|
||||
}
|
||||
|
||||
/// Convert the block position into a Vec3 without centering it.
|
||||
pub fn to_vec3_floored(&self) -> Vec3 {
|
||||
Vec3 {
|
||||
|
|
|
@ -113,14 +113,14 @@ impl Goal for RadiusGoal {
|
|||
let dx = (self.pos.x - n.x) as f32;
|
||||
let dy = (self.pos.y - n.y) as f32;
|
||||
let dz = (self.pos.z - n.z) as f32;
|
||||
dx * dx + dy * dy + dz * dz
|
||||
dx.powi(2) + dy.powi(2) + dz.powi(2)
|
||||
}
|
||||
fn success(&self, n: BlockPos) -> bool {
|
||||
let n = n.center();
|
||||
let dx = (self.pos.x - n.x) as f32;
|
||||
let dy = (self.pos.y - n.y) as f32;
|
||||
let dz = (self.pos.z - n.z) as f32;
|
||||
dx * dx + dy * dy + dz * dz <= self.radius * self.radius
|
||||
dx.powi(2) + dy.powi(2) + dz.powi(2) <= self.radius.powi(2)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -226,7 +226,7 @@ impl Goal for ReachBlockPosGoal {
|
|||
return false;
|
||||
}
|
||||
|
||||
let eye_position = n.to_vec3_floored() + Vec3::new(0.5, 1.62, 0.5);
|
||||
let eye_position = n.center_bottom().up(1.62);
|
||||
let look_direction = crate::direction_looking_at(&eye_position, &self.pos.center());
|
||||
let block_hit_result = azalea_client::interact::pick_block(
|
||||
&look_direction,
|
||||
|
|
Loading…
Add table
Reference in a new issue