feat: add PlayerBundleItemSelectEvent#13898
Conversation
|
This pretty much enables listening for scrolling above an item. Here are some usage examples for this event: rules.mp4item_browser.mp4 |
|
I think it may be better to view this as an inventory event? As then you can instead act on a slot in an inventory so this can be better used in inventory guis. Also, exposing the previous selected slot would be nice. |
|
Inventory event does make more sense as the supertype for this event: PlayerBundleItemSelectEvent now inherits InventoryEvent. Added slot and previous index/item fields. |
|
|
|
I now moved all of the firing logic to the craft event factory; not sure how the logic could have been split up. |
|
I was thinking: would it maybe be a good addition for the event to expose a getSelectionDelta / getScrollDirection method to simplify the GUI scrolling handling? I'm guessing this event will mainly be used for GUI-related stuff anyway. |
| } | ||
|
|
||
| final net.minecraft.world.item.component.BundleContents contents = item.get(net.minecraft.core.component.DataComponents.BUNDLE_CONTENTS); | ||
| if (contents == null || (new net.minecraft.world.item.component.BundleContents.Mutable(contents)).indexIsOutsideAllowedBounds(selectedIndex)) { |
There was a problem hiding this comment.
That's a bit weird to create a new Mutable instance just for this check can you inline this logic.
| * @return the previously selected item | ||
| */ | ||
| public ItemStack getPreviousItem() { | ||
| return this.previousItem; |
There was a problem hiding this comment.
Should clone all the mutable items.
e5e563f to
ff2dbff
Compare
Adds a new event that is called when a player selects an item in a bundle.