Server: send a player standing up again, and draw other players' crouch
A value back at its default is left out of an entity's state, so the tracker never told clients that a player stopped crouching or a mob stopped burning: Entity's shared flags and pose now go back to 0. On a client of a server (the host window on the server thread), another player's crouch flag now reaches their model and name tag. From #731's server-thread list; lan_e2e's walls check passed in-frame and failed with --server-thread. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user