aboutsummaryrefslogtreecommitdiff
path: root/azalea-physics
diff options
context:
space:
mode:
authormat <git@matdoes.dev>2025-06-02 23:44:49 -0900
committermat <git@matdoes.dev>2025-06-02 23:44:49 -0900
commit415c0d873e7e793bbc8304247b828355d3ea8118 (patch)
tree9400981cd7767155bd710f8dba45e35404b68449 /azalea-physics
parentcc3e64a3151398046408a7b97c339d32700cc541 (diff)
downloadazalea-drasl-415c0d873e7e793bbc8304247b828355d3ea8118.tar.xz
fix CubeVoxelShape::find_index
Diffstat (limited to 'azalea-physics')
-rw-r--r--azalea-physics/src/collision/shape.rs18
1 files changed, 11 insertions, 7 deletions
diff --git a/azalea-physics/src/collision/shape.rs b/azalea-physics/src/collision/shape.rs
index 902ae20c..59671622 100644
--- a/azalea-physics/src/collision/shape.rs
+++ b/azalea-physics/src/collision/shape.rs
@@ -399,8 +399,13 @@ impl VoxelShape {
}
pub fn find_index(&self, axis: Axis, coord: f64) -> i32 {
- let upper_limit = (self.shape().size(axis) + 1) as i32;
- binary_search(0, upper_limit, |t| coord < self.get(axis, t as usize)) - 1
+ match self {
+ VoxelShape::Cube(s) => s.find_index(axis, coord),
+ _ => {
+ let upper_limit = (self.shape().size(axis) + 1) as i32;
+ binary_search(0, upper_limit, |t| coord < self.get(axis, t as usize)) - 1
+ }
+ }
}
pub fn clip(&self, from: &Vec3, to: &Vec3, block_pos: &BlockPos) -> Option<BlockHitResult> {
@@ -669,11 +674,10 @@ impl CubeVoxelShape {
axis.choose(&self.x_coords, &self.y_coords, &self.z_coords)
}
- // unused
- // fn find_index(&self, axis: Axis, coord: f64) -> i32 {
- // let n = self.shape().size(axis);
- // (f64::clamp(coord * (n as f64), -1f64, n as f64)) as i32
- // }
+ fn find_index(&self, axis: Axis, coord: f64) -> i32 {
+ let n = self.shape().size(axis);
+ f64::floor(f64::clamp(coord * (n as f64), -1f64, n as f64)) as i32
+ }
}
#[derive(Debug)]