[PR #2687] [MERGED] Put books into a chiseled bookshelf and take them out #4540

Closed
opened 2026-11-03 04:17:55 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/horizon-rust/horizon/pull/2687
Author: @kacpherek
Created: 10/27/2026
Status: ✅ Merged
Merged: 10/27/2026
Merged by: @ludovic111

Base: main ← Head: feat/shelf-use


📝 Commits (2)

  • ff28fd8 Read a chiseled bookshelf's last slot and a shelf's back mask with a comparator
  • 2f6d259 Put books into a chiseled bookshelf and take them out

📊 Changes

8 files changed (+350 additions, -5 deletions)

View changed files

📝 crates/horizon-client/src/containers.rs (+23 -0)
📝 crates/horizon-client/src/game.rs (+17 -3)
➕ crates/horizon-client/src/game/chiseled_bookshelf.rs (+178 -0)
📝 crates/horizon-client/src/game/machines.rs (+54 -1)
📝 crates/horizon-client/src/save.rs (+12 -0)
📝 crates/horizon-world/src/level/data.rs (+6 -0)
📝 crates/horizon-world/src/level/interact.rs (+59 -0)
📝 crates/horizon-world/src/level/mod.rs (+1 -1)

📄 Description

What and why

Using a chiseled bookshelf did nothing: Horizon kept only its saved data. It is now a block entity (BlockEntity::ChiseledBookshelf: six slots and lastInteractedSlot, loaded and saved as Items and last_interacted_slot).

  • Click a slot with a #bookshelf_books item: one book goes in, the insert sound plays (enchanted variant for enchanted books), the used statistic and item_used_on_block fire, and the block state's slot_N_occupied follows. Click an occupied slot (main hand): the book goes to the inventory, or is dropped when it does not fit, with the pickup sound. A click on an empty slot without a book is consumed, a click off the 3x2 front grid passes.
  • The slot comes from SelectableSlotContainer.getHitSlot, ported as horizon_world::level::hit_slot. The same result feeds the world crate's use_item_on, so the client's prediction ends the click like the server does (a writable book does not open the editor).
  • Server thread, --in-frame and LAN guests share the use code; the new state reaches clients with the normal block update, and nothing else needs sending (the books are drawn by the state's model, ChiseledBookShelfBlockEntity has no update packet).
  • Hoppers and droppers treat it as a container: books only, one per slot (canPlaceItem); the slot whose book came or went updates the state and lastInteractedSlot.
  • The comparator now reads lastInteractedSlot from the block entity.
  • Breaking it still spills its books (the existing Containers.dropContents path now reads the live slots).

This builds on #2641 (its commit is the first one here): its shelf_signal read the saved tag, which a modelled block entity replaces, so the chiseled bookshelf branch reads the block entity instead. The shelf (ShelfBlock: swapping items, powered hotbar swap, drawing items) is not part of this.

Vanilla reference

ChiseledBookShelfBlock.useItemOn, useWithoutItem, addBook, removeBook, getAnalogOutputSignal; ChiseledBookShelfBlockEntity.updateState, canPlaceItem (via ListBackedContainer), getMaxStackSize; SelectableSlotContainer.getHitSlot; HopperBlockEntity.addItem / tryMoveInItem.

Self-check

  • cargo clippy -p horizon-client --all-targets -- -D warnings: clean. rustfmt --edition 2024 on the changed files.
  • Not run in game (not built or launched), so the click, the sounds, the hopper and dropper flows and the comparator are checked by reading vanilla only.
  • No new tests.

🔄 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/2687 **Author:** [@kacpherek](https://github.com/kacpherek) **Created:** 10/27/2026 **Status:** ✅ Merged **Merged:** 10/27/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `feat/shelf-use` --- ### 📝 Commits (2) - [`ff28fd8`](https://github.com/horizon-rust/horizon/commit/ff28fd839036a7c3f88203a428bd6c23a92963f9) Read a chiseled bookshelf's last slot and a shelf's back mask with a comparator - [`2f6d259`](https://github.com/horizon-rust/horizon/commit/2f6d259615028dd45859893d29936db1aa7ec4f5) Put books into a chiseled bookshelf and take them out ### 📊 Changes **8 files changed** (+350 additions, -5 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/src/containers.rs` (+23 -0) 📝 `crates/horizon-client/src/game.rs` (+17 -3) ➕ `crates/horizon-client/src/game/chiseled_bookshelf.rs` (+178 -0) 📝 `crates/horizon-client/src/game/machines.rs` (+54 -1) 📝 `crates/horizon-client/src/save.rs` (+12 -0) 📝 `crates/horizon-world/src/level/data.rs` (+6 -0) 📝 `crates/horizon-world/src/level/interact.rs` (+59 -0) 📝 `crates/horizon-world/src/level/mod.rs` (+1 -1) </details> ### 📄 Description ## What and why Using a chiseled bookshelf did nothing: Horizon kept only its saved data. It is now a block entity (`BlockEntity::ChiseledBookshelf`: six slots and `lastInteractedSlot`, loaded and saved as `Items` and `last_interacted_slot`). - Click a slot with a `#bookshelf_books` item: one book goes in, the insert sound plays (enchanted variant for enchanted books), the used statistic and `item_used_on_block` fire, and the block state's `slot_N_occupied` follows. Click an occupied slot (main hand): the book goes to the inventory, or is dropped when it does not fit, with the pickup sound. A click on an empty slot without a book is consumed, a click off the 3x2 front grid passes. - The slot comes from `SelectableSlotContainer.getHitSlot`, ported as `horizon_world::level::hit_slot`. The same result feeds the world crate's `use_item_on`, so the client's prediction ends the click like the server does (a writable book does not open the editor). - Server thread, `--in-frame` and LAN guests share the use code; the new state reaches clients with the normal block update, and nothing else needs sending (the books are drawn by the state's model, `ChiseledBookShelfBlockEntity` has no update packet). - Hoppers and droppers treat it as a container: books only, one per slot (`canPlaceItem`); the slot whose book came or went updates the state and `lastInteractedSlot`. - The comparator now reads `lastInteractedSlot` from the block entity. - Breaking it still spills its books (the existing `Containers.dropContents` path now reads the live slots). This builds on #2641 (its commit is the first one here): its `shelf_signal` read the saved tag, which a modelled block entity replaces, so the chiseled bookshelf branch reads the block entity instead. The shelf (`ShelfBlock`: swapping items, powered hotbar swap, drawing items) is not part of this. ## Vanilla reference `ChiseledBookShelfBlock.useItemOn`, `useWithoutItem`, `addBook`, `removeBook`, `getAnalogOutputSignal`; `ChiseledBookShelfBlockEntity.updateState`, `canPlaceItem` (via `ListBackedContainer`), `getMaxStackSize`; `SelectableSlotContainer.getHitSlot`; `HopperBlockEntity.addItem` / `tryMoveInItem`. ## Self-check - `cargo clippy -p horizon-client --all-targets -- -D warnings`: clean. `rustfmt --edition 2024` on the changed files. - Not run in game (not built or launched), so the click, the sounds, the hopper and dropper flows and the comparator are checked by reading vanilla only. - No new tests. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-03 04:17:55 +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#4540
No description provided.