From c626f696f55593bdfa4dda320278a52a1c24a55b Mon Sep 17 00:00:00 2001 From: Ludovic Marie <136255825+ludovic111@users.noreply.github.com> Date: Sun, 11 Oct 2026 15:41:00 +0200 Subject: [PATCH] Set dispensed mobs down as EntityType.getYOffset does Only the collision shapes overlapping the spawn block stop the fall, so a wide mob beside the dispenser no longer lands a block high. Spawn egg cases compare that the new mob speaks and where, not which of its voices its own unseeded random picked. Co-Authored-By: Claude Opus 5.5 --- crates/horizon-client/src/game/dispenser.rs | 21 ++++++++++++++++----- tools/test_dispenser_parity.py | 15 ++++++++++++--- 2 files changed, 28 insertions(+), 8 deletions(-) diff --git a/crates/horizon-client/src/game/dispenser.rs b/crates/horizon-client/src/game/dispenser.rs index 26f5e0b50..bb987a930 100644 --- a/crates/horizon-client/src/game/dispenser.rs +++ b/crates/horizon-client/src/game/dispenser.rs @@ -682,23 +682,34 @@ impl Game<'_> { } out } - /// The Y offset `EntityType.getYOffset` finds for a box set down into a block. + /// `EntityType.getYOffset(level, pos, false, box)`: the entity box set on + /// top of the block (`setPos(x + 0.5, y + 1, z + 0.5)`) falls one block + /// against the collision shapes overlapping that block alone. fn drop_offset(&self, width: f64, height: f64, p: Pos) -> f64 { + use horizon_world::{block_collision_scan::BlockCollisionScan, collision_context::CollisionContext}; let h = width / 2.0; let (x, z) = (f64::from(p.0) + 0.5, f64::from(p.2) + 0.5); let y = f64::from(p.1) + 1.0; - let bounds = Aabb::new( + let entity = Aabb::new( Vec3::new(x - h, y, z - h), Vec3::new(x + h, y + height, z + h), ); + let cell = Aabb::new( + Vec3::new(f64::from(p.0), f64::from(p.1), f64::from(p.2)), + Vec3::new(f64::from(p.0) + 1.0, f64::from(p.1) + 1.0, f64::from(p.2) + 1.0), + ); let mut scene = SceneCollisions { world: &self.world, binding: self.collision, }; - match scene.resolve(bounds, Vec3::new(0.0, -1.0, 0.0), 0.0, false) { - Ok(moved) => 1.0 + moved.y, - Err(_) => 0.0, + let mut amount = -1.0; + // Level.getCollisions(null, aabb): CollisionContext.empty(). + if let Ok(scan) = BlockCollisionScan::new(&mut scene, CollisionContext::empty(false), cell, false, 1_000_000) { + for hit in scan.flatten() { + amount = hit.shape.collide(horizon_core::geometry::Axis::Y, entity, amount); + } } + 1.0 + amount } /// `EntityType.spawn(.., pos, reason, tryMoveDown, false)` for a mob. fn spawn_mob_at(&mut self, kind: &str, p: Pos, try_move_down: bool) -> Option { diff --git a/tools/test_dispenser_parity.py b/tools/test_dispenser_parity.py index 33792488d..4dbb83b13 100644 --- a/tools/test_dispenser_parity.py +++ b/tools/test_dispenser_parity.py @@ -297,6 +297,13 @@ FINALIZED = ('_spawn_egg', 'salmon_bucket', 'cod_bucket', 'pufferfish_bucket', ' def finalizes(case): return any(any(tag in i[4] for tag in FINALIZED) for i in case['items'] if i[:3] == [0, 0, 0]) +def voice(line): + parts = line.split(' ') + if parts[0] == 'S' and len(parts) == 3 and parts[2].lstrip('~').startswith('minecraft:entity.'): + parts[2] = 'entity-voice' + return ' '.join(parts) + + def run(command, **kwargs): done = subprocess.run(command, capture_output=True, text=True, **kwargs) if done.returncode: @@ -378,9 +385,11 @@ def main(): continue if finalizes(case): unseeded += 1 - # The spawned mob's variant (and so its voice) is chosen in finalizeSpawn too. - a = [line for line in a if not line.startswith('rng ') and not line.endswith('.ambient')] - b = [line for line in b if not line.startswith('rng ') and not line.endswith('.ambient')] + # EntityType.spawn plays the new mob's ambient sound: which one (a + # wolf pants or barks, in its sound variant) comes from the mob's + # own unseeded random, so only that a voice plays, and where, is compared. + a = [voice(line) for line in a if not line.startswith('rng ')] + b = [voice(line) for line in b if not line.startswith('rng ')] if not same(a, b): item = next(i[4] for i in case['items'] if i[:3] == [0, 0, 0]) block = facts.states[case['cells'][0][3]][0].split(':')[1]