aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormat <git@matdoes.dev>2025-06-02 17:56:16 -0800
committermat <git@matdoes.dev>2025-06-02 17:56:16 -0800
commit1edb9d34486b432c84351692aa82a3c0328a7d69 (patch)
treed3f456e52772074849d42131fb65e4d50f390c5a
parentf3a5e91a8ccbcd03a239aa3565dbfddabb26fa76 (diff)
downloadazalea-drasl-1edb9d34486b432c84351692aa82a3c0328a7d69.tar.xz
add BlockPos::center_bottom
-rw-r--r--azalea-core/src/position.rs10
-rw-r--r--azalea/src/pathfinder/goals.rs6
2 files changed, 13 insertions, 3 deletions
diff --git a/azalea-core/src/position.rs b/azalea-core/src/position.rs
index beb8eedb..7cb8b143 100644
--- a/azalea-core/src/position.rs
+++ b/azalea-core/src/position.rs
@@ -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 {
diff --git a/azalea/src/pathfinder/goals.rs b/azalea/src/pathfinder/goals.rs
index 36fca762..aa6f357a 100644
--- a/azalea/src/pathfinder/goals.rs
+++ b/azalea/src/pathfinder/goals.rs
@@ -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,