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 <noreply@anthropic.com>
This commit is contained in:
@@ -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<u32> {
|
||||
|
||||
@@ -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]
|
||||
|
||||
Reference in New Issue
Block a user