diff --git a/crates/horizon-client/src/game/remote.rs b/crates/horizon-client/src/game/remote.rs index 680360c93..feeb1750c 100644 --- a/crates/horizon-client/src/game/remote.rs +++ b/crates/horizon-client/src/game/remote.rs @@ -1490,6 +1490,20 @@ impl Game<'_> { } } } + // Entity.DATA_SHARED_FLAGS_ID's crouching bit: another + // player's crouch (their model and Entity.isDiscrete's name tag). + if self + .remote + .as_ref() + .is_some_and(|r| r.level_players.contains_key(&p.id)) + && let Some(m) = self.mobs.iter_mut().find(|m| m.id == p.id as u32) + { + for (index, _, value) in &p.values { + if let (0, Value::Byte(flags)) = (index, value) { + m.extra.crouching = flags & 2 != 0; + } + } + } for (index, _, value) in &p.values { if *index == ITEM_ENTITY_ITEM && let Value::Item(stack) = value diff --git a/crates/horizon-client/src/lan/entity.rs b/crates/horizon-client/src/lan/entity.rs index 3d8090267..d63a76b89 100644 --- a/crates/horizon-client/src/lan/entity.rs +++ b/crates/horizon-client/src/lan/entity.rs @@ -8,7 +8,7 @@ use super::tracking; use horizon_protocol::{ buf::pack_degrees, - entity_data::Value, + entity_data::{Value, serializer}, item::Stack, packets::play::{ self, AddEntity, EntityPositionSync, MoveEntity, MoveEntityPos, MoveEntityPosRot, @@ -347,12 +347,25 @@ impl ServerEntity { if !dirty { return; } - let changed: Vec<_> = e + let mut changed: Vec<_> = e .meta .iter() .filter(|m| !self.meta.contains(m)) .cloned() .collect(); + // A value back at its default is left out of the state, but the + // clients still hold the old one: Entity's shared flags and pose go + // back to 0 (a player standing up again, a mob no longer on fire). + for (index, kind, _) in &self.meta { + let default = match (*index, *kind) { + (0, serializer::BYTE) => Value::Byte(0), + (6, serializer::POSE) => Value::Id(0), + _ => continue, + }; + if !e.meta.iter().any(|m| m.0 == *index) { + changed.push((*index, *kind, default)); + } + } if !changed.is_empty() { out.push(play::Clientbound::SetEntityData(SetEntityData { id: e.id, @@ -697,6 +710,35 @@ mod tests { )); } + #[test] + fn cleared_flags_and_pose_go_back_to_their_default() { + let mut e = state(0.0); + let mut s = added(&e); + changes(&mut s, &e); + // A crouching player: the crouch flag and the crouching pose. + e.meta = vec![ + (0, serializer::BYTE, Value::Byte(2)), + (6, serializer::POSE, Value::Id(5)), + ]; + changes(&mut s, &e); + e.meta.clear(); + let data = changes(&mut s, &e) + .into_iter() + .find_map(|p| match p { + play::Clientbound::SetEntityData(d) => Some(d), + _ => None, + }) + .expect("standing up is sent"); + assert_eq!( + data.values, + vec![ + (0, serializer::BYTE, Value::Byte(0)), + (6, serializer::POSE, Value::Id(0)), + ] + ); + assert!(changes(&mut s, &e).is_empty()); + } + #[test] fn metadata_and_equipment_send_only_the_changes() { let mut e = state(0.0);