Skip to content

feat: add PlayerBundleItemSelectEvent#13898

Open
mrtz6 wants to merge 3 commits into
PaperMC:mainfrom
mrtz6:feature/player-bundle-item-select-event
Open

feat: add PlayerBundleItemSelectEvent#13898
mrtz6 wants to merge 3 commits into
PaperMC:mainfrom
mrtz6:feature/player-bundle-item-select-event

Conversation

@mrtz6
Copy link
Copy Markdown

@mrtz6 mrtz6 commented May 20, 2026

Adds a new event that is called when a player selects an item in a bundle.

@mrtz6 mrtz6 requested a review from a team as a code owner May 20, 2026 20:25
@github-project-automation github-project-automation Bot moved this to Awaiting review in Paper PR Queue May 20, 2026
@mrtz6
Copy link
Copy Markdown
Author

mrtz6 commented May 20, 2026

This pretty much enables listening for scrolling above an item. Here are some usage examples for this event:

rules.mp4
item_browser.mp4

@Owen1212055
Copy link
Copy Markdown
Member

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.

@mrtz6
Copy link
Copy Markdown
Author

mrtz6 commented May 21, 2026

Inventory event does make more sense as the supertype for this event: PlayerBundleItemSelectEvent now inherits InventoryEvent. Added slot and previous index/item fields.

masmc05

This comment was marked as outdated.

@Owen1212055
Copy link
Copy Markdown
Member

Owen1212055 commented May 21, 2026

Can this also be made cancellable Also, move most of this logic to craft event factory.

@mrtz6
Copy link
Copy Markdown
Author

mrtz6 commented May 21, 2026

I now moved all of the firing logic to the craft event factory; not sure how the logic could have been split up.

@mrtz6
Copy link
Copy Markdown
Author

mrtz6 commented May 24, 2026

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.

@Warriorrrr Warriorrrr added type: feature Request for a new Feature. scope: api labels May 26, 2026
}

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)) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a bit weird to create a new Mutable instance just for this check can you inline this logic.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

refactored in bc06319

* @return the previously selected item
*/
public ItemStack getPreviousItem() {
return this.previousItem;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should clone all the mutable items.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done in b894827

@mrtz6 mrtz6 force-pushed the feature/player-bundle-item-select-event branch from e5e563f to ff2dbff Compare May 31, 2026 21:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

scope: api type: feature Request for a new Feature.

Projects

Status: Awaiting review

Development

Successfully merging this pull request may close these issues.

5 participants