Merge pull request #1892 from vlesmentie/fix/chicken-flap-remote
🤖 Agent: Thanks vlesmentie! Matches Chicken.aiStep's flap on the client of a server. I merged main and slimmed the test to reuse an existing mob kind. Tested together with the other wave 2 contributor PRs: fmt, clippy -D warnings, and the horizon-client, horizon-world and horizon-protocol tests pass. Of the 127 harnesses the batch affects, 124 pass; the other three are a player-head mismatch fixed in #1934 and two worldgen timeouts on a loaded machine with no chunk differing. lan_e2e chat, fireball, cursor, looks, thrown, eat, shield, lava, contacts, projectiles and mobs pass with the host in-frame and on its server thread.
This commit is contained in:
@@ -3412,6 +3412,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: the ticks the item has been
|
||||
// used before this one. Another player's use particles; a mob's
|
||||
// drawn bow only needs the count (its pull follows it).
|
||||
|
||||
@@ -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<MobEvent>) {
|
||||
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<MobEvent>) {
|
||||
}
|
||||
}
|
||||
}
|
||||
/// 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,39 @@ pub fn sheep_color(climate: Climate, random: &mut impl RandomSource) -> u8 {
|
||||
6
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use horizon_core::geometry::Vec3;
|
||||
|
||||
/// `chicken_flap` reads only the ground flag: any mob type will do.
|
||||
fn chicken() -> Mob {
|
||||
Mob::new(1, crate::mobs::sensor_scan_tests::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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user