Merge pull request #2003 from rdbtCVS/fix/bat-wing-animation-2000
🤖 Agent: contrib-gate-17 verified this head (26.3 sources, integration tree build, clippy, tests, parity; details in the PR comment). Thanks @rdbtCVS!
This commit is contained in:
@@ -9,7 +9,7 @@ use horizon_client::mesher::Vertex;
|
||||
use horizon_client::mobs::{
|
||||
Mob, MobData, MobTypes, Part, Species, allay,
|
||||
anim::{self, Poses, State},
|
||||
aquatic, body_anim as b_anim, equine, guardian,
|
||||
aquatic, bat, body_anim as b_anim, equine, guardian,
|
||||
keyframes::AnimationState,
|
||||
render, shulker, sniffer, species, tame,
|
||||
};
|
||||
@@ -108,6 +108,22 @@ fn entity_state(mob: &mut Mob, species: Species, case: &Value) {
|
||||
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;
|
||||
match species {
|
||||
Species::Bat => {
|
||||
mob.extra.flag = flag("isResting");
|
||||
mob.anim.states[0].started = case["flyAnimationState"].as_f64().map(|v| v as f32);
|
||||
mob.anim.states[1].started = case["restAnimationState"].as_f64().map(|v| v as f32);
|
||||
if let Some(ticks) = case["@batTicks"].as_array() {
|
||||
for (i, flags) in ticks.iter().enumerate() {
|
||||
mob.age = i as u32 + 1;
|
||||
bat::set_resting(mob, flags.as_i64().unwrap_or(0) & 1 != 0);
|
||||
if flag("@batInFrame") {
|
||||
bat::tick(mob);
|
||||
} else {
|
||||
bat::setup_animation_states(mob);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Species::Sheep => mob.extra.anim_ticks = num("eatTick") as i32,
|
||||
Species::Guardian | Species::ElderGuardian => {
|
||||
mob.anim.v[guardian::TAIL] = num("tailAnimation");
|
||||
@@ -456,14 +472,6 @@ pub fn main() -> horizon_client::Result<()> {
|
||||
roll_amount: num("rollAmount"),
|
||||
},
|
||||
),
|
||||
Species::Bat => b_anim::bat(
|
||||
p,
|
||||
s,
|
||||
flag("isResting"),
|
||||
&started("flyAnimationState"),
|
||||
&started("restAnimationState"),
|
||||
&animations,
|
||||
),
|
||||
Species::Armadillo => b_anim::armadillo(
|
||||
p,
|
||||
s,
|
||||
|
||||
@@ -194,6 +194,13 @@ fn mob_meta(
|
||||
let e = &m.extra;
|
||||
let id = |registry: &str, name: &str| hub.registry_id(registry, &format!("minecraft:{name}"));
|
||||
match kind {
|
||||
// Bat.DATA_ID_FLAGS: resting in bit 0, flying by default.
|
||||
"minecraft:bat" => {
|
||||
if e.flag {
|
||||
meta.push((16, serializer::BYTE, Value::Byte(1)));
|
||||
}
|
||||
defaults.push((16, serializer::BYTE, Value::Byte(0)));
|
||||
}
|
||||
// Sheep.DATA_WOOL_ID: the colour in the low nibble, 16 when sheared.
|
||||
"minecraft:sheep" => {
|
||||
let value = (e.color & 15) | if e.sheared { 16 } else { 0 };
|
||||
|
||||
@@ -3492,6 +3492,9 @@ impl Game<'_> {
|
||||
if m.species() == horizon_client::mobs::Species::Rabbit {
|
||||
horizon_client::mobs::rabbit::post_tick(m);
|
||||
}
|
||||
if m.species() == horizon_client::mobs::Species::Bat {
|
||||
horizon_client::mobs::bat::setup_animation_states(m);
|
||||
}
|
||||
}
|
||||
for o in self.orbs.iter_mut().filter(|_| running) {
|
||||
o.previous = o.position;
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
//! own simulation, which a client of a server doesn't run.
|
||||
use super::Game;
|
||||
use horizon_client::mobs::render::{PROFESSIONS, VILLAGER_TYPES};
|
||||
use horizon_client::mobs::{Mob, Species, tame};
|
||||
use horizon_client::mobs::{Mob, Species, bat, tame};
|
||||
use horizon_protocol::entity_data::Value;
|
||||
use horizon_protocol::registry::Builtin;
|
||||
|
||||
@@ -46,6 +46,8 @@ fn apply(m: &mut Mob, values: &[(u8, i32, Value)], builtin: &Builtin) {
|
||||
_ => {}
|
||||
}
|
||||
match (species, *index, value) {
|
||||
// Bat.DATA_ID_FLAGS: resting in bit 0.
|
||||
(Species::Bat, 16, Value::Byte(flags)) => bat::set_resting(m, flags & 1 != 0),
|
||||
// Sheep.DATA_WOOL_ID: the colour in the low nibble, 16 sheared.
|
||||
(Species::Sheep, 18, Value::Byte(wool)) => {
|
||||
m.extra.color = (*wool & 15) as u8;
|
||||
@@ -126,6 +128,10 @@ pub(super) fn client_defaults(m: &mut Mob) {
|
||||
if matches!(m.species(), Species::Wolf | Species::Cat) {
|
||||
m.extra.color = tame::RED;
|
||||
}
|
||||
if m.species() == Species::Bat {
|
||||
// Bat's constructor sets resting only on the server; the data default is 0.
|
||||
bat::set_resting(m, false);
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
@@ -174,6 +180,69 @@ mod tests {
|
||||
assert!(!calf.is_baby());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn bat_flags_select_continuous_client_clocks_without_changing_motion() {
|
||||
use horizon_client::mobs::{MobTypes, anim, keyframes::Animation};
|
||||
use horizon_core::geometry::Vec3;
|
||||
use serde_json::json;
|
||||
use std::{collections::HashMap, fs, sync::Arc};
|
||||
|
||||
// Original minimal resources keep this regression runnable without vanilla data.
|
||||
let root =
|
||||
std::env::temp_dir().join(format!("horizon-bat-animation-{}", std::process::id()));
|
||||
fs::create_dir(&root).unwrap();
|
||||
fs::write(root.join("entity-types.json"), r#"{"minecraft:bat": {}}"#).unwrap();
|
||||
fs::write(
|
||||
root.join("entity-models.json"),
|
||||
r#"{"minecraft:bat#main": {"children": {"right_wing": {}, "head": {}}}}"#,
|
||||
)
|
||||
.unwrap();
|
||||
let mut types = MobTypes::load(&root).unwrap();
|
||||
fs::remove_dir_all(root).unwrap();
|
||||
let position = Vec3::new(1.0, 2.25, 3.0);
|
||||
let velocity = Vec3::new(0.2, 0.3, 0.4);
|
||||
let mut m = Mob::new(
|
||||
1,
|
||||
Arc::new(types.types.remove("minecraft:bat").unwrap()),
|
||||
position,
|
||||
0.0,
|
||||
);
|
||||
assert!(bat::resting(&m));
|
||||
client_defaults(&mut m);
|
||||
assert!(!bat::resting(&m));
|
||||
m.velocity = velocity;
|
||||
m.age = 1;
|
||||
bat::setup_animation_states(&mut m);
|
||||
m.age = 4;
|
||||
apply(&mut m, &[(16, s::BYTE, Value::Byte(2))]);
|
||||
bat::setup_animation_states(&mut m);
|
||||
assert_eq!(m.anim.states[0].started, Some(1.0));
|
||||
|
||||
let curve = Animation::parse(&json!({"length": 1, "looping": true,
|
||||
"bones": {"right_wing": [{"target": "rotation", "keyframes":
|
||||
[[0,[0,0,0],[0,0,0],"linear"],[1,[0,1,0],[0,1,0],"linear"]]}]}}));
|
||||
let animations = HashMap::from([("BatAnimation.BAT_FLYING".into(), curve)]);
|
||||
let wing = |partial| {
|
||||
let mut poses = anim::Poses::new(&m.kind.model);
|
||||
anim::setup(&m, &anim::state(&m, partial), &mut poses, &animations);
|
||||
poses.get("right_wing")[4]
|
||||
};
|
||||
assert!(wing(0.5) > wing(0.0));
|
||||
|
||||
m.age = 5;
|
||||
apply(&mut m, &[(16, s::BYTE, Value::Byte(3))]);
|
||||
bat::setup_animation_states(&mut m);
|
||||
assert!(bat::resting(&m));
|
||||
assert_eq!(m.anim.states[0].started, None);
|
||||
assert_eq!(m.anim.states[1].started, Some(5.0));
|
||||
m.age = 7;
|
||||
apply(&mut m, &[(16, s::BYTE, Value::Byte(0))]);
|
||||
bat::setup_animation_states(&mut m);
|
||||
assert_eq!(m.anim.states[0].started, Some(7.0));
|
||||
assert_eq!(m.anim.states[1].started, None);
|
||||
assert_eq!((m.position, m.velocity), (position, velocity));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_wolf_takes_its_owner_flags_and_collar() {
|
||||
let Some(mut m) = mob("minecraft:wolf") else {
|
||||
|
||||
@@ -132,6 +132,10 @@ pub fn tick(m: &mut Mob) {
|
||||
} else {
|
||||
m.velocity.y *= 0.6;
|
||||
}
|
||||
setup_animation_states(m);
|
||||
}
|
||||
/// `Bat.setupAnimationStates`: client visuals, without changing server motion.
|
||||
pub fn setup_animation_states(m: &mut Mob) {
|
||||
let age = m.age as f32;
|
||||
if resting(m) {
|
||||
m.anim.states[0].stop();
|
||||
|
||||
Reference in New Issue
Block a user