From 4e871bf22ee70b5c119a289650db2f162f63e886 Mon Sep 17 00:00:00 2001 From: Ludovic Marie <136255825+ludovic111@users.noreply.github.com> Date: Mon, 12 Oct 2026 16:29:00 +0200 Subject: [PATCH] Match vanilla llamas: the horse tail draw and mobs seeing earlier mobs' moves AbstractHorse.aiStep draws a tail swish every tick before the goals run. Mobs now see the mobs ticked before them as they are after their tick (ServerLevel ticks entities one after another), in the game and in the mob AI probe; a baby llama following its parent depended on it. The llama's strength is read raw, as getStrength does. Co-Authored-By: Claude Opus 5.5 --- .../horizon-client/examples/mob_ai_probe.rs | 58 ++++++++++--------- crates/horizon-client/src/game/creatures.rs | 24 +++++--- crates/horizon-client/src/mobs/ai.rs | 4 ++ crates/horizon-client/src/mobs/anim.rs | 3 +- crates/horizon-client/src/mobs/llama.rs | 21 ++----- 5 files changed, 58 insertions(+), 52 deletions(-) diff --git a/crates/horizon-client/examples/mob_ai_probe.rs b/crates/horizon-client/examples/mob_ai_probe.rs index ab6cce246..261eef40f 100644 --- a/crates/horizon-client/examples/mob_ai_probe.rs +++ b/crates/horizon-client/examples/mob_ai_probe.rs @@ -464,35 +464,41 @@ fn main() -> horizon_client::Result<()> { } for t in 1..=s.ticks { world.game_time += 1; - let snapshot: Vec = mobs.iter().filter(|m| !m.removed).map(seen).collect(); - let w = MobWorld { - world: &world, - registry, - facts: &facts, - collision: &collision, - data: &data, - player: player.clone(), - others: &snapshot, - daylight: (s.time.rem_euclid(24000)) < 12000, - game_time: world.game_time, - day_time: world.day_time, - raining: s.rain, - thundering: s.thunder, - nether: false, - block_tags: &items.block_tags, - biomes: &biomes, - mob_griefing: true, - difficulty: LocalDifficulty::new(2, world.day_time, 0, 0.0), - end: false, - world_seed: 0, - }; + let mut snapshot: Vec = mobs.iter().filter(|m| !m.removed).map(seen).collect(); let mut events = Vec::new(); - for m in &mut mobs { - if m.removed { + for i in 0..mobs.len() { + if mobs[i].removed { continue; } - if !m.tick(&w, &mut scratch, &mut events) { - m.removed = true; + let w = MobWorld { + world: &world, + registry, + facts: &facts, + collision: &collision, + data: &data, + player: player.clone(), + others: &snapshot, + daylight: (s.time.rem_euclid(24000)) < 12000, + game_time: world.game_time, + day_time: world.day_time, + raining: s.rain, + thundering: s.thunder, + nether: false, + block_tags: &items.block_tags, + biomes: &biomes, + mob_griefing: true, + difficulty: LocalDifficulty::new(2, world.day_time, 0, 0.0), + end: false, + world_seed: 0, + }; + if !mobs[i].tick(&w, &mut scratch, &mut events) { + mobs[i].removed = true; + } + // ServerLevel ticks entities one after another: the ones + // after this mob see it as it is now. + if let Some(e) = snapshot.iter_mut().find(|e| e.id == mobs[i].id) { + *e = seen(&mobs[i]); + e.alive &= !mobs[i].removed; } } for (i, m) in mobs.iter().enumerate() { diff --git a/crates/horizon-client/src/game/creatures.rs b/crates/horizon-client/src/game/creatures.rs index 1e0751d5b..cfa159dd4 100644 --- a/crates/horizon-client/src/game/creatures.rs +++ b/crates/horizon-client/src/game/creatures.rs @@ -438,26 +438,34 @@ impl Game<'_> { } self.tick_raids(); let uuid = self.level.player_uuid; - let snapshot: Vec = self.mobs.iter().map(|m| seen(m, uuid)).collect(); + let mut snapshot: Vec = self.mobs.iter().map(|m| seen(m, uuid)).collect(); let mut events = Vec::new(); let mut mobs = std::mem::take(&mut self.mobs); let mut dead = Vec::new(); { - let w = self.mob_world_base(&snapshot); let mut scratch = self.world.random.clone(); - mobs.retain_mut(|m| { + let mut keep = Vec::with_capacity(mobs.len()); + for (i, m) in mobs.iter_mut().enumerate() { + let w = self.mob_world_base(&snapshot); if !w .world .loaded(m.position.x.floor() as i32, m.position.z.floor() as i32) { - return !m.hostile() || m.persistent; + keep.push(!m.hostile() || m.persistent); + continue; } - let keep = m.tick(&w, &mut scratch, &mut events); - if !keep && !m.alive() && !m.removed { + let kept = m.tick(&w, &mut scratch, &mut events); + if !kept && !m.alive() && !m.removed { dead.push(m.clone()); } - keep - }); + keep.push(kept); + // ServerLevel ticks entities one after another: the ones + // after this mob see it as it is now. + snapshot[i] = seen(m, uuid); + snapshot[i].alive &= kept; + } + let mut flags = keep.into_iter(); + mobs.retain(|_| flags.next().unwrap_or(true)); push_apart(&mut mobs); } self.mobs.append(&mut mobs); diff --git a/crates/horizon-client/src/mobs/ai.rs b/crates/horizon-client/src/mobs/ai.rs index 4d5c1307e..2d0a32a80 100644 --- a/crates/horizon-client/src/mobs/ai.rs +++ b/crates/horizon-client/src/mobs/ai.rs @@ -490,6 +490,10 @@ fn play_ambient(m: &mut Mob, w: &MobWorld, events: &mut Vec) { } /// LivingEntity.aiStep (and Mob/AgeableMob/Animal additions). fn ai_step(m: &mut Mob, w: &MobWorld, events: &mut Vec) { + // AbstractHorse.aiStep: the tail swishes now and then (moveTail). + if super::equine::is_equine(m.species()) { + let _ = m.random.next_int_bound(200); + } if super::creaking::is_creaking(m) { super::creaking::update(m, w, events); } diff --git a/crates/horizon-client/src/mobs/anim.rs b/crates/horizon-client/src/mobs/anim.rs index 27f441adc..b8434d75e 100644 --- a/crates/horizon-client/src/mobs/anim.rs +++ b/crates/horizon-client/src/mobs/anim.rs @@ -464,7 +464,8 @@ pub fn setup( Anim::Sniffer => super::sniffer::anim(m, s, p, w_anims), Anim::HappyGhast => super::happy_ghast::anim(m, s, p), Anim::Nautilus => super::nautilus::anim(m, s, p, w_anims), - Anim::Llama => super::llama::anim(m, s, p), + // body_anim::llama runs first. + Anim::Llama => quadruped(p, s), Anim::Warden => super::warden::anim(m, s, p, w_anims), Anim::Allay => super::allay::anim(m, s, p), Anim::Creaking => super::creaking::anim(m, s, p, w_anims), diff --git a/crates/horizon-client/src/mobs/llama.rs b/crates/horizon-client/src/mobs/llama.rs index fbae29b02..3fc2dc935 100644 --- a/crates/horizon-client/src/mobs/llama.rs +++ b/crates/horizon-client/src/mobs/llama.rs @@ -3,9 +3,7 @@ //! spit ranged attack, hunting wolves (and, for traders, zombies and //! illagers) and `LlamaModel`. use super::{ - Mob, MobEvent, MobWorld, Seen, Species, Who, - anim::{Poses, State}, - equine, + Mob, MobEvent, MobWorld, Seen, Species, Who, equine, goals::{ Breed, Cx, Float, FollowParent, Goal, HurtByTarget, LookAtPlayer, NearestTarget, Panic, Prey, RandomLookAround, Stroll, Tempt, goal_clone, @@ -14,7 +12,6 @@ use super::{ }; use crate::projectiles::{Projectile, ProjectileKind}; use horizon_core::{geometry::Vec3, random::RandomSource}; -use std::f32::consts::PI; pub const VARIANTS: [&str; 4] = ["creamy", "white", "brown", "gray"]; /// `Llama.getMaxTemper`. @@ -29,9 +26,10 @@ pub fn is_llama(s: Species) -> bool { pub fn is_trader(m: &Mob) -> bool { m.species() == Species::TraderLlama } -/// `Llama.getStrength`. +/// `Llama.getStrength`: the stored strength (0 for a llama that was never +/// given one; `setStrength` keeps it within 1 to 5). pub fn strength(m: &Mob) -> i32 { - i32::from(m.extra.variant2).clamp(1, 5) + i32::from(m.extra.variant2) } /// `getInventoryColumns`: a chest holds three rows of `strength` columns. pub fn inventory_columns(m: &Mob) -> i32 { @@ -250,17 +248,6 @@ pub fn decor(m: &Mob) -> Option<(String, String)> { (model.into(), format!("entity/equipment/llama_body/{name}")) }) } -/// `LlamaModel.setupAnim`. -pub fn anim(m: &Mob, s: &State, p: &mut Poses) { - super::anim::quadruped(p, s); - let chest = m.extra.chested && !s.baby; - for part in ["right_chest", "left_chest"] { - if !chest { - p.visible(part, false); - } - } - let _ = PI; -} #[cfg(test)] mod tests { use super::*;