From 2c8930c48da0ba6c17db31dcaf09dea9a1465b4f Mon Sep 17 00:00:00 2001 From: vlesmentie <129341611+vlesmentie@users.noreply.github.com> Date: Sun, 25 Oct 2026 15:16:32 -0300 Subject: [PATCH 1/2] Chickens flap while they fall on a client of a server Chicken.aiStep updates flap and flapSpeed on the client too, for the chickens it only displays. tick_remote_entities never did, so with single player on its server thread (and on servers) a falling chicken kept its wings folded. The wing part of chicken_ai_step is now chicken_flap, and the remote tick runs it from the server's on-ground flag; the falling slowdown and egg laying stay the server's. Fixes #1706. Co-Authored-By: Claude Opus 5.5 --- crates/horizon-client/src/game/remote.rs | 4 + crates/horizon-client/src/mobs/farm.rs | 111 +++++++++++++++++++++-- 2 files changed, 106 insertions(+), 9 deletions(-) diff --git a/crates/horizon-client/src/game/remote.rs b/crates/horizon-client/src/game/remote.rs index 620d145bf..b3a2b73ce 100644 --- a/crates/horizon-client/src/game/remote.rs +++ b/crates/horizon-client/src/game/remote.rs @@ -3572,6 +3572,10 @@ impl Game<'_> { m.head_yaw += wrap_degrees(*yaw - m.head_yaw) / *steps as f32; *steps -= 1; } + // Chicken.aiStep: the wings follow the server's on-ground flag. + if m.species() == horizon_client::mobs::Species::Chicken { + horizon_client::mobs::farm::chicken_flap(m); + } // LivingEntity.updatingUsingItem for another player: the ticks the // item has been used before this one. if player && m.extra.using_item > 0 { diff --git a/crates/horizon-client/src/mobs/farm.rs b/crates/horizon-client/src/mobs/farm.rs index bf886cb5a..aa02c901d 100644 --- a/crates/horizon-client/src/mobs/farm.rs +++ b/crates/horizon-client/src/mobs/farm.rs @@ -69,18 +69,10 @@ pub fn register(m: &mut Mob) { } /// Chicken.aiStep: wing flapping, slowed falling and laying eggs. pub fn chicken_ai_step(m: &mut Mob, _w: &MobWorld, events: &mut Vec) { - let a = &mut m.anim; - a.flap_o = a.flap; - a.flap_speed_o = a.flap_speed; - a.flap_speed = (a.flap_speed + if m.on_ground { -1.0 } else { 4.0 } * 0.3).clamp(0.0, 1.0); - if !m.on_ground && a.flapping < 1.0 { - a.flapping = 1.0; - } - a.flapping *= 0.9; + chicken_flap(m); if !m.on_ground && m.velocity.y < 0.0 { m.velocity.y *= 0.6; } - a.flap += a.flapping * 2.0; if m.alive() && !m.is_baby() && !m.extra.jockey { m.extra.egg_time -= 1; if m.extra.egg_time <= 0 { @@ -95,6 +87,21 @@ pub fn chicken_ai_step(m: &mut Mob, _w: &MobWorld, events: &mut Vec) { } } } +/// Chicken.aiStep's wings: `flapSpeed` rises in the air and falls on the +/// ground, `flapping` restarts at 1 in the air and decays, and `flap` turns +/// by it. It runs on a client too, for the chickens it only displays (the +/// falling slowdown and the eggs are the server's). +pub fn chicken_flap(m: &mut Mob) { + let a = &mut m.anim; + a.flap_o = a.flap; + a.flap_speed_o = a.flap_speed; + a.flap_speed = (a.flap_speed + if m.on_ground { -1.0 } else { 4.0 } * 0.3).clamp(0.0, 1.0); + if !m.on_ground && a.flapping < 1.0 { + a.flapping = 1.0; + } + a.flapping *= 0.9; + a.flap += a.flapping * 2.0; +} /// Farm animal climate from the biome tags (`spawns_warm/cold_variant_farm_animals`). #[derive(Clone, Copy, Debug, PartialEq, Eq, Default)] pub enum Climate { @@ -125,3 +132,89 @@ pub fn sheep_color(climate: Climate, random: &mut impl RandomSource) -> u8 { 6 } } + +#[cfg(test)] +mod tests { + use super::*; + use crate::mobs::{Anim, Brain, Flags, MobType, Part, Species}; + use horizon_core::geometry::Vec3; + use serde_json::json; + use std::collections::HashMap; + + fn chicken() -> Mob { + let model = Arc::new(Part::parse( + "root", + &json!({"children": {"right_wing": {}, "left_wing": {}}}), + )); + let kind = Arc::new(MobType { + id: "minecraft:chicken".into(), + species: Species::Chicken, + width: 0.4, + height: 0.7, + eye_height: 0.644, + category: "creature".into(), + max_health: 4.0, + speed: 0.25, + flying_speed: 0.4, + attack_damage: 0.0, + attack_knockback: 0.0, + follow_range: 16.0, + step_height: 0.6, + armor: 0.0, + armor_toughness: 0.0, + knockback_resistance: 0.0, + jump_strength: 0.42, + attributes: Arc::default(), + gravity: 0.08, + safe_fall_distance: 3.0, + fall_damage_multiplier: 1.0, + water_efficiency: 0.0, + water_slowdown: 0.8, + air_speed: 0.02, + baby_scale: 0.5, + head_rot_speed: 10.0, + max_head_x_rot: 40.0, + max_head_y_rot: 75.0, + ambient_interval: 120, + flags: Flags { + animal: true, + ..Default::default() + }, + model, + layers: HashMap::new(), + texture: String::new(), + brain: Brain::Passive, + anim: Anim::Chicken, + sounds: [""; 3], + step_sound: None, + food: Arc::default(), + tempt: Arc::default(), + }); + Mob::new(1, kind, Vec3::ZERO, 0.0) + } + + #[test] + fn a_falling_chicken_flaps_and_a_landed_one_folds_its_wings() { + let mut m = chicken(); + m.on_ground = true; + chicken_flap(&mut m); + assert_eq!(m.anim.flap_speed, 0.0); + assert_eq!(m.anim.flap, 0.0); + // In the air flapSpeed rises by 1.2 (clamped to 1), flapping restarts + // at 1 and decays by 0.9, and flap turns by twice flapping. + m.on_ground = false; + chicken_flap(&mut m); + assert_eq!(m.anim.flap_speed, 1.0); + assert_eq!(m.anim.flapping, 0.9); + assert_eq!(m.anim.flap, 1.8); + chicken_flap(&mut m); + assert_eq!(m.anim.flap_o, 1.8); + assert_eq!(m.anim.flap_speed_o, 1.0); + assert_eq!(m.anim.flap, 3.6); + // Landed, flapSpeed falls by 0.3 a tick and flapping decays. + m.on_ground = true; + chicken_flap(&mut m); + assert!((m.anim.flap_speed - 0.7).abs() < 1.0e-6); + assert!((m.anim.flapping - 0.81).abs() < 1.0e-6); + } +} From 9d5301627bbb81bf46113a9c41dff841d2d4f2e1 Mon Sep 17 00:00:00 2001 From: Ludovic Marie <136255825+ludovic111@users.noreply.github.com> Date: Sun, 25 Oct 2026 23:55:43 +0100 Subject: [PATCH 2/2] Chickens: the flap test uses the shared test mob type chicken_flap reads only the ground flag, so the test builds its mob from mobs::sensor_scan_tests::kind() instead of a 50-line copy of a MobType. Co-Authored-By: Claude Opus 5.5 --- crates/horizon-client/src/mobs/farm.rs | 54 +------------------------- 1 file changed, 2 insertions(+), 52 deletions(-) diff --git a/crates/horizon-client/src/mobs/farm.rs b/crates/horizon-client/src/mobs/farm.rs index aa02c901d..83d5ac1f5 100644 --- a/crates/horizon-client/src/mobs/farm.rs +++ b/crates/horizon-client/src/mobs/farm.rs @@ -136,61 +136,11 @@ pub fn sheep_color(climate: Climate, random: &mut impl RandomSource) -> u8 { #[cfg(test)] mod tests { use super::*; - use crate::mobs::{Anim, Brain, Flags, MobType, Part, Species}; use horizon_core::geometry::Vec3; - use serde_json::json; - use std::collections::HashMap; + /// `chicken_flap` reads only the ground flag: any mob type will do. fn chicken() -> Mob { - let model = Arc::new(Part::parse( - "root", - &json!({"children": {"right_wing": {}, "left_wing": {}}}), - )); - let kind = Arc::new(MobType { - id: "minecraft:chicken".into(), - species: Species::Chicken, - width: 0.4, - height: 0.7, - eye_height: 0.644, - category: "creature".into(), - max_health: 4.0, - speed: 0.25, - flying_speed: 0.4, - attack_damage: 0.0, - attack_knockback: 0.0, - follow_range: 16.0, - step_height: 0.6, - armor: 0.0, - armor_toughness: 0.0, - knockback_resistance: 0.0, - jump_strength: 0.42, - attributes: Arc::default(), - gravity: 0.08, - safe_fall_distance: 3.0, - fall_damage_multiplier: 1.0, - water_efficiency: 0.0, - water_slowdown: 0.8, - air_speed: 0.02, - baby_scale: 0.5, - head_rot_speed: 10.0, - max_head_x_rot: 40.0, - max_head_y_rot: 75.0, - ambient_interval: 120, - flags: Flags { - animal: true, - ..Default::default() - }, - model, - layers: HashMap::new(), - texture: String::new(), - brain: Brain::Passive, - anim: Anim::Chicken, - sounds: [""; 3], - step_sound: None, - food: Arc::default(), - tempt: Arc::default(), - }); - Mob::new(1, kind, Vec3::ZERO, 0.0) + Mob::new(1, crate::mobs::sensor_scan_tests::kind(), Vec3::ZERO, 0.0) } #[test]