Skip to content

feat: add item tracking for Chiseled Bookshelf#368

Open
netcrafts wants to merge 1 commit intoQuiltServerTools:masterfrom
netcrafts:feat/chiseled-bookshelf-tracking
Open

feat: add item tracking for Chiseled Bookshelf#368
netcrafts wants to merge 1 commit intoQuiltServerTools:masterfrom
netcrafts:feat/chiseled-bookshelf-tracking

Conversation

@netcrafts
Copy link
Copy Markdown

What does this change?

Adds item-insert and item-remove action logging for the Chiseled Bookshelf block. When a player places a book into or removes a book from a Chiseled Bookshelf, the action is now logged and fully supports rollback and restore.

Why?

The Chiseled Bookshelf bypasses the standard container menu system — players interact directly with the block face to slot and unslot books, so the existing AbstractContainerMenuMixin never fires for it. This left a gap in logging for a commonly used storage block.

How?

Added ChiseledBookShelfBlockMixin.java, modelled directly on the existing ShelfBlockMixin.java pattern:

  • @Inject into the private static addBook() method, firing ItemInsertCallback after setItem() stores the book
  • @ModifyExpressionValue on removeBook(), capturing the ItemStack returned by removeItem() and firing ItemRemoveCallback

Both hooks only run server-side (guard on level instanceof ServerLevel), matching the pattern used throughout the codebase.

ChiseledBookShelfBlockEntity implements ListBackedContainer extends Container, so rollback and restore work through the existing ItemChangeActionType.getInventory() path with no changes needed.

Testing

Tested on a local Fabric 0.18.4 / Minecraft 1.26.1 server:

  • Inserted a regular book and an enchanted book into a Chiseled Bookshelf — both logged as item-insert
  • Removed both books — both logged as item-remove
  • /ledger rollback range:2 action:item-insert after:10m — books correctly removed from the bookshelf (2 rollback entries logged)
  • Confirmed same actions logged correctly on a Chest for comparison

Known limitation: /ledger preview rollback does not visually reflect Chiseled Bookshelf changes. This is a pre-existing limitation of the preview system — ServerPlayerEntityMixin intercepts ClientboundContainerSetContentPacket, which is not sent for blocks that track slot state via block-state properties rather than a container screen. The same limitation exists for ShelfBlock. Actual rollback and restore work correctly.

Adds item-insert and item-remove logging for ChiseledBookShelfBlock.
Players inserting or removing books from a Chiseled Bookshelf are now
tracked, with full rollback and restore support.

Modelled on the existing ShelfBlockMixin pattern:
- Inject into addBook() after setItem() fires ItemInsertCallback
- ModifyExpressionValue on removeBook() to capture the removed stack
  and fire ItemRemoveCallback

ChiseledBookShelfBlockEntity implements ListBackedContainer extends
Container, so rollback resolves through the existing getInventory()
path in ItemChangeActionType with no additional changes required.

Note: preview rollback has no visual effect on Chiseled Bookshelf —
this is a pre-existing limitation of ServerPlayerEntityMixin which
intercepts ClientboundContainerSetContentPacket, a packet not sent
for blocks using block-state slot properties. The same limitation
exists for ShelfBlock. Actual rollback and restore work correctly.
@netcrafts netcrafts requested a review from a team as a code owner April 5, 2026 22:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant