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 <noreply@anthropic.com>
This commit is contained in:
Ludovic Marie
2026-10-12 16:29:00 +02:00
parent 0e076c7153
commit 4e871bf22e
5 changed files with 58 additions and 52 deletions
+32 -26
View File
@@ -464,35 +464,41 @@ fn main() -> horizon_client::Result<()> {
}
for t in 1..=s.ticks {
world.game_time += 1;
let snapshot: Vec<Seen> = 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<Seen> = 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() {
+16 -8
View File
@@ -438,26 +438,34 @@ impl Game<'_> {
}
self.tick_raids();
let uuid = self.level.player_uuid;
let snapshot: Vec<Seen> = self.mobs.iter().map(|m| seen(m, uuid)).collect();
let mut snapshot: Vec<Seen> = 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);
+4
View File
@@ -490,6 +490,10 @@ fn play_ambient(m: &mut Mob, w: &MobWorld, events: &mut Vec<MobEvent>) {
}
/// LivingEntity.aiStep (and Mob/AgeableMob/Animal additions).
fn ai_step(m: &mut Mob, w: &MobWorld, events: &mut Vec<MobEvent>) {
// 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);
}
+2 -1
View File
@@ -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),
+4 -17
View File
@@ -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::*;