[PR #7591] Beds: the sleeping height comes from the bed's shape, not a constant #7697

Open
opened 2026-11-03 07:22:10 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/horizon-rust/horizon/pull/7591
Author: @MSedgeMC
Created: 11/2/2026
Status: 🔄 Open

Base: main ← Head: fix/straw-bed-sleep-height


📝 Commits (4)

  • a1f83a7 fix: a bed's sleeping height comes from the shape it is slept on
  • e43b10c fix: the sleeper's position uses that height
  • db79949 test: the shape's top, the straw bed's foot and setPosToBed's 0.125
  • 611bbed port_map: StrawBedBlock.getSleepHeight is ported

📊 Changes

4 files changed (+182 additions, -14 deletions)

View changed files

📝 crates/horizon-client/src/game.rs (+13 -12)
📝 crates/horizon-client/src/game/beds.rs (+167 -0)
📝 crates/horizon-client/src/game/respawn_anchor.rs (+1 -1)
📝 tools/port_map/game2-016.tsv (+1 -1)

📄 Description

AbstractBedBlock.getSleepHeight answers with OptionalDouble.of(shape.max(Direction.Axis.Y)) for the block's shape, and OptionalDouble.empty() when the shape is empty (bytecode 12–45). StrawBedBlock.getSleepHeight runs first and rewrites the position: for a PART == HEAD it steps to getConnectedDirection(state) (the foot) and only is(this) with PART == FOOT will do — otherwise it returns empty before the shape is ever looked at (bytecode 0–62). LivingEntity.startSleeping calls it and returns false when the height is empty (bytecode 34–55), so a straw bed's head standing alone is not slept in at all. LivingEntity.setPosToBed(double, BlockPos) then places the sleeper at pos.getX() + 0.5, pos.getY() + height + 0.125, pos.getZ() + 0.5 (0.125d at 0, dload_1 added to getY() at 16–25).

What Horizon lacked

Both places a sleeper is placed (try_sleep when the player lies down, tick_sleep every tick after) used the constant head y + 0.5625 + 0.125. That is an ordinary bed's head, so a straw bed's head put the player on top of the pillow instead of on the foot's shape, and a straw bed head whose foot was broken still put them in it — vanilla refuses to lie down there.

beds::sleep_height asks the bed: StrawBedBlock's head-to-foot walk (slept_on), then the top of the shape the pack gives that block (outline_boxes, VoxelShape.max(Axis.Y) from the block's own y). sleeping_position applies setPosToBed's 0.125. try_sleep stops before stop_mining/occupied when the bed gives no height, and tick_sleep leaves the sleeper where it is.

Proven: game::beds::tests (3 tests, all passing):

  • a_straw_beds_head_is_slept_on_at_its_foot — the foot is used (Some(Foot)); a head facing a head, a foot replaced by minecraft:oak_planks, and a foot that is another bed (minecraft:red_bed) all give None, which is the "no sleeping" case; a straw bed's foot and an ordinary bed's head stay on their own shape.
  • the_height_is_the_top_of_the_shape — a 9/16 bed is Some(0.5625); a taller pillow Some(0.6875); the tallest of two boxes wins; an empty shape is None.
  • the_sleeper_lies_an_eighth_above_the_shape — a 7/16 foot at y 70 puts the sleeper at y = 70.5625; the constant gave 70.6875 for every bed, which is the second assertion in the same test.

Not proven: the tests cover the decision table and the arithmetic, not a live session — asserting the pack's real bed shapes end to end needs a headless game with prepared resources, which the VM queue would have to run. The straw bed's own BASE_SHAPE/PILLOW_SHAPE numbers are not asserted here; the code takes whatever shape the pack gives the block, as vanilla takes getShape.


🔄 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/7591 **Author:** [@MSedgeMC](https://github.com/MSedgeMC) **Created:** 11/2/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `fix/straw-bed-sleep-height` --- ### 📝 Commits (4) - [`a1f83a7`](https://github.com/horizon-rust/horizon/commit/a1f83a7bda2aea8d1ffaa4a1279460e19bd9dcde) fix: a bed's sleeping height comes from the shape it is slept on - [`e43b10c`](https://github.com/horizon-rust/horizon/commit/e43b10c35602f46ffc77fdadaa529b2c69d73220) fix: the sleeper's position uses that height - [`db79949`](https://github.com/horizon-rust/horizon/commit/db799490ba2ae6c497c7d72be58ef169d5b1f70e) test: the shape's top, the straw bed's foot and setPosToBed's 0.125 - [`611bbed`](https://github.com/horizon-rust/horizon/commit/611bbed5a573ee2f68aa576f356399129cfd240e) port_map: StrawBedBlock.getSleepHeight is ported ### 📊 Changes **4 files changed** (+182 additions, -14 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/src/game.rs` (+13 -12) 📝 `crates/horizon-client/src/game/beds.rs` (+167 -0) 📝 `crates/horizon-client/src/game/respawn_anchor.rs` (+1 -1) 📝 `tools/port_map/game2-016.tsv` (+1 -1) </details> ### 📄 Description `AbstractBedBlock.getSleepHeight` answers with `OptionalDouble.of(shape.max(Direction.Axis.Y))` for the block's shape, and `OptionalDouble.empty()` when the shape is empty (bytecode 12–45). `StrawBedBlock.getSleepHeight` runs first and rewrites the position: for a `PART == HEAD` it steps to `getConnectedDirection(state)` (the foot) and only `is(this)` with `PART == FOOT` will do — otherwise it returns empty before the shape is ever looked at (bytecode 0–62). `LivingEntity.startSleeping` calls it and returns **false** when the height is empty (bytecode 34–55), so a straw bed's head standing alone is not slept in at all. `LivingEntity.setPosToBed(double, BlockPos)` then places the sleeper at `pos.getX() + 0.5`, `pos.getY() + height + 0.125`, `pos.getZ() + 0.5` (`0.125d` at 0, `dload_1` added to `getY()` at 16–25). **What Horizon lacked** Both places a sleeper is placed (`try_sleep` when the player lies down, `tick_sleep` every tick after) used the constant `head y + 0.5625 + 0.125`. That is an ordinary bed's head, so a straw bed's head put the player on top of the pillow instead of on the foot's shape, and a straw bed head whose foot was broken still put them in it — vanilla refuses to lie down there. `beds::sleep_height` asks the bed: `StrawBedBlock`'s head-to-foot walk (`slept_on`), then the top of the shape the pack gives that block (`outline_boxes`, `VoxelShape.max(Axis.Y)` from the block's own y). `sleeping_position` applies `setPosToBed`'s 0.125. `try_sleep` stops before `stop_mining`/`occupied` when the bed gives no height, and `tick_sleep` leaves the sleeper where it is. **Proven:** `game::beds::tests` (3 tests, all passing): - `a_straw_beds_head_is_slept_on_at_its_foot` — the foot is used (`Some(Foot)`); a head facing a head, a foot replaced by `minecraft:oak_planks`, and a foot that is another bed (`minecraft:red_bed`) all give `None`, which is the "no sleeping" case; a straw bed's foot and an ordinary bed's head stay on their own shape. - `the_height_is_the_top_of_the_shape` — a 9/16 bed is `Some(0.5625)`; a taller pillow `Some(0.6875)`; the tallest of two boxes wins; an empty shape is `None`. - `the_sleeper_lies_an_eighth_above_the_shape` — a 7/16 foot at y 70 puts the sleeper at `y = 70.5625`; the constant gave `70.6875` for every bed, which is the second assertion in the same test. **Not proven:** the tests cover the decision table and the arithmetic, not a live session — asserting the pack's real bed shapes end to end needs a headless game with prepared resources, which the VM queue would have to run. The straw bed's own `BASE_SHAPE`/`PILLOW_SHAPE` numbers are not asserted here; the code takes whatever shape the pack gives the block, as vanilla takes `getShape`. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
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#7697
No description provided.