From 54acb709e403423f4a84bba8022f31e3d2f6d230 Mon Sep 17 00:00:00 2001 From: Ludovic Marie <136255825+ludovic111@users.noreply.github.com> Date: Fri, 16 Oct 2026 15:21:16 +0200 Subject: [PATCH] Mobs: shape only the cells that can support them Entity.checkSupportingBlock runs findSupportingBlock after every move of a mob on the ground. Horizon looked up and built the collision shape of every cell of the cursor (27 to 48 per call, twice when it falls back to where the mob came from). Like BlockCollisions' cursor, a block whose shape stays inside its own cell (neither hasLargeCollisionShape nor a moving piston) can only meet the area when its cell does, so only those cells, and large shapes such as fences, are shaped now. The pick is a total order, so visiting column by column finds the same block. Co-Authored-By: Claude Opus 5.5 --- crates/horizon-client/src/mobs/living.rs | 28 ++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/crates/horizon-client/src/mobs/living.rs b/crates/horizon-client/src/mobs/living.rs index 772041edd..6bf246541 100644 --- a/crates/horizon-client/src/mobs/living.rs +++ b/crates/horizon-client/src/mobs/living.rs @@ -139,16 +139,40 @@ impl MobWorld<'_> { /// `Level.findSupportingBlock`: of the blocks whose collision shape /// meets `area`, the one whose centre is nearest `from` (ties: the /// greatest by `Vec3i.compareTo`, y then z then x). + /// + /// Like `BlockCollisions`' cursor, a block whose shape stays inside its + /// own cell (not `hasLargeCollisionShape`, not a moving piston) is only + /// shaped when that cell meets `area`: elsewhere it cannot. The pick is + /// a total order, so the column-by-column visit finds the same block. pub fn supporting_block(&self, area: Aabb, from: Vec3) -> Option<[i32; 3]> { use horizon_core::geometry::Axis; let range = |axis| { (area.min(axis) - 1.0e-7).floor() as i32 - 1 ..=(area.max(axis) + 1.0e-7).floor() as i32 + 1 }; + // Aabb.intersects of the unit cell at `c` along one axis. + let meets = |axis, c: i32| { + let c = f64::from(c); + c < area.max(axis) && c + 1.0 > area.min(axis) + }; let mut best: Option<(f64, [i32; 3])> = None; - for y in range(Axis::Y) { + for x in range(Axis::X) { for z in range(Axis::Z) { - for x in range(Axis::X) { + let Some(chunk) = self.world.chunks.get(&(x >> 4, z >> 4)) else { + continue; + }; + let column = meets(Axis::X, x) && meets(Axis::Z, z); + for y in range(Axis::Y) { + let state = chunk.block(x & 15, y, z & 15); + let Ok(block) = self.collision.collision_block(state) else { + continue; + }; + if !block.large_collision_shape + && !block.moving_piston + && !(column && meets(Axis::Y, y)) + { + continue; + } if !self .block_collision_boxes(x, y, z) .iter()