diff --git a/crates/horizon-client/examples/mob_ai_probe.rs b/crates/horizon-client/examples/mob_ai_probe.rs index f28ee853c..7058d448f 100644 --- a/crates/horizon-client/examples/mob_ai_probe.rs +++ b/crates/horizon-client/examples/mob_ai_probe.rs @@ -142,6 +142,8 @@ fn goal_name(m: &Mob, name: &str) -> String { let vanilla = match name { "Float" => "FloatGoal", "Stroll" => "WaterAvoidingRandomStrollGoal", + "RandomStroll" => "RandomStrollGoal", + "RandomSwimming" => "RandomSwimmingGoal", "LookAtPlayer" => "LookAtPlayerGoal", "RandomLookAround" => "RandomLookAroundGoal", "HurtByTarget" => "HurtByTargetGoal", @@ -248,7 +250,9 @@ fn player_hurt(player: Option<&PlayerView>, e: &MobEvent) -> bool { fn print(out: &mut String, t: i32, i: usize, m: &Mob) { let _ = write!(out, "{t} {i}"); if m.removed { - let _ = writeln!(out, " removed DISCARDED"); + // Entity.RemovalReason: the end of the death animation, else a discard. + let reason = if m.alive() { "DISCARDED" } else { "KILLED" }; + let _ = writeln!(out, " removed {reason}"); return; } let p = m.position; @@ -506,6 +510,8 @@ fn main() -> horizon_client::Result<()> { difficulty: LocalDifficulty::new(2, world.day_time, 0, 0.0), end: false, world_seed: 0, + // FlatLevelSource.getSeaLevel. + sea_level: -63, }; let mut events = Vec::new(); #[allow(unused_mut)] // filled only with the rng-trace feature diff --git a/crates/horizon-client/src/entity_nbt.rs b/crates/horizon-client/src/entity_nbt.rs index b38fb8469..1dfe273e7 100644 --- a/crates/horizon-client/src/entity_nbt.rs +++ b/crates/horizon-client/src/entity_nbt.rs @@ -407,7 +407,9 @@ pub fn mob_to_nbt(m: &Mob, uuid: [i32; 4], raw: Option<&Tag>) -> Tag { } // Skeletons are spawned holding a bow (finalizeSpawn); a mob loaded // from NBT keeps only its saved equipment. - "minecraft:skeleton" | "minecraft:stray" | "minecraft:bogged" if raw.is_none() => { + "minecraft:skeleton" | "minecraft:stray" | "minecraft:bogged" + if raw.is_none() && m.extra.main_hand.as_deref() == Some("minecraft:bow") => + { map.entry("equipment".into()).or_insert_with(|| { Tag::compound([( "mainhand", diff --git a/crates/horizon-client/src/game/creatures.rs b/crates/horizon-client/src/game/creatures.rs index bceb78131..38c56d408 100644 --- a/crates/horizon-client/src/game/creatures.rs +++ b/crates/horizon-client/src/game/creatures.rs @@ -366,6 +366,7 @@ impl Game<'_> { mob_griefing: self.ui.rules.bool("mob_griefing"), end: self.dim == Dim::End, world_seed: self.level.seed, + sea_level: if self.dim == Dim::Nether { 32 } else { 63 }, difficulty: self.local_difficulty( self.player .as_ref() @@ -2391,6 +2392,7 @@ fn damage_type(kind: horizon_client::mobs::DamageKind, player: bool) -> &'static K::InWall => "minecraft:in_wall", K::Thorns => "minecraft:thorns", K::SonicBoom => "minecraft:sonic_boom", + K::OutOfWorld => "minecraft:out_of_world", } } /// A Horizon item stack as a loot stack (id, count, damage, enchantments). diff --git a/crates/horizon-client/src/mobs.rs b/crates/horizon-client/src/mobs.rs index fc0d15a0f..efd9bc88a 100644 --- a/crates/horizon-client/src/mobs.rs +++ b/crates/horizon-client/src/mobs.rs @@ -359,6 +359,8 @@ pub enum DamageKind { InWall, Thorns, SonicBoom, + /// `fell_out_of_world`: below the world's floor. + OutOfWorld, } /// A damage source: its type, the attacking entity and where it came from. #[derive(Clone, Copy, Debug)] @@ -414,6 +416,7 @@ impl Damage { | DamageKind::InWall | DamageKind::Generic | DamageKind::SonicBoom + | DamageKind::OutOfWorld ) } pub fn is_fire(&self) -> bool { @@ -436,6 +439,7 @@ impl Damage { | DamageKind::Cactus | DamageKind::Generic | DamageKind::InWall + | DamageKind::OutOfWorld ) } pub fn is_projectile(&self) -> bool { @@ -960,6 +964,8 @@ pub struct MobWorld<'a> { pub end: bool, /// The world seed (slime chunks). pub world_seed: i64, + /// `Level.getSeaLevel` (63 in the overworld, -63 in a flat world). + pub sea_level: i32, } impl Mob { pub fn new(id: u32, kind: Arc, position: Vec3, yaw: f32) -> Self { diff --git a/crates/horizon-client/src/mobs/ai.rs b/crates/horizon-client/src/mobs/ai.rs index f001a360a..180fcfe0a 100644 --- a/crates/horizon-client/src/mobs/ai.rs +++ b/crates/horizon-client/src/mobs/ai.rs @@ -221,6 +221,9 @@ fn pre_tick(m: &mut Mob, events: &mut Vec) { } /// Move controls implemented by the species (MoveKind::Custom). pub fn custom_move_control(m: &mut Mob, w: &MobWorld, events: &mut Vec) { + if m.species() == Species::Drowned { + return undead::drowned_move_control(m, w); + } if m.species() == Species::Ghast { return super::nether::ghast_move_control(m, w); } @@ -264,6 +267,47 @@ fn generic(m: &mut Mob) { g.add(7, RandomLookAround::default()); } } +/// Subclasses of `net.minecraft.world.entity.monster.Monster`. +pub fn is_monster(s: Species) -> bool { + use Species as S; + matches!( + s, + S::Zombie + | S::Husk + | S::Drowned + | S::ZombieVillager + | S::ZombifiedPiglin + | S::Giant + | S::Skeleton + | S::Stray + | S::Bogged + | S::Parched + | S::WitherSkeleton + | S::Creeper + | S::Spider + | S::CaveSpider + | S::Enderman + | S::Endermite + | S::Silverfish + | S::Witch + | S::Pillager + | S::Vindicator + | S::Evoker + | S::Illusioner + | S::Ravager + | S::Vex + | S::Piglin + | S::PiglinBrute + | S::Zoglin + | S::Blaze + | S::Guardian + | S::ElderGuardian + | S::Breeze + | S::Creaking + | S::Warden + | S::Wither + ) +} /// One full entity tick. Returns false when the mob is gone. pub fn tick(m: &mut Mob, w: &MobWorld, events: &mut Vec) -> bool { if m.removed { @@ -310,7 +354,7 @@ pub fn tick(m: &mut Mob, w: &MobWorld, events: &mut Vec) -> bool { m.update_walk_animation(); m.anim.end_tick(m.ai.swinging); tick_swing(m); - m.position.y > -128.0 + true } /// LivingEntity.updateSwingTime (6-tick swing duration). fn tick_swing(m: &mut Mob) { @@ -355,6 +399,10 @@ fn base_tick(m: &mut Mob, w: &MobWorld, events: &mut Vec) { m.fire_ticks -= 1; } } + // Entity.checkBelowWorld: LivingEntity.onBelowWorld hurts 4 a tick. + if m.position.y < f64::from(crate::chunk::MIN_Y - 64) { + m.damage(4.0, Damage::of(DamageKind::OutOfWorld)); + } if m.alive() { // LivingEntity.baseTick: suffocation inside full blocks. let (ex, ey, ez) = ( @@ -494,6 +542,12 @@ fn ai_step(m: &mut Mob, w: &MobWorld, events: &mut Vec) { .is_some_and(|t| t.position.distance_squared(m.position) > 121.0); super::witch::ai_step(m, events, far); } + // Monster.aiStep: updateNoActionTime (Raider: always +2). + if is_monster(m.species()) + && (super::raider::is_raider(m.species()) || super::hostile::mob_brightness(m, w) > 0.5) + { + m.ai.no_action_time += 2; + } if super::creaking::is_creaking(m) { super::creaking::update(m, w, events); } @@ -1014,6 +1068,9 @@ pub fn ate(m: &mut Mob) { } /// Species-specific travel (fish, squid, dolphins swim with their own rules). pub fn custom_travel(m: &mut Mob, w: &MobWorld, input: Vec3, events: &mut Vec) -> bool { + if m.species() == Species::Drowned { + return undead::drowned_travel(m, w, input, events); + } match family(m.species()) { Family::Aquatic => aquatic::travel(m, w, input, events), Family::Guardian => super::guardian::travel(m, w, input, events), diff --git a/crates/horizon-client/src/mobs/control.rs b/crates/horizon-client/src/mobs/control.rs index 361b1b13a..e4637bb0c 100644 --- a/crates/horizon-client/src/mobs/control.rs +++ b/crates/horizon-client/src/mobs/control.rs @@ -230,7 +230,7 @@ impl Mob { self.ai.speed = speed; self.ai.zza = speed; } - fn ground_move_tick(&mut self, w: &MobWorld, attr_speed: f64) { + pub(crate) fn ground_move_tick(&mut self, w: &MobWorld, attr_speed: f64) { match self.ai.mov.operation { Operation::Strafe => { let speed = self.ai.mov.speed_modifier as f32 * attr_speed as f32; diff --git a/crates/horizon-client/src/mobs/goals.rs b/crates/horizon-client/src/mobs/goals.rs index b1c7ecb26..5869d4478 100644 --- a/crates/horizon-client/src/mobs/goals.rs +++ b/crates/horizon-client/src/mobs/goals.rs @@ -585,6 +585,15 @@ impl Stroll { } impl Goal for Stroll { goal_clone!(); + fn name(&self) -> &'static str { + if self.water_avoiding.is_some() { + "Stroll" + } else if self.swim { + "RandomSwimming" + } else { + "RandomStroll" + } + } fn flags(&self) -> u8 { MOVE } @@ -648,6 +657,11 @@ pub struct LookAtPlayer { pub range: f32, pub probability: f32, pub only_horizontal: bool, + /// `LookAtPlayerGoal(Mob.class, ...)`: the nearest mob, not the player. + pub mobs: bool, + /// InteractGoal: LOOK and MOVE. + pub interact: bool, + look_at: Option, look_time: i32, } impl LookAtPlayer { @@ -656,45 +670,110 @@ impl LookAtPlayer { range, probability: 0.02, only_horizontal: false, + mobs: false, + interact: false, + look_at: None, look_time: 0, } } + /// `LookAtPlayerGoal(this, Mob.class, range)`. + pub fn mobs(range: f32) -> Self { + Self { + mobs: true, + ..Self::new(range) + } + } + /// `InteractGoal(this, Player.class, range, probability)`. + pub fn interact(range: f32, probability: f32) -> Self { + Self { + interact: true, + ..Self::new(range).probability(probability) + } + } pub fn probability(mut self, p: f32) -> Self { self.probability = p; self } + /// The goal's look target, alive, with its position and eye height. + fn look_target(&self, w: &MobWorld) -> Option<(Vec3, f64)> { + match self.look_at? { + Who::Player => w + .player + .as_ref() + .filter(|p| p.alive) + .map(|p| (p.position, p.eye[1])), + Who::Mob(id) => w + .seen(id) + .filter(|s| s.alive) + .map(|s| (s.position, s.eye_y)), + } + } } impl Goal for LookAtPlayer { goal_clone!(); fn flags(&self) -> u8 { - LOOK + if self.interact { LOOK | MOVE } else { LOOK } + } + fn name(&self) -> &'static str { + if self.interact { + "InteractGoal" + } else { + "LookAtPlayer" + } } fn can_use(&mut self, m: &mut Mob, cx: &mut Cx) -> bool { if m.random.next_float() >= self.probability { return false; } - // level.getNearestPlayer(forNonCombat().range(lookDistance)). - m.can_see_player(cx.w, f64::from(self.range)) + self.look_at = None; + let range = f64::from(self.range); + if !self.mobs { + // level.getNearestPlayer(forNonCombat().range(lookDistance)). + if m.can_see_player(cx.w, range) { + self.look_at = Some(Who::Player); + } + return self.look_at.is_some(); + } + // level.getNearestEntity(mobs in the box inflated by (range, 3, range)). + let area = m.bounds().inflate(Vec3::new(range, 3.0, range)); + let id = m.id; + let at = Vec3::new(m.position.x, m.eye_y(), m.position.z); + let candidates: Vec<(u32, Vec3)> = + cx.w.others + .iter() + .filter(|s| s.id != id && s.alive && s.bounds.intersects(area)) + .map(|s| (s.id, s.position)) + .collect(); + let mut best: Option<(u32, f64)> = None; + for (cid, pos) in candidates { + let reach = range.max(2.0); + if m.distance_sqr(pos) > reach * reach || !m.sees(cx.w, Who::Mob(cid)) { + continue; + } + let d = pos.distance_squared(at); + if best.is_none_or(|(_, b)| d < b) { + best = Some((cid, d)); + } + } + self.look_at = best.map(|(cid, _)| Who::Mob(cid)); + self.look_at.is_some() } fn can_continue(&mut self, m: &mut Mob, cx: &mut Cx) -> bool { - let Some(p) = &cx.w.player else { return false }; - p.alive - && m.distance_sqr(p.position) <= f64::from(self.range * self.range) - && self.look_time > 0 + let Some((pos, _)) = self.look_target(cx.w) else { + return false; + }; + m.distance_sqr(pos) <= f64::from(self.range * self.range) && self.look_time > 0 } fn start(&mut self, m: &mut Mob, _: &mut Cx) { self.look_time = reduced(40 + m.random.next_int_bound(40).unwrap_or(0)); } + fn stop(&mut self, _: &mut Mob, _: &mut Cx) { + self.look_at = None; + } fn tick(&mut self, m: &mut Mob, cx: &mut Cx) { - if let Some(p) = &cx.w.player - && p.alive - { - let y = if self.only_horizontal { - m.eye_y() - } else { - p.eye[1] - }; - m.look_at([p.position.x, y, p.position.z]); + if let Some((pos, eye)) = self.look_target(cx.w) { + let y = if self.only_horizontal { m.eye_y() } else { eye }; + m.look_at([pos.x, y, pos.z]); self.look_time -= 1; } } diff --git a/crates/horizon-client/src/mobs/illager.rs b/crates/horizon-client/src/mobs/illager.rs index f2879887c..46d3ff9d2 100644 --- a/crates/horizon-client/src/mobs/illager.rs +++ b/crates/horizon-client/src/mobs/illager.rs @@ -65,6 +65,7 @@ pub fn register_pillager(m: &mut Mob) { g.add(3, CrossbowAttack::new(1.0, 8.0)); g.add(8, Stroll::new(0.6)); g.add(9, LookAtPlayer::new(15.0).probability(1.0)); + g.add(10, LookAtPlayer::mobs(15.0)); targets(m, false); } pub fn register_vindicator(m: &mut Mob) { @@ -74,7 +75,8 @@ pub fn register_vindicator(m: &mut Mob) { g.add(4, super::raider::HoldGroundAttack::new(10.0)); g.add(5, MeleeAttack::new(1.0, false)); g.add(8, Stroll::new(0.6)); - g.add(9, LookAtPlayer::new(3.0)); + g.add(9, LookAtPlayer::new(3.0).probability(1.0)); + g.add(10, LookAtPlayer::mobs(8.0)); targets(m, true); // VindicatorJohnnyAttackGoal: a vindicator named Johnny attacks anything. m.ai.targets.add( @@ -95,11 +97,13 @@ pub fn register_evoker(m: &mut Mob) { 2, super::goals::AvoidEntity::new(super::goals::Avoid::Player, 8.0, 0.6, 1.0), ); + g.add(3, avoid_creaking(0.6, 1.0)); g.add(4, UseSpell::new(Spell::Vexes)); g.add(5, UseSpell::new(Spell::Fangs)); g.add(6, UseSpell::new(Spell::Wololo)); g.add(8, Stroll::new(0.6)); g.add(9, LookAtPlayer::new(3.0).probability(1.0)); + g.add(10, LookAtPlayer::mobs(8.0)); targets(m, false); } #[derive(Clone, Copy, Debug, PartialEq, Eq)] diff --git a/crates/horizon-client/src/mobs/illusioner.rs b/crates/horizon-client/src/mobs/illusioner.rs index ee36acf40..ec17abad7 100644 --- a/crates/horizon-client/src/mobs/illusioner.rs +++ b/crates/horizon-client/src/mobs/illusioner.rs @@ -39,7 +39,7 @@ pub fn register(m: &mut Mob) { g.add(6, BowAttack::new(0.5, 20, 15.0)); g.add(8, Stroll::new(0.6)); g.add(9, LookAtPlayer::new(3.0).probability(1.0)); - g.add(10, LookAtPlayer::new(8.0)); + g.add(10, LookAtPlayer::mobs(8.0)); let mut hurt = HurtByTarget::new().alert(); hurt.ignore = vec![ Species::Pillager, diff --git a/crates/horizon-client/src/mobs/living.rs b/crates/horizon-client/src/mobs/living.rs index 8d294cdcc..99d7417b1 100644 --- a/crates/horizon-client/src/mobs/living.rs +++ b/crates/horizon-client/src/mobs/living.rs @@ -474,7 +474,11 @@ impl Mob { if self.horizontal_collision && self.kind.flags.climber { m.y = 0.2; } - m = Vec3::new(m.x * f64::from(slow), m.y * 0.8, m.z * f64::from(slow)); + m = Vec3::new( + m.x * f64::from(slow), + m.y * f64::from(0.8_f32), + m.z * f64::from(slow), + ); self.velocity = fluid_falling(gravity, falling, m); } else { self.move_relative(0.02, input); @@ -482,7 +486,7 @@ impl Mob { if self.fluids.lava <= self.fluid_jump_threshold() { self.velocity = Vec3::new( self.velocity.x * 0.5, - self.velocity.y * 0.8, + self.velocity.y * f64::from(0.8_f32), self.velocity.z * 0.5, ); self.velocity = fluid_falling(gravity, falling, self.velocity); @@ -502,11 +506,11 @@ impl Mob { if self.horizontal_collision && w.no_collision(self.bounds().move_by(Vec3::new( m.x, - m.y + 0.6 - self.position.y + old_y, + m.y + f64::from(0.6_f32) - self.position.y + old_y, m.z, ))) { - self.velocity.y = 0.3; + self.velocity.y = f64::from(0.3_f32); } } /// The jump part of LivingEntity.aiStep. diff --git a/crates/horizon-client/src/mobs/ravager.rs b/crates/horizon-client/src/mobs/ravager.rs index 4b982687d..ef71b8f77 100644 --- a/crates/horizon-client/src/mobs/ravager.rs +++ b/crates/horizon-client/src/mobs/ravager.rs @@ -21,6 +21,7 @@ pub fn register(m: &mut Mob) { g.add(4, MeleeAttack::new(1.0, true)); g.add(5, Stroll::avoiding_water(0.4)); g.add(6, LookAtPlayer::new(6.0)); + g.add(10, LookAtPlayer::mobs(8.0)); let mut hurt = HurtByTarget::new().alert(); hurt.ignore = vec![ Species::Pillager, diff --git a/crates/horizon-client/src/mobs/spawn_rules.rs b/crates/horizon-client/src/mobs/spawn_rules.rs index 40806b04e..22f9206af 100644 --- a/crates/horizon-client/src/mobs/spawn_rules.rs +++ b/crates/horizon-client/src/mobs/spawn_rules.rs @@ -586,7 +586,7 @@ impl SpawnLevel for super::MobWorld<'_> { self.thundering } fn sea_level(&self) -> i32 { - if self.nether { 32 } else { 63 } + self.sea_level } fn world_surface(&self, x: i32, z: i32) -> i32 { let top = crate::chunk::MIN_Y + crate::chunk::HEIGHT; diff --git a/crates/horizon-client/src/mobs/spawning.rs b/crates/horizon-client/src/mobs/spawning.rs index cffe7e03d..0bfd5d223 100644 --- a/crates/horizon-client/src/mobs/spawning.rs +++ b/crates/horizon-client/src/mobs/spawning.rs @@ -220,10 +220,15 @@ pub fn finalize(m: &mut Mob, biome: &BiomeFacts, difficulty: &LocalDifficulty) { .into(), ); } - // AbstractSkeleton.populateDefaultEquipmentSlots (the bow is given on - // registration). + // AbstractSkeleton.populateDefaultEquipmentSlots: armour, then a bow. S::Skeleton | S::Stray | S::Bogged | S::Parched => { populate_armor(m, difficulty); + m.extra.main_hand = Some("minecraft:bow".into()); + m.extra.pick_up_loot = m.random.next_float() < 0.55 * difficulty.special(); + } + // WitherSkeleton.populateDefaultEquipmentSlots: a stone sword only. + S::WitherSkeleton => { + m.extra.main_hand = Some("minecraft:stone_sword".into()); m.extra.pick_up_loot = m.random.next_float() < 0.55 * difficulty.special(); } S::Pillager => { diff --git a/crates/horizon-client/src/mobs/trader.rs b/crates/horizon-client/src/mobs/trader.rs index d72760e21..2d7101909 100644 --- a/crates/horizon-client/src/mobs/trader.rs +++ b/crates/horizon-client/src/mobs/trader.rs @@ -44,10 +44,10 @@ pub fn register(m: &mut Mob) { for (species, distance) in [ (Species::Zombie, 8.0), (Species::Evoker, 12.0), - (Species::Illusioner, 12.0), (Species::Vindicator, 8.0), (Species::Vex, 8.0), (Species::Pillager, 15.0), + (Species::Illusioner, 12.0), (Species::Zoglin, 10.0), ] { // `Zombie.class` covers the zombie family. @@ -78,8 +78,8 @@ pub fn register(m: &mut Mob) { ); g.add(4, MoveTowardsRestriction::new(0.35)); g.add(8, Stroll::avoiding_water(0.35)); - g.add(9, LookAtPlayer::new(3.0).probability(1.0)); - g.add(10, LookAtPlayer::new(8.0)); + g.add(9, LookAtPlayer::interact(3.0, 1.0)); + g.add(10, LookAtPlayer::mobs(8.0)); } fn invisible(m: &Mob) -> bool { m.extra.effects.iter().any(|e| e.0 == INVISIBILITY) diff --git a/crates/horizon-client/src/mobs/undead.rs b/crates/horizon-client/src/mobs/undead.rs index 4d2886a00..4d6c76d73 100644 --- a/crates/horizon-client/src/mobs/undead.rs +++ b/crates/horizon-client/src/mobs/undead.rs @@ -56,24 +56,53 @@ pub fn register(m: &mut Mob) { ); } S::Drowned => { + // Zombie.registerGoals, then Drowned.addBehaviourGoals. let g = &mut m.ai.goals; - g.add(1, DrownedGoToWater::default()); - g.add(2, MeleeAttack::new(1.0, false).zombie()); - g.add(5, Stroll::new(1.0)); + g.add(4, AttackTurtleEgg::default()); g.add(8, LookAtPlayer::new(8.0)); g.add(8, RandomLookAround::default()); + g.add(1, DrownedGoToWater::default()); + g.add( + 2, + DrownedTridentAttack(super::witch::RangedAttack::new( + 1.0, + 40, + 40, + 10.0, + drowned_throw, + )), + ); + g.add(2, DrownedAttack(MeleeAttack::new(1.0, false).zombie())); + g.add( + 5, + DrownedGoToBeach(super::goals::MoveToBlock::new(1.0, 8, 2)), + ); + g.add(6, DrownedSwimUp { stuck: false }); + g.add(7, Stroll::new(1.0)); let t = &mut m.ai.targets; - let mut hurt = HurtByTarget::new().alert(); + let mut hurt = HurtByTarget::new().alert().ignoring(&[S::Drowned]); hurt.alert_except = vec![S::ZombifiedPiglin]; t.add(1, hurt); - t.add(2, NearestTarget::player(false).when(drowned_can_attack)); + t.add(2, NearestTarget::player(true).when(drowned_can_attack)); t.add( 3, NearestTarget::species(&[S::Villager, S::WanderingTrader], false), ); t.add(3, NearestTarget::species(&[S::IronGolem], true)); - t.add(3, NearestTarget::species(&[S::Axolotl], true).interval(10)); + t.add(3, NearestTarget::species(&[S::Axolotl], true)); + t.add( + 5, + NearestTarget::new( + super::goals::Prey::Filter(|s| s.species == Species::Turtle && s.baby), + true, + ) + .interval(10), + ); + // DrownedMoveControl, AmphibiousPathNavigation, no water malus. + m.ai.mov.kind = super::control::MoveKind::Custom; + m.ai.nav.kind = super::nav::NavKind::Amphibious; m.ai.nav.can_float = false; + m.set_malus(super::path::PathType::Water, 0.0); } S::Skeleton | S::Stray | S::Bogged | S::Parched | S::WitherSkeleton => { let species = m.species(); @@ -104,30 +133,281 @@ pub fn register(m: &mut Mob) { 3, NearestTarget::species(&[S::Piglin, S::PiglinBrute], true), ); - m.extra.main_hand = Some("minecraft:stone_sword".into()); - m.ai.goals.add(4, MeleeAttack::new(1.2, false)); - } else { - m.extra.main_hand = Some("minecraft:bow".into()); - let interval = if matches!(m.species(), S::Bogged | S::Parched) { - 70 - } else { - 40 - }; - m.ai.goals.add(4, BowAttack::new(1.0, interval, 15.0)); } + // The AbstractSkeleton constructor's reassessWeaponGoal, after + // registerGoals; the weapon itself comes with finalizeSpawn. + let interval = if matches!(species, S::Bogged | S::Parched) { + 70 + } else { + 40 + }; + m.ai.goals.add(4, SkeletonWeapon::new(interval)); } _ => {} } } -fn drowned_can_attack(m: &Mob, w: &super::MobWorld) -> bool { - // Drowned.okTarget: at night or when the target is in water. +/// Drowned.okTarget: at night, or when the target is in water. +fn drowned_can_attack(_m: &Mob, w: &super::MobWorld) -> bool { let Some(p) = &w.player else { return false }; - let (x, y, z) = ( - p.position.x.floor() as i32, - p.position.y.floor() as i32, - p.position.z.floor() as i32, + !w.daylight || in_water_at(w, p.position) +} +/// The target's isInWater, from the water at its feet. +fn in_water_at(w: &super::MobWorld, p: Vec3) -> bool { + let (x, y, z) = (p.x.floor() as i32, p.y.floor() as i32, p.z.floor() as i32); + w.fluid(x, y, z) == crate::blocks::Fluid::Water +} +/// Drowned.okTarget for the current target. +fn drowned_ok_target(m: &Mob, w: &super::MobWorld) -> bool { + m.target_info(w) + .is_some_and(|t| !w.daylight || in_water_at(w, t.position)) +} +// Drowned state: `flag` wantsToSwim (target in water), `flag2` searchingForLand. +/// Drowned.wantsToSwim +pub fn drowned_wants_to_swim(m: &Mob, w: &super::MobWorld) -> bool { + m.extra.flag2 || m.target_info(w).is_some_and(|t| in_water_at(w, t.position)) +} +/// Drowned.DrownedMoveControl +pub fn drowned_move_control(m: &mut Mob, w: &super::MobWorld) { + let target = m.target_info(w); + if drowned_wants_to_swim(m, w) && m.fluids.in_water { + if target.is_some_and(|t| t.position.y > m.position.y) || m.extra.flag2 { + m.velocity = Vec3::new(m.velocity.x, m.velocity.y + 0.002, m.velocity.z); + } + if m.ai.mov.operation != super::control::Operation::MoveTo || m.ai.nav.is_done() { + m.set_speed(0.0); + return; + } + let [wx, wy, wz] = m.ai.mov.wanted; + let (xd, mut yd, zd) = (wx - m.position.x, wy - m.position.y, wz - m.position.z); + let dd = (xd * xd + yd * yd + zd * zd).sqrt(); + yd /= dd; + let y_rot = horizon_core::geometry::trig::atan2_degrees(zd, xd) - 90.0; + m.yaw = super::control::rotlerp(m.yaw, y_rot, 90.0); + m.body_yaw = m.yaw; + let target_speed = (m.ai.mov.speed_modifier * m.movement_speed()) as f32; + let speed = m.ai.speed + 0.125 * (target_speed - m.ai.speed); + m.set_speed(speed); + let s = f64::from(speed); + m.velocity = Vec3::new( + m.velocity.x + s * xd * 0.005, + m.velocity.y + s * yd * 0.1, + m.velocity.z + s * zd * 0.005, + ); + } else { + if !m.on_ground { + m.velocity = Vec3::new(m.velocity.x, m.velocity.y - 0.008, m.velocity.z); + } + let speed = m.movement_speed(); + m.ground_move_tick(w, speed); + } +} +/// Drowned.travelInWater: swimming under water slowly when it wants to. +pub fn drowned_travel( + m: &mut Mob, + w: &super::MobWorld, + input: Vec3, + events: &mut Vec, +) -> bool { + if !(m.fluids.eye_in_water && m.fluids.in_water && drowned_wants_to_swim(m, w)) { + return false; + } + m.move_relative(0.01, input); + m.do_move(w, events); + m.velocity = Vec3::new(m.velocity.x * 0.9, m.velocity.y * 0.9, m.velocity.z * 0.9); + true +} +/// The trident throw of `Drowned.performRangedAttack`, until thrown tridents +/// exist: an arrow-like shot with the trident's damage. +fn drowned_throw(m: &mut Mob, who: Who, _power: f32, cx: &mut Cx) { + let Some(t) = cx.w.target_info(who) else { + return; + }; + let start = Vec3::new(m.position.x, m.eye_y() - 0.1, m.position.z); + let xd = t.position.x - m.position.x; + let yd = t.position.y + (t.bounds.max_position().y - t.bounds.min_position().y) / 3.0 - start.y; + let zd = t.position.z - m.position.z; + let dist = (xd * xd + zd * zd).sqrt(); + let mut p = Projectile::new( + ProjectileKind::Arrow { + base_damage: 8.0, + critical: false, + effect: None, + }, + start, + Some(Who::Mob(m.id)), ); - !w.daylight || w.fluid(x, y, z) == crate::blocks::Fluid::Water || m.fluids.in_water + // The spread draws from the new projectile's own random. + let mut spread = horizon_core::random::LegacyRandom::new(i64::from(m.id) ^ m.age as i64); + p.shoot( + &mut spread, + [xd, yd + dist * f64::from(0.2_f32), zd], + 1.6, + (14 - 2 * 4) as f32, + ); + cx.events.push(MobEvent::Projectile(p)); + let pitch = 1.0 / (m.random.next_float() * 0.4 + 0.8); + cx.events.push(MobEvent::Sound( + "entity.drowned.shoot", + m.center(), + 1.0, + pitch, + )); +} +/// Drowned.DrownedTridentAttackGoal: the ranged goal while holding a trident. +#[derive(Clone, Debug)] +struct DrownedTridentAttack(super::witch::RangedAttack); +impl Goal for DrownedTridentAttack { + goal_clone!(); + fn flags(&self) -> u8 { + self.0.flags() + } + fn name(&self) -> &'static str { + "Drowned$DrownedTridentAttackGoal" + } + fn can_use(&mut self, m: &mut Mob, cx: &mut Cx) -> bool { + self.0.can_use(m, cx) && m.extra.main_hand.as_deref() == Some("minecraft:trident") + } + fn can_continue(&mut self, m: &mut Mob, cx: &mut Cx) -> bool { + self.0.can_continue(m, cx) + } + fn start(&mut self, m: &mut Mob, cx: &mut Cx) { + self.0.start(m, cx); + m.ai.aggressive = true; + } + fn stop(&mut self, m: &mut Mob, cx: &mut Cx) { + self.0.stop(m, cx); + m.ai.aggressive = false; + } + fn every_tick(&self) -> bool { + self.0.every_tick() + } + fn tick(&mut self, m: &mut Mob, cx: &mut Cx) { + self.0.tick(m, cx) + } +} +/// Drowned.DrownedAttackGoal: ZombieAttackGoal on a target it may attack. +#[derive(Clone, Debug)] +struct DrownedAttack(MeleeAttack); +impl Goal for DrownedAttack { + goal_clone!(); + fn flags(&self) -> u8 { + self.0.flags() + } + fn name(&self) -> &'static str { + "Drowned$DrownedAttackGoal" + } + fn can_use(&mut self, m: &mut Mob, cx: &mut Cx) -> bool { + self.0.can_use(m, cx) && drowned_ok_target(m, cx.w) + } + fn can_continue(&mut self, m: &mut Mob, cx: &mut Cx) -> bool { + self.0.can_continue(m, cx) && drowned_ok_target(m, cx.w) + } + fn start(&mut self, m: &mut Mob, cx: &mut Cx) { + self.0.start(m, cx) + } + fn stop(&mut self, m: &mut Mob, cx: &mut Cx) { + self.0.stop(m, cx) + } + fn every_tick(&self) -> bool { + self.0.every_tick() + } + fn tick(&mut self, m: &mut Mob, cx: &mut Cx) { + self.0.tick(m, cx) + } +} +/// Drowned.DrownedGoToBeachGoal: at night, swim near the surface to a +/// standable block with air above. +#[derive(Clone, Debug)] +struct DrownedGoToBeach(super::goals::MoveToBlock); +fn beach_target(w: &super::MobWorld, p: [i32; 3]) -> bool { + let empty = |y: i32| { + let state = w.world.block(p[0], y, p[2]); + w.facts.is_air(state) && w.facts.get(state).fluid == crate::blocks::Fluid::None + }; + // BlockState.entityCanStandOn: a full top face. + empty(p[1] + 1) + && empty(p[1] + 2) + && w.facts.get(w.world.block(p[0], p[1], p[2])).sturdy_full & (1 << 1) != 0 +} +impl Goal for DrownedGoToBeach { + goal_clone!(); + fn flags(&self) -> u8 { + MOVE | super::goals::JUMP + } + fn name(&self) -> &'static str { + "Drowned$DrownedGoToBeachGoal" + } + fn every_tick(&self) -> bool { + true + } + fn can_use(&mut self, m: &mut Mob, cx: &mut Cx) -> bool { + // MoveToBlockGoal.canUse, then the drowned's conditions. + if self.0.next_start > 0 { + self.0.next_start -= 1; + return false; + } + self.0.next_start = super::goals::reduced(200 + m.random.next_int_bound(200).unwrap_or(0)); + self.0.find_nearest(m, cx.w, beach_target) + && !cx.w.daylight + && m.fluids.in_water + && m.position.y >= f64::from(cx.w.sea_level - 3) + } + fn can_continue(&mut self, _m: &mut Mob, cx: &mut Cx) -> bool { + self.0.can_continue(cx.w, beach_target) + } + fn start(&mut self, m: &mut Mob, cx: &mut Cx) { + m.extra.flag2 = false; + self.0.start(m, cx.w); + } + fn tick(&mut self, m: &mut Mob, cx: &mut Cx) { + self.0.tick(m, cx.w); + } +} +/// Drowned.DrownedSwimUpGoal: at night, deep in water, head for the surface. +#[derive(Clone, Debug)] +struct DrownedSwimUp { + stuck: bool, +} +impl Goal for DrownedSwimUp { + goal_clone!(); + fn flags(&self) -> u8 { + 0 + } + fn name(&self) -> &'static str { + "Drowned$DrownedSwimUpGoal" + } + fn can_use(&mut self, m: &mut Mob, cx: &mut Cx) -> bool { + !cx.w.daylight && m.fluids.in_water && m.position.y < f64::from(cx.w.sea_level - 2) + } + fn can_continue(&mut self, m: &mut Mob, cx: &mut Cx) -> bool { + self.can_use(m, cx) && !self.stuck + } + fn start(&mut self, m: &mut Mob, _cx: &mut Cx) { + m.extra.flag2 = true; + self.stuck = false; + } + fn stop(&mut self, m: &mut Mob, _cx: &mut Cx) { + m.extra.flag2 = false; + } + fn tick(&mut self, m: &mut Mob, cx: &mut Cx) { + let sea = f64::from(cx.w.sea_level); + if m.position.y < sea - 1.0 && (m.ai.nav.is_done() || drowned_close_to_next_pos(m)) { + let to = [m.position.x, sea - 1.0, m.position.z]; + match m.default_random_pos_towards(cx.w, 4, 8, to, std::f64::consts::FRAC_PI_2) { + None => self.stuck = true, + Some(p) => { + m.nav_move_to(cx.w, p, 1.0); + } + } + } + } +} +/// Drowned.closeToNextPos: within two blocks of the path's target. +fn drowned_close_to_next_pos(m: &Mob) -> bool { + m.ai.nav.path.as_ref().is_some_and(|p| { + let t = p.target; + m.distance_sqr(Vec3::new(f64::from(t[0]), f64::from(t[1]), f64::from(t[2]))) < 4.0 + }) } /// Zombie drowning conversion (Zombie.DrowningTracker) and husk -> zombie. /// `ZombifiedPiglin.customServerAiStep`: faster and loud while angry, @@ -237,25 +517,82 @@ pub fn custom_server_ai_step(m: &mut Mob, cx: &mut Cx) { m.extra.counter = -1; } } - if m.species() == Species::Drowned { - // Drowned.updateSwimming / travel: swim when the target is in water. - let wants = - m.ai.target - .and_then(|t| cx.w.target_info(t)) - .is_some_and(|t| { - let (x, y, z) = ( - t.position.x.floor() as i32, - t.position.y.floor() as i32, - t.position.z.floor() as i32, - ); - cx.w.fluid(x, y, z) == crate::blocks::Fluid::Water - }); - m.extra.flag = wants; - if m.fluids.in_water && wants { - m.ai.nav.kind = super::nav::NavKind::Water { breach: false }; - } else if m.ai.nav.kind != super::nav::NavKind::Ground { - m.ai.nav.kind = super::nav::NavKind::Ground; - m.ai.nav.stop(); +} +/// `AbstractSkeleton.reassessWeaponGoal`'s goal: the bow goal while holding a +/// bow, otherwise the melee goal (the anonymous `AbstractSkeleton$1`). +#[derive(Clone, Debug)] +pub struct SkeletonWeapon { + bow: BowAttack, + melee: MeleeAttack, + use_bow: bool, +} +impl SkeletonWeapon { + pub fn new(bow_interval: i32) -> Self { + Self { + bow: BowAttack::new(1.0, bow_interval, 15.0), + melee: MeleeAttack::new(1.2, false), + use_bow: false, + } + } +} +impl Goal for SkeletonWeapon { + goal_clone!(); + fn flags(&self) -> u8 { + MOVE | LOOK + } + fn name(&self) -> &'static str { + if self.use_bow { + "BowAttack" + } else { + "AbstractSkeleton$1" + } + } + fn every_tick(&self) -> bool { + if self.use_bow { + self.bow.every_tick() + } else { + self.melee.every_tick() + } + } + fn can_use(&mut self, m: &mut Mob, cx: &mut Cx) -> bool { + // The goal registered for the weapon in hand. + self.use_bow = holding_bow(m); + if self.use_bow { + self.bow.can_use(m, cx) + } else { + self.melee.can_use(m, cx) + } + } + fn can_continue(&mut self, m: &mut Mob, cx: &mut Cx) -> bool { + // Changing weapons removes the running goal. + if self.use_bow != holding_bow(m) { + return false; + } + if self.use_bow { + self.bow.can_continue(m, cx) + } else { + self.melee.can_continue(m, cx) + } + } + fn start(&mut self, m: &mut Mob, cx: &mut Cx) { + if self.use_bow { + self.bow.start(m, cx) + } else { + self.melee.start(m, cx) + } + } + fn stop(&mut self, m: &mut Mob, cx: &mut Cx) { + if self.use_bow { + self.bow.stop(m, cx) + } else { + self.melee.stop(m, cx) + } + } + fn tick(&mut self, m: &mut Mob, cx: &mut Cx) { + if self.use_bow { + self.bow.tick(m, cx) + } else { + self.melee.tick(m, cx) } } } diff --git a/crates/horizon-client/src/mobs/vex.rs b/crates/horizon-client/src/mobs/vex.rs index 74551edb6..de38f6da8 100644 --- a/crates/horizon-client/src/mobs/vex.rs +++ b/crates/horizon-client/src/mobs/vex.rs @@ -28,6 +28,7 @@ pub fn register(m: &mut Mob) { g.add(4, Charge); g.add(8, RandomMove); g.add(9, LookAtPlayer::new(3.0).probability(1.0)); + g.add(10, LookAtPlayer::mobs(8.0)); let mut hurt = HurtByTarget::new().alert(); hurt.ignore = vec![ Species::Pillager, diff --git a/debug/chunk-aiworld-2026-10-11_16.47.20-server.txt b/debug/chunk-aiworld-2026-10-11_16.47.20-server.txt new file mode 100644 index 000000000..ca30394cc --- /dev/null +++ b/debug/chunk-aiworld-2026-10-11_16.47.20-server.txt @@ -0,0 +1,96 @@ +---- Minecraft Chunk IO Error Report ---- +// Let's not do it again... + +Time: 2026-10-11 16:47:20 +Description: Chunk save failure + +java.io.IOException: No space left on device + at java.base/sun.nio.ch.UnixFileDispatcherImpl.pwrite0(Native Method) + at java.base/sun.nio.ch.UnixFileDispatcherImpl.pwrite(UnixFileDispatcherImpl.java:71) + at java.base/sun.nio.ch.IOUtil.writeFromNativeBuffer(IOUtil.java:135) + at java.base/sun.nio.ch.IOUtil.write(IOUtil.java:102) + at java.base/sun.nio.ch.IOUtil.write(IOUtil.java:72) + at java.base/sun.nio.ch.FileChannelImpl.writeInternal(FileChannelImpl.java:1261) + at java.base/sun.nio.ch.FileChannelImpl.implWrite(FileChannelImpl.java:1234) + at java.base/sun.nio.ch.FileChannelImpl.write(FileChannelImpl.java:1216) + at net.minecraft.world.level.chunk.storage.RegionFile.write(RegionFile.java:420) + at net.minecraft.world.level.chunk.storage.RegionFile$ChunkBuffer.close(RegionFile.java:393) + at java.base/java.util.zip.DeflaterOutputStream.close(DeflaterOutputStream.java:320) + at java.base/java.io.FilterOutputStream.close(FilterOutputStream.java:190) + at java.base/java.io.FilterOutputStream.close(FilterOutputStream.java:190) + at net.minecraft.world.level.chunk.storage.RegionFileStorage.write(RegionFileStorage.java:117) + at net.minecraft.world.level.chunk.storage.IOWorker.runStore(IOWorker.java:280) + at net.minecraft.world.level.chunk.storage.IOWorker.storePendingChunk(IOWorker.java:270) + at net.minecraft.util.thread.StrictQueue$RunnableWithPriority.run(StrictQueue.java:50) + at net.minecraft.util.Util.runNamed(Util.java:351) + at net.minecraft.util.thread.AbstractConsecutiveExecutor.pollTask(AbstractConsecutiveExecutor.java:50) + at net.minecraft.util.thread.AbstractConsecutiveExecutor.run(AbstractConsecutiveExecutor.java:60) + at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1090) + at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:614) + at java.base/java.lang.Thread.run(Thread.java:1474) + + +A detailed walkthrough of the error, its code path and all known details is as follows: +--------------------------------------------------------------------------------------- + +-- Head -- +Thread: IO-Worker-37 +Stacktrace: + at java.base/sun.nio.ch.UnixFileDispatcherImpl.pwrite0(Native Method) + at java.base/sun.nio.ch.UnixFileDispatcherImpl.pwrite(UnixFileDispatcherImpl.java:71) + at java.base/sun.nio.ch.IOUtil.writeFromNativeBuffer(IOUtil.java:135) + at java.base/sun.nio.ch.IOUtil.write(IOUtil.java:102) + at java.base/sun.nio.ch.IOUtil.write(IOUtil.java:72) + at java.base/sun.nio.ch.FileChannelImpl.writeInternal(FileChannelImpl.java:1261) + at java.base/sun.nio.ch.FileChannelImpl.implWrite(FileChannelImpl.java:1234) + at java.base/sun.nio.ch.FileChannelImpl.write(FileChannelImpl.java:1216) + at net.minecraft.world.level.chunk.storage.RegionFile.write(RegionFile.java:420) + at net.minecraft.world.level.chunk.storage.RegionFile$ChunkBuffer.close(RegionFile.java:393) + at java.base/java.util.zip.DeflaterOutputStream.close(DeflaterOutputStream.java:320) + at java.base/java.io.FilterOutputStream.close(FilterOutputStream.java:190) + at java.base/java.io.FilterOutputStream.close(FilterOutputStream.java:190) + at net.minecraft.world.level.chunk.storage.RegionFileStorage.write(RegionFileStorage.java:117) + at net.minecraft.world.level.chunk.storage.IOWorker.runStore(IOWorker.java:280) + at net.minecraft.world.level.chunk.storage.IOWorker.storePendingChunk(IOWorker.java:270) + at net.minecraft.util.thread.StrictQueue$RunnableWithPriority.run(StrictQueue.java:50) + at net.minecraft.util.Util.runNamed(Util.java:351) + at net.minecraft.util.thread.AbstractConsecutiveExecutor.pollTask(AbstractConsecutiveExecutor.java:50) + +-- Chunk Info -- +Details: + Level: aiworld + Dimension: minecraft:overworld + Storage: chunk + Position: [680, 15] +Stacktrace: + at net.minecraft.server.MinecraftServer.lambda$storeChunkIoError$0(MinecraftServer.java:2225) + at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1090) + at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:614) + at java.base/java.lang.Thread.run(Thread.java:1474) + +-- System Details -- +Details: + Minecraft Version: 26.3 + Minecraft Version ID: 26.3 + Operating System: Linux (amd64) version 6.18.55 + Java Version: 25.0.4.1, N/A + Java VM Version: OpenJDK 64-Bit Server VM (mixed mode, sharing), Oracle Corporation + Memory: 239988568 bytes (228 MiB) / 1694498816 bytes (1616 MiB) up to 3221225472 bytes (3072 MiB) + Memory (heap): init: 436MiB, used: 1383MiB, committed: 1616MiB, max: 3072MiB + Memory (non-heap): init: 007MiB, used: 123MiB, committed: 135MiB, max: 000MiB + CPUs: 24 + processor: ~~ERROR~~ NoClassDefFoundError: Could not initialize class oshi.software.os.linux.LinuxOperatingSystem + Graphics card #0 name: AD103 [GeForce RTX 4080] + Graphics card #0 vendor: NVIDIA Corporation (0x10de) + Graphics card #0 VRAM (MiB): 16416.00 + Graphics card #0 deviceId: 0x2704 + Graphics card #0 versionInfo: unknown + memory: ~~ERROR~~ NoClassDefFoundError: Could not initialize class oshi.hardware.platform.linux.LinuxGlobalMemory + Space in storage for jna.tmpdir (MiB): + Space in storage for org.lwjgl.system.SharedLibraryExtractPath (MiB): + Space in storage for io.netty.native.workdir (MiB): + Space in storage for java.io.tmpdir (MiB): available: 8.54, total: 936786.75 + Space in storage for workdir (MiB): available: 8.54, total: 936786.75 + software: ~~ERROR~~ NoClassDefFoundError: Could not initialize class oshi.software.os.linux.LinuxOperatingSystem + JVM Flags: 1 total; -Xmx3g + Debug Flags: 0 total; \ No newline at end of file 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 30a94811b..a854c291a 100644 --- a/mods/horizon/src/test/java/dev/horizonlab/parity/VanillaMobAiOracle.java +++ b/mods/horizon/src/test/java/dev/horizonlab/parity/VanillaMobAiOracle.java @@ -105,6 +105,8 @@ import net.minecraft.world.phys.Vec3; public final class VanillaMobAiOracle { static final List SCENARIOS = new ArrayList<>(); static PrintWriter out; + /** The temporary world directory, deleted before the oracle halts. */ + static Path UNIVERSE; static final List SOUNDS = new ArrayList<>(); /** Draws of a traced mob random: the caller frames of each draw (AI_TRACE=scenario:from-to). */ @@ -208,7 +210,10 @@ public final class VanillaMobAiOracle { SharedConstants.tryDetectVersion(); Bootstrap.bootStrap(); Util.startTimerHackThread(); - Path universe = Files.createTempDirectory("horizon-mob-ai"); + // The harness passes an empty world directory under its build directory. + Path universe = args.length > 2 ? Path.of(args[2]) : Files.createTempDirectory("horizon-mob-ai"); + Files.createDirectories(universe); + UNIVERSE = universe; LevelStorageSource.LevelStorageAccess access = LevelStorageSource.createDefault(universe).createAccess("aiworld"); PackRepository packs = ServerPacksSource.createPackRepository(access); MinecraftServer.spin(thread -> Server.create(thread, access, packs)); @@ -344,7 +349,12 @@ public final class VanillaMobAiOracle { void step(BooleanSupplier haveTime) throws Exception { if (scenario >= SCENARIOS.size()) { out.close(); - // Nothing to save: skip the shutdown. + // Nothing to save: skip the shutdown, but leave no world behind. + try (var paths = Files.walk(UNIVERSE)) { + paths.sorted(java.util.Comparator.reverseOrder()).forEach(p -> p.toFile().delete()); + } catch (Exception e) { + // best effort + } Runtime.getRuntime().halt(0); return; } @@ -427,6 +437,9 @@ 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); + // 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); player.setDeltaMovement(Vec3.ZERO); } else if (player != null) { player.snapTo(s.originX + 5000, -60, s.originZ, 0.0F, 0.0F); diff --git a/tools/test_mob_ai_parity.py b/tools/test_mob_ai_parity.py index 4214da235..eb1e0a470 100644 --- a/tools/test_mob_ai_parity.py +++ b/tools/test_mob_ai_parity.py @@ -13,6 +13,7 @@ reports, per scenario and mob, how many ticks match before the first divergence """ import argparse import os +import shutil import struct import subprocess import sys @@ -236,8 +237,11 @@ def main(): if not args.rust_only: classes, dependencies, _ = oracle_harness.compile_oracle(build, 'VanillaMobAiOracle', jars, baking.client_libraries(), lock['minecraft']['java_major']) + # The oracle's server world: cleared before each run, never left in /tmp. + world = build / 'world' + shutil.rmtree(world, ignore_errors=True) oracle_harness.run_logged(['java', '-Xmx3g', '-Djava.awt.headless=true', '-cp', str(classes) + os.pathsep + dependencies, - 'dev.horizonlab.parity.VanillaMobAiOracle', inputs, build / 'vanilla.txt'], + 'dev.horizonlab.parity.VanillaMobAiOracle', inputs, build / 'vanilla.txt', world], build, 'vanilla', timeout=3600) if not args.java_only: command = ['cargo', 'build', '--locked', '--release', '-p', 'horizon-client', '--example', 'mob_ai_probe']