[PR #3037] [MERGED] Beds: occupied while someone sleeps in them, and sleeping villagers are saved #4763

Closed
opened 2026-11-03 05:07:45 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/horizon-rust/horizon/pull/3037
Author: @ASOwnerYT
Created: 10/28/2026
Status: ✅ Merged
Merged: 10/29/2026
Merged by: @ludovic111

Base: main ← Head: claude/dreamy-khayyam-1553ca


📝 Commits (3)

  • cc575e2 Sleeping: villagers lie on the pillow, the player's body shows, beds wake villagers
  • df4877a lan_e2e: sleep-villager, a bed wakes its villager and the sleeper's body shows
  • f1212a0 Beds: occupied while someone sleeps in them, and sleeping villagers are saved

📊 Changes

18 files changed (+517 additions, -33 deletions)

View changed files

📝 crates/horizon-client/src/game.rs (+33 -2)
➕ crates/horizon-client/src/game/beds.rs (+97 -0)
📝 crates/horizon-client/src/game/creatures.rs (+7 -0)
📝 crates/horizon-client/src/game/dedicated.rs (+2 -0)
📝 crates/horizon-client/src/game/integrated.rs (+2 -0)
📝 crates/horizon-client/src/game/lan.rs (+1 -3)
📝 crates/horizon-client/src/game/levels.rs (+1 -0)
📝 crates/horizon-client/src/game/perspective.rs (+11 -3)
📝 crates/horizon-client/src/game/remote.rs (+5 -0)
📝 crates/horizon-client/src/game/saving.rs (+1 -0)
📝 crates/horizon-client/src/game/villagers.rs (+32 -0)
📝 crates/horizon-client/src/mobs.rs (+6 -0)
📝 crates/horizon-client/src/mobs/ai.rs (+2 -2)
📝 crates/horizon-client/src/mobs/living.rs (+6 -0)
📝 crates/horizon-client/src/mobs/render.rs (+1 -1)
📝 crates/horizon-client/src/mobs/villager.rs (+90 -17)
📝 crates/horizon-client/src/mobs/villager_brain.rs (+3 -3)
📝 tools/lan_e2e.py (+217 -2)

📄 Description

🤖 Opened by asowneryt's AI agent (Claude Code), not by asowneryt himself.

Builds on horizon-rust/horizon#3016 (its two commits are the first two here). Until it merges, review only the last commit: Beds: occupied while someone sleeps in them, and sleeping villagers are saved (15 files, +411 −31, about 180 of those lines are the two lan_e2e checks).

What and why

Today nothing ever sets a bed's occupied property, so two players can share a bed and a villager can lie down in a bed a player is sleeping in. This PR follows vanilla:

  • LivingEntity.startSleeping / stopSleeping: the bed's head gets occupied=true when someone lies down and false when they get up. The foot follows through the existing updateShape.
    • Villagers send a new MobEvent::BedOccupied from start_sleeping and stop_sleeping. That covers the brain, being hurt, the bed disappearing, being kicked out, and death (LivingEntity.die). The bed a villager lies in is kept as sleeping_pos, no longer taken from its home memory.
    • Players and LAN guests (game/beds.rs): the bed is marked when the player lies down (try_sleep). It is freed in the level's tick once no player sleeps in it. This one check covers waking, the Leave Bed button, death, a broken bed and a guest leaving, including a guest's STOP_SLEEPING, which the hub handles without Game. Levels with a player-held bed keep ticking until it is freed. Before the server's last save (integrated, dedicated, and closing an in-frame world), every player's bed is freed, as vanilla's PlayerList.removeAll does through ServerPlayer.disconnect.
  • AbstractBedBlock.useWithoutItem: if the bed is occupied, the villager in it is woken (kickVillagerOutOfBed, from #3016); otherwise the player sees "This bed is occupied".
  • Save data: LivingEntity's sleeping_pos (26.3's key; the datafixer already turns old SleepingX/Y/Z into it) is written and read for villagers. Without it, a world saved at night would load with beds stuck occupied and nobody in them. The DATA_SLEEPING_POS sent to clients now uses it too.
  • Two gaps the new checks turned up:
    • In-frame, the host now gets up when its bed is gone (checkBedExists); guests already did.
    • A client that leaves a server while asleep no longer comes back with the in-bed chat stuck open (leave_server clears sleeping).

How it was checked

  • lan_e2e bed-occupied (new) passes in both server-thread and --in-frame modes:
    • while the host sleeps, the head and foot are occupied=true;
    • the guest can't lie down and gets "This bed is occupied";
    • the bed is free again after Escape, after death, after the bed is broken and replaced, and after the sleeping guest disconnects;
    • the guest then sleeps in it.
  • lan_e2e sleep-reload (new, server thread) passes: a villager asleep in its bed while the guest sleeps in another; the host saves, quits and reopens; the villager still has sleeping_pos and an occupied bed, and the guest's bed is saved free.
  • The existing sleep and sleep-villager checks pass in both modes.
  • Unit test a_sleeper_is_saved_asleep_in_its_bed covers the sleeping_pos round trip.
  • pr_ready: everything passes except entity_model, which fails on the known bat oracle bug (IllegalAccessException on Bat.flyAnimationState), fixed by horizon-rust/horizon#2941 and unrelated to this change. The scope line counts #3016's lines too.

Label: none (a fix).

pr_ready (tools/pr_ready.py --base upstream/main on cachyos, against upstream/main at 56f968e11, 29 min 52 s)

Check Result
Scope ⚠️ 18 files, +517 −33; 550 lines of code: over 500, split it if it can ship in parts
Cargo.lock ✅ unchanged
Public tree ✅
Python tests ✅ 398 passed (19 s)
rustfmt ✅ (5 s)
clippy ✅ (1 min 29 s)
tests: horizon-client ✅ 1263 passed (2 min 13 s)
doc tests ✅ 0 passed (24 s)
content root tests ➖ content root untouched
tokens.css up to date ➖ theme untouched
launcher rustfmt ➖ launcher untouched
launcher clippy ➖ launcher untouched
launcher tests ➖ launcher untouched
Parity ❌ 68 affected, 66 passed, failed: entity_model (25 min 16 s)
Label player-facing: feature if players get something new, no label for a fix (release-now if urgent)

🤖 Generated with Claude Code


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/horizon-rust/horizon/pull/3037 **Author:** [@ASOwnerYT](https://github.com/ASOwnerYT) **Created:** 10/28/2026 **Status:** ✅ Merged **Merged:** 10/29/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `claude/dreamy-khayyam-1553ca` --- ### 📝 Commits (3) - [`cc575e2`](https://github.com/horizon-rust/horizon/commit/cc575e2c6a3796d4df35c70c597f14827a9ab25c) Sleeping: villagers lie on the pillow, the player's body shows, beds wake villagers - [`df4877a`](https://github.com/horizon-rust/horizon/commit/df4877a10bbf5637d920de4159af319de35ed26c) lan_e2e: sleep-villager, a bed wakes its villager and the sleeper's body shows - [`f1212a0`](https://github.com/horizon-rust/horizon/commit/f1212a0e5acccc4bd6fd1d0db25725cb6c309bda) Beds: occupied while someone sleeps in them, and sleeping villagers are saved ### 📊 Changes **18 files changed** (+517 additions, -33 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/src/game.rs` (+33 -2) ➕ `crates/horizon-client/src/game/beds.rs` (+97 -0) 📝 `crates/horizon-client/src/game/creatures.rs` (+7 -0) 📝 `crates/horizon-client/src/game/dedicated.rs` (+2 -0) 📝 `crates/horizon-client/src/game/integrated.rs` (+2 -0) 📝 `crates/horizon-client/src/game/lan.rs` (+1 -3) 📝 `crates/horizon-client/src/game/levels.rs` (+1 -0) 📝 `crates/horizon-client/src/game/perspective.rs` (+11 -3) 📝 `crates/horizon-client/src/game/remote.rs` (+5 -0) 📝 `crates/horizon-client/src/game/saving.rs` (+1 -0) 📝 `crates/horizon-client/src/game/villagers.rs` (+32 -0) 📝 `crates/horizon-client/src/mobs.rs` (+6 -0) 📝 `crates/horizon-client/src/mobs/ai.rs` (+2 -2) 📝 `crates/horizon-client/src/mobs/living.rs` (+6 -0) 📝 `crates/horizon-client/src/mobs/render.rs` (+1 -1) 📝 `crates/horizon-client/src/mobs/villager.rs` (+90 -17) 📝 `crates/horizon-client/src/mobs/villager_brain.rs` (+3 -3) 📝 `tools/lan_e2e.py` (+217 -2) </details> ### 📄 Description > 🤖 Opened by asowneryt's AI agent (Claude Code), not by asowneryt himself. **Builds on horizon-rust/horizon#3016** (its two commits are the first two here). Until it merges, review only the last commit: `Beds: occupied while someone sleeps in them, and sleeping villagers are saved` (15 files, +411 −31, about 180 of those lines are the two lan_e2e checks). ## What and why Today nothing ever sets a bed's `occupied` property, so two players can share a bed and a villager can lie down in a bed a player is sleeping in. This PR follows vanilla: - **`LivingEntity.startSleeping` / `stopSleeping`:** the bed's head gets `occupied=true` when someone lies down and `false` when they get up. The foot follows through the existing `updateShape`. - **Villagers** send a new `MobEvent::BedOccupied` from `start_sleeping` and `stop_sleeping`. That covers the brain, being hurt, the bed disappearing, being kicked out, and death (`LivingEntity.die`). The bed a villager lies in is kept as `sleeping_pos`, no longer taken from its `home` memory. - **Players and LAN guests** (`game/beds.rs`): the bed is marked when the player lies down (`try_sleep`). It is freed in the level's tick once no player sleeps in it. This one check covers waking, the Leave Bed button, death, a broken bed and a guest leaving, including a guest's STOP_SLEEPING, which the hub handles without `Game`. Levels with a player-held bed keep ticking until it is freed. Before the server's last save (integrated, dedicated, and closing an in-frame world), every player's bed is freed, as vanilla's `PlayerList.removeAll` does through `ServerPlayer.disconnect`. - **`AbstractBedBlock.useWithoutItem`:** if the bed is occupied, the villager in it is woken (`kickVillagerOutOfBed`, from #3016); otherwise the player sees "This bed is occupied". - **Save data:** `LivingEntity`'s `sleeping_pos` (26.3's key; the datafixer already turns old `SleepingX/Y/Z` into it) is written and read for villagers. Without it, a world saved at night would load with beds stuck occupied and nobody in them. The `DATA_SLEEPING_POS` sent to clients now uses it too. - **Two gaps the new checks turned up:** - In-frame, the host now gets up when its bed is gone (`checkBedExists`); guests already did. - A client that leaves a server while asleep no longer comes back with the in-bed chat stuck open (`leave_server` clears `sleeping`). ## How it was checked - `lan_e2e` **`bed-occupied`** (new) passes in both server-thread and `--in-frame` modes: - while the host sleeps, the head and foot are `occupied=true`; - the guest can't lie down and gets "This bed is occupied"; - the bed is free again after Escape, after death, after the bed is broken and replaced, and after the sleeping guest disconnects; - the guest then sleeps in it. - `lan_e2e` **`sleep-reload`** (new, server thread) passes: a villager asleep in its bed while the guest sleeps in another; the host saves, quits and reopens; the villager still has `sleeping_pos` and an occupied bed, and the guest's bed is saved free. - The existing `sleep` and `sleep-villager` checks pass in both modes. - Unit test `a_sleeper_is_saved_asleep_in_its_bed` covers the `sleeping_pos` round trip. - `pr_ready`: everything passes except `entity_model`, which fails on the known bat oracle bug (`IllegalAccessException` on `Bat.flyAnimationState`), fixed by horizon-rust/horizon#2941 and unrelated to this change. The scope line counts #3016's lines too. Label: none (a fix). **pr_ready** (`tools/pr_ready.py --base upstream/main` on cachyos, against upstream/main at 56f968e11, 29 min 52 s) | Check | Result | | --- | --- | | Scope | ⚠️ 18 files, +517 −33; 550 lines of code: over 500, split it if it can ship in parts | | Cargo.lock | ✅ unchanged | | Public tree | ✅ | | Python tests | ✅ 398 passed (19 s) | | rustfmt | ✅ (5 s) | | clippy | ✅ (1 min 29 s) | | tests: horizon-client | ✅ 1263 passed (2 min 13 s) | | doc tests | ✅ 0 passed (24 s) | | content root tests | ➖ content root untouched | | tokens.css up to date | ➖ theme untouched | | launcher rustfmt | ➖ launcher untouched | | launcher clippy | ➖ launcher untouched | | launcher tests | ➖ launcher untouched | | Parity | ❌ 68 affected, 66 passed, failed: entity_model (25 min 16 s) | | Label | player-facing: `feature` if players get something new, no label for a fix (`release-now` if urgent) | 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-03 05:07:45 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
horizon-rust/horizon#4763
No description provided.