Other players are drawn lying in their beds

A sleeping guest stood on top of its bed for everyone else: the server
sent its pose but never its bed (LivingEntity.SLEEPING_POS goes only to
the sleeper itself), Horizon's clients had no sleeping pose for other
players, and the host's own models of its guests ignored the bed. A
player paired with the sleeper later (the host walking up from afar)
saw the same.

The tracked state of a sleeping player (the host or a guest) now holds
its bed, so pairing and updates send it, and its removal sends the empty
position back; the clients and the host's guest models lie the player in
the bed as LivingEntityRenderer.setupRotations does for Pose.SLEEPING
(the villagers' sleeping pose, by the bed's facing).

lan_e2e `sleep`: the host draws the sleeping guest lying, the guest the
sleeping host, and neither once they are up.

Fixes #1045

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Ludovic Marie
2026-10-21 21:43:01 +02:00
parent b31cb42242
commit 4f461b27ed
9 changed files with 79 additions and 11 deletions
@@ -102,6 +102,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
equipment: Default::default(),
health: 20.0,
attributes: Vec::new(),
bed: None,
living_flags: 0,
};
loop {
+19
View File
@@ -395,6 +395,8 @@ impl Game<'_> {
],
"chunks": g.sent_chunks.len(),
"tracked": g.tracker.len(),
// Whether the host draws this guest lying in a bed.
"model_lying": h.models.get(&g.conn).map(|m| m.extra.ints[1] != 0),
// The armour the host draws on this guest, head to feet.
"model_armor": h.models.get(&g.conn).map(|m| {
[&m.extra.head, &m.extra.chest, &m.extra.legs, &m.extra.feet]
@@ -735,6 +737,7 @@ impl Game<'_> {
health: p.health.health(),
attributes: horizon_client::lan::attributes::syncable(&p.attributes),
living_flags: living_flags(self.using),
bed: self.sleeping,
})
}
@@ -1207,6 +1210,8 @@ impl Game<'_> {
.each_ref()
.map(|s| s.as_ref().map(|s| s.item.clone()));
m.extra.crouching = g.sneaking;
// Lying in its bed (LivingEntity.getBedOrientation).
m.extra.ints[1] = g.bed.map_or(0, |b| self.bed_facing(b));
// LivingEntity.updateSwingTime: the arm swing lan_swings started.
m.anim.attack_anim_o = m.anim.attack_anim;
horizon_client::mobs::ai::tick_swing(m);
@@ -1218,6 +1223,20 @@ impl Game<'_> {
}
}
/// The bed at `head` as a sleeping model lies in it (`ints[1]`,
/// `villager::sleep_pose`): its `facing`.
pub(super) fn bed_facing(&self, head: [i32; 3]) -> i32 {
let state = self.world.block(head[0], head[1], head[2]);
let facing = self
.pack
.assets
.registry
.state(state)
.and_then(|s| s.properties.get("facing"))
.map(String::as_str);
horizon_client::mobs::villager::bed_facing_code(facing)
}
/// The guests' models for the entity pass.
pub(super) fn guest_model_geometry(
&self,
+19
View File
@@ -1544,6 +1544,18 @@ impl Game<'_> {
}
}
}
// LivingEntity.onSyncedDataUpdated(SLEEPING_POS_ID): another
// player lies down in their bed (drawn lying in it), or gets up.
if other {
for (index, _, value) in &p.values {
if let (14, Value::OptPos(bed)) = (index, value) {
let code = bed.map_or(0, |b| self.bed_facing(b));
if let Some(m) = self.mobs.iter_mut().find(|m| m.id == p.id as u32) {
m.extra.ints[1] = code;
}
}
}
}
// LivingEntity.onSyncedDataUpdated(SLEEPING_POS_ID): this
// player lies down in the bed, or gets up.
if self.remote.as_ref().is_some_and(|r| r.entity_id == p.id) {
@@ -4102,6 +4114,13 @@ impl Game<'_> {
.filter(|m| r.level_players.contains_key(&(m.id as i32)) && !m.alive())
.map(|m| m.id)
.collect::<Vec<_>>(),
// The other players this client draws lying in a bed (SLEEPING_POS).
"lying_players": self
.mobs
.iter()
.filter(|m| r.level_players.contains_key(&(m.id as i32)) && m.extra.ints[1] != 0)
.map(|m| m.id)
.collect::<Vec<_>>(),
// The player's own model exists (third person and the inventory draw it).
"player_model": self.player_model.is_some(),
"health": r.health.0,
+3 -1
View File
@@ -393,11 +393,13 @@ impl ServerEntity {
.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).
// back to 0 (a player standing up again, a mob no longer on fire),
// a sleeper's bed to none.
for (index, kind, _) in &self.meta {
let default = match (*index, *kind) {
(0, serializer::BYTE) => Value::Byte(0),
(6, serializer::POSE) => Value::Id(0),
(14, serializer::OPTIONAL_BLOCK_POS) => Value::OptPos(None),
_ => continue,
};
if !e.meta.iter().any(|m| m.0 == *index) {
+11 -1
View File
@@ -85,6 +85,8 @@ pub struct HostState {
pub attributes: Vec<play::AttributeSnapshot>,
/// `LivingEntity.DATA_LIVING_ENTITY_FLAGS` (the item in use).
pub living_flags: i8,
/// The bed the host sleeps in (`LivingEntity.SLEEPING_POS`).
pub bed: Option<[i32; 3]>,
}
/// Everything the hub needs from the game for one tick.
@@ -1467,6 +1469,7 @@ impl Hub {
on_ground: bool,
flags: (bool, bool, bool, bool),
living_flags: i8,
bed: Option<[i32; 3]>,
skin: u8,
health: f32,
equipment: Vec<(u8, Option<horizon_protocol::item::Stack>)>,
@@ -1502,6 +1505,11 @@ impl Hub {
// Always there: the trackers send the entries that changed, and an
// item no longer in use is a change back to 0.
meta.push((8, serializer::BYTE, Value::Byte(living_flags)));
// LivingEntity.SLEEPING_POS: the others draw the player lying in it,
// a player paired later too.
if let Some(bed) = bed.filter(|_| sleeping) {
meta.push((14, serializer::OPTIONAL_BLOCK_POS, Value::OptPos(Some(bed))));
}
if (health - 1.0).abs() > f32::EPSILON && health != 20.0 {
meta.push((9, serializer::FLOAT, Value::Float(health)));
}
@@ -1565,8 +1573,9 @@ impl Hub {
h.position,
(h.yaw, h.pitch, h.head_yaw),
h.on_ground,
(h.sneaking, h.sprinting, false, false),
(h.sneaking, h.sprinting, false, h.bed.is_some()),
h.living_flags,
h.bed,
0x7F,
h.health,
equipment,
@@ -1598,6 +1607,7 @@ impl Hub {
g.on_ground,
(g.sneaking, g.sprinting, g.fall_flying, g.sleeping),
g.living_flags,
g.bed,
g.info.model_customisation,
g.health,
equipment,
+2 -1
View File
@@ -749,7 +749,8 @@ pub fn base_transform_at(m: &Mob, alpha: f32, origin: glam::Mat4) -> glam::Mat4
let ticks = (m.age as f32 + alpha).floor();
body += (f64::from(ticks * 3.25).cos() * std::f64::consts::PI * 0.4) as f32;
}
let sleep = (m.species() == Species::Villager)
// A sleeping villager, or another player lying in their bed.
let sleep = (m.species() == Species::Villager || m.kind.id == "minecraft:player")
.then(|| super::villager::sleep_pose(m))
.flatten();
let rotation = match sleep {
+10 -6
View File
@@ -98,12 +98,7 @@ pub fn start_sleeping(m: &mut Mob, p: [i32; 3], w: &MobWorld) -> bool {
if w.prop(p[0], p[1], p[2], "occupied") == Some("true") {
return false;
}
m.extra.ints[1] = match w.prop(p[0], p[1], p[2], "facing") {
Some("north") => 1,
Some("south") => 2,
Some("west") => 3,
_ => 4,
};
m.extra.ints[1] = bed_facing_code(w.prop(p[0], p[1], p[2], "facing"));
m.nav_stop();
ext_mut(m).last_slept = Some(w.game_time);
m.velocity = horizon_core::geometry::Vec3::ZERO;
@@ -144,6 +139,15 @@ pub fn stop_sleeping(m: &mut Mob, w: &MobWorld) {
}
/// `LivingEntityRenderer.sleepDirectionToRotation` and the bed's direction
/// (the body is shifted back from the pillow by the standing eye height).
/// A bed's `facing` as `sleep_pose` keeps it in `ints[1]`.
pub fn bed_facing_code(facing: Option<&str>) -> i32 {
match facing {
Some("north") => 1,
Some("south") => 2,
Some("west") => 3,
_ => 4,
}
}
pub fn sleep_pose(m: &Mob) -> Option<(f32, [f32; 2])> {
Some(match m.extra.ints[1] {
1 => (270.0, [0.0, -1.0]),
+1
View File
@@ -184,6 +184,7 @@ impl Server {
equipment: Default::default(),
health: 20.0,
attributes: Vec::new(),
bed: None,
living_flags: 0,
};
let mut ctx = TickCtx {
+13 -2
View File
@@ -1219,6 +1219,11 @@ def check_sleep(host, guest, out):
asleep = {'guest': guest('state').get('sleeping'), 'host': host('state').get('sleeping'),
'server': lan_guest(host).get('sleeping')}
guest.shot(out, 'sleep-guest')
# The host draws the guest lying in its bed (#1045): in frame its model, on the server thread its
# client's (SLEEPING_POS), and a client pairing with the sleeper later too.
host.wait(5)
lying = {'host': lan_guest(host).get('model_lying') if not SERVER_THREAD else bool(remote(host)['lying_players'])}
host.shot(out, 'sleep-host-sees-guest')
# Alone in bed: still night 120 ticks later (everyone must sleep).
guest.wait(120)
night = host('state')['time']['time_of_day']
@@ -1228,19 +1233,25 @@ def check_sleep(host, guest, out):
up = guest('state').get('sleeping')
guest.raw('interact', *guest_bed)
host.raw('interact', *host_bed)
host.wait(130)
host.wait(5)
# Both in bed: the guest draws the host lying too.
lying['guest'] = bool(remote(guest)['lying_players'])
host.wait(125)
after = {'guest': guest('state').get('sleeping'), 'host': host('state').get('sleeping'),
'time': host('state')['time']['time_of_day']}
lying['after'] = bool(remote(guest)['lying_players'])
guest.shot(out, 'sleep-morning')
for at in (guest_bed, host_bed):
guest('command', command=f'fill {at[0] - 1} {at[1]} {at[2]} {at[0]} {at[1]} {at[2]} minecraft:air')
host('command', command='time set day')
detail = {'asleep': asleep, 'night': night, 'up': up, 'after': after}
detail = {'asleep': asleep, 'night': night, 'up': up, 'after': after, 'lying': lying}
assert asleep['guest'] == guest_bed and asleep['server'] == guest_bed, f'the guest is not in its bed: {detail}'
assert asleep['host'] is None, f'the guest\'s bed put the host to sleep: {detail}'
assert 13000 < night < 23000, f'one of two players asleep ended the night: {detail}'
assert up is None, f'Escape did not get the guest up: {detail}'
assert after['guest'] is None and after['host'] is None and after['time'] < 1000, f'no morning: {detail}'
assert lying['host'] and lying['guest'], f'a sleeping player is drawn standing: {detail}'
assert not lying['after'], f'a player up again is still drawn lying: {detail}'
return detail
def check_push(host, guest, out):
guest('command', command='gamemode survival')