Skip to content

Add SulfurCubeSwallowEvent#14061

Open
kacimiamine wants to merge 2 commits into
PaperMC:mainfrom
kacimiamine:feat/sulfurcube-swallow-event
Open

Add SulfurCubeSwallowEvent#14061
kacimiamine wants to merge 2 commits into
PaperMC:mainfrom
kacimiamine:feat/sulfurcube-swallow-event

Conversation

@kacimiamine

Copy link
Copy Markdown

Add a new event to the sulfur cube swallowing an item after the player interaction.

@kacimiamine kacimiamine requested a review from a team as a code owner July 13, 2026 15:52
@github-project-automation github-project-automation Bot moved this to Awaiting review in Paper PR Queue Jul 13, 2026

@Strokkur424 Strokkur424 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I generally like the QoL this event provides. For anyone following along, with PlayerInteractAtEntityEvent, replacing the cube's contained item on interact can be done like so:

@EventHandler
void onInteractWithSulfurCube(PlayerInteractAtEntityEvent event) {
    if (!(event.getRightClicked() instanceof SulfurCube cube)) {
        return;
    }

    ItemStack is = event.getPlayer().getInventory().getItemInMainHand();
    if (is.getType().asItemType() == ItemType.SHEARS) {
        return;
    }

    if (!cube.getEquipment().getItem(EquipmentSlot.BODY).isEmpty()) {
        return;
    }

    event.setCancelled(true);
    cube.getEquipment().setItem(EquipmentSlot.BODY, ItemType.BIRCH_LOG.createItemStack());
    event.getPlayer().swingMainHand();
}

With this new event, that is simplified to just this:

@EventHandler
void onSulfurCubeSwallowItem(SulfurCubeSwallowItemEvent event) {
    event.setNewItem(ItemType.BIRCH_LOG.createItemStack());
}

Generally, a lot of entity interaction stuff is left just as a generic PlayerInteractAtEntityEvent. But in this case I'd argue there are enough lines saved and logical edge-cases (like that top version does not handle the small sulfur cubes not being allowed to swallow items normally) for this event to make sense.

The way it is integrated with NMS code also makes complete sense, for this reason I approve.

@kacimiamine

Copy link
Copy Markdown
Author

The punctuation and comments should be all resolved now

@kacimiamine kacimiamine force-pushed the feat/sulfurcube-swallow-event branch from d00ce24 to 9794ee4 Compare July 16, 2026 10:01
@kennytv

kennytv commented Jul 16, 2026

Copy link
Copy Markdown
Member

Not consuming the original item based on the setter feels weird, that should either just be removed or be a separate method in the event (unless there's many existing events doing the same, but I couldn't think of any)

@kacimiamine

Copy link
Copy Markdown
Author

iirc that's what PlayerItemConsumeEvent does, it doesn't remove the original item if you change it with the setter as said in the javadocs

This event will fire when a player is finishing consuming an item (food, potion, milk bucket).
If the ItemStack is modified the server will use the effects of the new item and not remove the original one from the player's inventory.
If the event is cancelled the effect will not be applied and the item will not be removed from the player's inventory.

@kacimiamine

Copy link
Copy Markdown
Author

I mean both of the implementations will feel weird; removing the item even if it was changed sounds weird since it doesn't use the original item so why remove it? But also not removing feels like something where players could just click on every sulfur cube which is weird too...

I guess it's between choosing what is more appropriate and feels less weird

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Awaiting review

Development

Successfully merging this pull request may close these issues.

3 participants