Add cancellable Shelf hotbar transfer event(s) to allow per-item filtering (direct, powered, and chained shelves)
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 12.7k
- Forks
- 3.5k
- Avg merge
- 3d 13h
- Merged PRs (30d)
- 11
Description
Is your feature request related to a problem?
Yes. In 1.21.10, interacting with a Shelf can pull items from a player’s hotbar into the Shelf, including when the Shelf is redstone powered and/or part of a side chained group. There is no API to intercept or veto a specific item transfer from the hotbar. PlayerInteractEvent only covers the initial click; the subsequent redstone/chain pulls don’t fire an interact event. Inventory events also don’t fire for this hotbar -> block path. The only hook we can use is PlayerInventorySlotChangeEvent, which is reactive and non cancellable, leading to race conditions (and potential duplication) if we try to “restore” protected items after the fact.
Describe the solution you'd like.
A cancellable, per item event that fires immediately before the Shelf pulls a specific hotbar slot from a player, for both direct interaction and redstone side chained propagation. Example API sketch:
- Event name: PlayerShelfHotbarSwapEvent (Cancellable)
- Package: io.papermc.paper.event.block (or player)
- Fields:
- Player getPlayer()
- Block getShelf() (must be a Shelf)
- int getHotbarSlot() (0–8)
- ItemStack getItem()
- boolean isPoweredChain() (true if caused by redstone/chain rather than the initial click)
- Behavior:
- Fired on the main thread before the transfer.
- Cancelling prevents just that item being pulled (does not cancel the whole shelf interaction/chain).
- Implementations may add a setter to replace the item if that fits Paper’s conventions.
Describe alternatives you've considered.
- Cancelling PlayerInteractEvent: Blocks the entire interaction and forces the plugin to reimplement swapping behavior; does not cover redstone/chain pulls, and is too coarse for per item filtering.
- PlayerInventorySlotChangeEvent: Fires after the slot has already changed and is non cancellable; “restoring” items post facto causes races and potential duplication with chained shelves and delayed redstone.
- InventoryClick/Drag/MoveItem events: Do not fire for this path (player hotbar -> block via Shelf swap).
- Cancelling BlockRedstoneEvent: Far too broad; it disables the whole redstone chain instead of allowing item level filtering.
This event would enable plugins to safely protect or filter specific hotbar items (e.g., a bound tool) without breaking Shelf behavior for all other items and without fighting redstone/chain timing.
Other
No response
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
The issue names no source files or tests; start by tracing the Shelf hotbar transfer path for direct interaction and redstone/side-chain propagation. Define the cancellable per-item event and verify that cancelling one slot prevents only that transfer while leaving other Shelf and chain behavior unchanged.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- api, game-dev
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100