From 4cc134d08a52c94b88bcf4dbbdfee70b14ddde2f Mon Sep 17 00:00:00 2001 From: rdbtCVS <87152661+rdbtCVS@users.noreply.github.com> Date: Mon, 26 Oct 2026 02:13:12 +0000 Subject: [PATCH] Fix passenger walk animation in shared render state Zero passenger walk position and speed like vanilla LivingEntityRenderer, covering local and remote riders. Extend entity model parity with moving passenger and on-foot render-state cases. Fixes #1962 Co-Authored-By: Codex GPT-6.1 Sol --- .../examples/probe/entity_anim_fixture.rs | 22 +++++++++++++++++-- crates/horizon-client/src/mobs/anim.rs | 7 +++--- .../parity/VanillaEntityAnimOracle.java | 13 +++++++++++ tools/test_entity_model_parity.py | 13 +++++++++++ 4 files changed, 50 insertions(+), 5 deletions(-) diff --git a/crates/horizon-client/examples/probe/entity_anim_fixture.rs b/crates/horizon-client/examples/probe/entity_anim_fixture.rs index 0a2e2951f..124ddbe03 100644 --- a/crates/horizon-client/examples/probe/entity_anim_fixture.rs +++ b/crates/horizon-client/examples/probe/entity_anim_fixture.rs @@ -377,7 +377,7 @@ pub fn main() -> horizon_client::Result<()> { mob.extra.age = -24000; } mob.age = f("ageInTicks") as u32; - let state = State { + let mut state = State { pos: f("walkAnimationPos"), speed: f("walkAnimationSpeed"), age: f("ageInTicks"), @@ -389,6 +389,20 @@ pub fn main() -> horizon_client::Result<()> { }; let mut poses = Poses::new(&model); entity_state(&mut mob, def.species, case); + if let Some(ticks) = case["@walkTicks"].as_array() { + for speed in ticks { + mob.previous_limb_speed = mob.limb_speed; + mob.limb_speed += (speed.as_f64().unwrap() as f32 - mob.limb_speed) * 0.4; + mob.limb_position += mob.limb_speed; + } + if !case["@alive"].as_bool().unwrap() { + mob.health = 0.0; + } + let extracted = anim::state(&mob, f("@partial")); + state.pos = extracted.pos; + state.speed = extracted.speed; + } + let flag = |k: &str| case[k].as_bool().unwrap_or(false); let num = |k: &str| case[k].as_f64().unwrap_or(0.0) as f32; let started = |k: &str| AnimationState { @@ -590,7 +604,11 @@ pub fn main() -> horizon_client::Result<()> { } _ => anim::setup(&mob, s, p, &animations), } - out.push_str(&format!("{}\n", emit(&model, &mut poses, case, layer))); + let mut result = emit(&model, &mut poses, case, layer); + if case["@walkTicks"].is_array() { + result["walk"] = json!([state.pos, state.speed]); + } + out.push_str(&format!("{result}\n")); } fs::write(&args[2], out)?; Ok(()) diff --git a/crates/horizon-client/src/mobs/anim.rs b/crates/horizon-client/src/mobs/anim.rs index b2158132b..8639c8a9b 100644 --- a/crates/horizon-client/src/mobs/anim.rs +++ b/crates/horizon-client/src/mobs/anim.rs @@ -189,14 +189,15 @@ pub fn state(m: &Mob, alpha: f32) -> State { swing += 1.0; } let swing = m.anim.attack_anim_o + swing * alpha; - let alive = m.alive(); + // LivingEntityRenderer.extractRenderState: riding motion is not walking. + let walking = m.alive() && !m.extra.passenger; State { - pos: if alive { + pos: if walking { m.limb_position - m.limb_speed * (1.0 - alpha) } else { 0.0 }, - speed: if alive { + speed: if walking { (m.previous_limb_speed + (m.limb_speed - m.previous_limb_speed) * alpha).min(1.0) } else { 0.0 diff --git a/mods/horizon/src/test/java/dev/horizonlab/parity/VanillaEntityAnimOracle.java b/mods/horizon/src/test/java/dev/horizonlab/parity/VanillaEntityAnimOracle.java index dc5f8c8df..80bd0bf14 100644 --- a/mods/horizon/src/test/java/dev/horizonlab/parity/VanillaEntityAnimOracle.java +++ b/mods/horizon/src/test/java/dev/horizonlab/parity/VanillaEntityAnimOracle.java @@ -282,6 +282,19 @@ public final class VanillaEntityAnimOracle { state.getClass(); for (var entry : kase.entrySet()) if (!entry.getKey().startsWith("@")) set(state, entry.getKey(), entry.getValue()); + if (kase.has("@walkTicks")) { + var walk = new net.minecraft.world.entity.WalkAnimationState(); + for (var speed : kase.getAsJsonArray("@walkTicks")) + walk.update(speed.getAsFloat(), 0.4F, 1.0F); + // LivingEntity.calculateEntityAnimation stops passengers/dead entities; + // LivingEntityRenderer.extractRenderState also zeros both fields. + if (kase.get("isPassenger").getAsBoolean() || !kase.get("@alive").getAsBoolean()) + walk.stop(); + float partial = kase.get("@partial").getAsFloat(); + set(state, "walkAnimationPos", gson.toJsonTree(walk.position(partial))); + set(state, "walkAnimationSpeed", gson.toJsonTree(walk.speed(partial))); + result.add("walk", gson.toJsonTree(new float[]{walk.position(partial), walk.speed(partial)})); + } hooks(state, kase); if (state instanceof net.minecraft.client.renderer.entity.state.ArmedEntityRenderState armed && armed.swingAnimation > 0) armed.currentSwing = new net.minecraft.world.entity.LivingEntity.SwingDescription(net.minecraft.world.InteractionHand.MAIN_HAND, net.minecraft.world.item.component.SwingAnimation.DEFAULT, 6); diff --git a/tools/test_entity_model_parity.py b/tools/test_entity_model_parity.py index 0cfc509f3..ca0585bcf 100644 --- a/tools/test_entity_model_parity.py +++ b/tools/test_entity_model_parity.py @@ -164,6 +164,15 @@ def cases(layer, model=None): cases_out = [{**c, **DEFAULTS.get(name, {})} for c in cases_out] yield from cases_out yield from species_cases(layer, cases_out) + # Exercise render-state extraction with a live walk clock, including the + # first mounted frame. Existing setupAnim cases bypass anim::state. + if name == 'skeleton': + for passenger in [False, True]: + for alive in [False, True]: + for partial in [0.0, 0.5, 1.0]: + yield {**cases_out[2], 'isPassenger': passenger, + '@walkTicks': [0.5, 1.0, 0.75], + '@alive': alive, '@partial': partial} part = model and scaled_part(model) if part: for index, scale in enumerate(PART_SCALES): @@ -379,6 +388,10 @@ def main(): skipped.add(layer); continue checked += 1 bad = [] + if 'walk' in v: + for a, b in zip(v['walk'], r['walk']): + if abs(a - b) > args.tolerance * (1.0 + abs(a)): + bad.append(('@walk', f'{v["walk"]} != {r["walk"]}')) for path, expected in v['parts'].items(): got = r['parts'].get(path) if got is None: