From 59a966a9e382295bd237de5715eb24b64f255e60 Mon Sep 17 00:00:00 2001 From: Ludovic Marie <136255825+ludovic111@users.noreply.github.com> Date: Mon, 12 Oct 2026 16:49:20 +0200 Subject: [PATCH] Compare breezes and creakings with vanilla in the mob AI harness Eight scenarios: a breeze alone and fighting a player near, inside and beyond its jump circle; a creaking alone, watched, unwatched, and woken then hunting once the player turns away (a new player turn= option). The oracle now faces the player +z with its head too (it kept a random head yaw from its creation, which the breeze's jump target reads). Co-Authored-By: Claude Opus 5.5 --- .../horizon-client/examples/mob_ai_probe.rs | 36 +++++++++++++++++-- .../horizonlab/parity/VanillaMobAiOracle.java | 23 +++++++++++- tools/test_mob_ai_parity.py | 11 ++++++ 3 files changed, 66 insertions(+), 4 deletions(-) diff --git a/crates/horizon-client/examples/mob_ai_probe.rs b/crates/horizon-client/examples/mob_ai_probe.rs index 4c5178fae..80e994288 100644 --- a/crates/horizon-client/examples/mob_ai_probe.rs +++ b/crates/horizon-client/examples/mob_ai_probe.rs @@ -43,6 +43,8 @@ struct Scenario { blocks: Vec>, player: Option<[f64; 3]>, creative: bool, + /// The tick from which the player faces another yaw. + turn: Option<(i32, f32)>, mobs: Vec, } @@ -79,7 +81,16 @@ fn parse(text: &str) -> Vec { f[2].parse().unwrap(), f[3].parse().unwrap(), ]); - s.creative = f.get(4) == Some(&"creative"); + for opt in &f[4..] { + if *opt == "creative" { + s.creative = true; + } else if let Some(t) = opt.strip_prefix("turn=") { + let (tick, yaw) = t.split_once(',').unwrap(); + s.turn = Some((tick.parse().unwrap(), yaw.parse().unwrap())); + } else { + panic!("unknown player option {opt}"); + } + } } "mob" => s.mobs.push(MobSpec { kind: f[1].to_owned(), @@ -355,7 +366,9 @@ fn print(out: &mut String, t: i32, i: usize, m: &Mob) { u8::from(m.ai.jumping) ); let _ = write!(out, "\trng {:x}", m.random.state()); - if let Some((acts, mem)) = horizon_client::mobs::villager_brain::describe(m) { + if let Some((acts, mem)) = horizon_client::mobs::villager_brain::describe(m) + .or_else(|| horizon_client::mobs::monster_brain::describe(m)) + { let _ = write!(out, "\tact {acts}\tmem {mem}"); } out.push('\n'); @@ -471,6 +484,11 @@ fn main() -> horizon_client::Result<()> { } } m.random = LegacyRandom::new(spec.seed); + if horizon_client::mobs::monster_brain::has_brain(m.species()) { + // The oracle delays the sensors again with the seeded random + // and seeds RunOne's shuffles with the mob's seed. + horizon_client::mobs::monster_brain::init(&mut m, spec.seed); + } if m.species() == Species::Villager { // The oracle seeds the random after the brain is built, then // delays the sensors again and seeds the gates' shuffles. @@ -483,7 +501,7 @@ fn main() -> horizon_client::Result<()> { } mobs.push(m); } - let player = s.player.map(|p| { + let mut player = s.player.map(|p| { let position = Vec3::new(p[0], p[1], p[2]); PlayerView { position, @@ -516,6 +534,18 @@ fn main() -> horizon_client::Result<()> { } for t in 1..=s.ticks { world.game_time += 1; + if let (Some(p), Some((tick, yaw))) = (player.as_mut(), s.turn) + && t >= tick + { + // Entity.calculateViewVector(0, yaw). + let r = -yaw * horizon_core::geometry::trig::DEG_TO_RAD; + let (cos, sin) = ( + horizon_core::geometry::trig::cos(f64::from(r)), + horizon_core::geometry::trig::sin(f64::from(r)), + ); + p.look = [f64::from(sin), -0.0, f64::from(cos)]; + p.yaw = yaw; + } let snapshot: Vec = mobs.iter().filter(|m| !m.removed).map(seen).collect(); let w = MobWorld { world: &world, diff --git a/mods/horizon/src/test/java/dev/horizonlab/parity/VanillaMobAiOracle.java b/mods/horizon/src/test/java/dev/horizonlab/parity/VanillaMobAiOracle.java index 7185ec400..610523bfe 100644 --- a/mods/horizon/src/test/java/dev/horizonlab/parity/VanillaMobAiOracle.java +++ b/mods/horizon/src/test/java/dev/horizonlab/parity/VanillaMobAiOracle.java @@ -157,6 +157,9 @@ public final class VanillaMobAiOracle { List blocks = new ArrayList<>(); double[] player; boolean creative; + /** The tick from which the player faces turnYaw (head and body), else 0. */ + int turnTick = Integer.MAX_VALUE; + float turnYaw; List mobs = new ArrayList<>(); long levelSeed = 0; } @@ -187,7 +190,14 @@ public final class VanillaMobAiOracle { case "fill", "block" -> s.blocks.add(f); case "player" -> { s.player = new double[] {Double.parseDouble(f[1]), Double.parseDouble(f[2]), Double.parseDouble(f[3])}; - s.creative = f.length > 4 && f[4].equals("creative"); + for (int i = 4; i < f.length; i++) { + if (f[i].equals("creative")) s.creative = true; + else if (f[i].startsWith("turn=")) { + String[] tv = f[i].substring(5).split(","); + s.turnTick = Integer.parseInt(tv[0]); + s.turnYaw = Float.parseFloat(tv[1]); + } else throw new IllegalArgumentException(line); + } } case "mob" -> { MobSpec m = new MobSpec(); @@ -441,6 +451,11 @@ public final class VanillaMobAiOracle { } player.setGameMode(s.creative ? GameType.CREATIVE : GameType.SURVIVAL); player.snapTo(s.player[0], s.player[1], s.player[2], 0.0F, 0.0F); + // snapTo leaves the head and body as the player was created + // (a random head yaw): face +z like the probe's player. + player.setYHeadRot(0.0F); + player.yHeadRotO = 0.0F; + player.setYBodyRot(0.0F); // The player is never ticked during a scenario: give it the water state of // where it stands (isInWater), not the previous scenario's. method(Entity.class, "updateFluidInteraction").invoke(player); @@ -498,6 +513,12 @@ public final class VanillaMobAiOracle { player.hurtTime = 0; player.snapTo(s.player[0], s.player[1], s.player[2], 0.0F, 0.0F); player.setDeltaMovement(Vec3.ZERO); + if (t >= s.turnTick) { + // The view vector follows the head (LivingEntity.getViewYRot). + player.setYRot(s.turnYaw); + player.setYHeadRot(s.turnYaw); + player.setYBodyRot(s.turnYaw); + } } TracingRandom.tick = t; TracingRandom.on = tracing(s) && t >= traceFrom() && t <= traceTo(); diff --git a/tools/test_mob_ai_parity.py b/tools/test_mob_ai_parity.py index 5730d8b3d..235e44e8a 100644 --- a/tools/test_mob_ai_parity.py +++ b/tools/test_mob_ai_parity.py @@ -77,6 +77,17 @@ def scenarios(): 'player 12.5 -60 0.5', 'mob minecraft:villager 0.5 -60 0.5 0 51 persistent', ]) + # Breezes: idle, and fighting a player near, in, and beyond the inner jump circle. + add('breeze_alone', 200, ['mob minecraft:breeze 0.5 -60 0.5 90 61 persistent']) + add('breeze_player', 200, ['player 8.5 -60 0.5', 'mob minecraft:breeze 0.5 -60 0.5 0 62 persistent']) + add('breeze_close', 200, ['player 2.5 -60 1.5', 'mob minecraft:breeze 0.5 -60 0.5 0 63 persistent']) + add('breeze_far', 200, ['player 13.5 -60 6.5', 'mob minecraft:breeze 0.5 -60 0.5 0 64 persistent']) + # Creakings: the player faces +z, so it watches one and turns its back on the other. + add('creaking_alone', 200, ['mob minecraft:creaking 0.5 -60 0.5 90 71 persistent']) + add('creaking_watched', 200, ['player 0.5 -60 -7.5', 'mob minecraft:creaking 0.5 -60 0.5 180 72 persistent']) + add('creaking_behind', 200, ['player 0.5 -60 8.5', 'mob minecraft:creaking 0.5 -60 0.5 0 73 persistent']) + # Woken while watched, then free to hunt and hit once the player turns away. + add('creaking_attack', 240, ['player 0.5 -60 -7.5 turn=40,180', 'mob minecraft:creaking 0.5 -60 0.5 180 74 persistent']) return s