From 16437eb47cc073d83b3df4a2e3319d6cdd447a34 Mon Sep 17 00:00:00 2001 From: kacimiamine Date: Mon, 13 Jul 2026 16:49:42 +0100 Subject: [PATCH 1/2] Add SulfurCubeSwallowEvent --- .../entity/SulfurCubeSwallowItemEvent.java | 101 ++++++++++++++++++ .../monster/cubemob/SulfurCube.java.patch | 29 +++++ 2 files changed, 130 insertions(+) create mode 100644 paper-api/src/main/java/io/papermc/paper/event/entity/SulfurCubeSwallowItemEvent.java diff --git a/paper-api/src/main/java/io/papermc/paper/event/entity/SulfurCubeSwallowItemEvent.java b/paper-api/src/main/java/io/papermc/paper/event/entity/SulfurCubeSwallowItemEvent.java new file mode 100644 index 000000000000..16b1a60ce2b8 --- /dev/null +++ b/paper-api/src/main/java/io/papermc/paper/event/entity/SulfurCubeSwallowItemEvent.java @@ -0,0 +1,101 @@ +package io.papermc.paper.event.entity; + +import org.bukkit.entity.Player; +import org.bukkit.entity.SulfurCube; +import org.bukkit.event.Cancellable; +import org.bukkit.event.HandlerList; +import org.bukkit.event.entity.EntityEvent; +import org.bukkit.inventory.ItemStack; +import org.jetbrains.annotations.ApiStatus; +import org.jspecify.annotations.NullMarked; + +/** + * Called when a SulfurCube swallows an item + *
+ * If the ItemStack is modified the SulfurCube will swallow the new item + * and not remove the original one from the player's inventory. + *
+ * If the event is cancelled the SulfurCube will not swallow the item and + * it will not be removed from the player's inventory + */ +@NullMarked +public class SulfurCubeSwallowItemEvent extends EntityEvent implements Cancellable { + + private static final HandlerList HANDLER_LIST = new HandlerList(); + + private final Player player; + private final ItemStack oldItem; + private ItemStack newItem; + + private boolean cancelled; + + @ApiStatus.Internal + public SulfurCubeSwallowItemEvent(final SulfurCube sulfurCube, final Player player, final ItemStack oldItem, final ItemStack newItem) { + super(sulfurCube); + this.player = player; + this.oldItem = oldItem; + this.newItem = newItem; + } + + /** + * Gets the player interacting with the SulfurCube. + * + * @return the player that interacted with the SulfurCube + */ + public Player getPlayer() { + return this.player; + } + + /** + * Gets the item that is currently swallowed by the SulfurCube + * + * @return an ItemStack for the item currently swallowed + */ + public ItemStack getOldItem() { + return this.oldItem.clone(); + } + + /** + * Gets the item that is being swallowed. Modifying the returned item will + * have no effect, you must use {@link + * #setNewItem(org.bukkit.inventory.ItemStack)} instead. + * + * @return an ItemStack for the item being swallowed + */ + public ItemStack getNewItem() { + return this.newItem.clone(); + } + + /** + * Set the item being swallowed + * + * @param newItem the item being swallowed + */ + public void setNewItem(ItemStack newItem) { + this.newItem = newItem; + } + + @Override + public SulfurCube getEntity() { + return (SulfurCube) super.getEntity(); + } + + @Override + public boolean isCancelled() { + return this.cancelled; + } + + @Override + public void setCancelled(final boolean cancel) { + this.cancelled = cancel; + } + + @Override + public HandlerList getHandlers() { + return HANDLER_LIST; + } + + public static HandlerList getHandlerList() { + return HANDLER_LIST; + } +} diff --git a/paper-server/patches/sources/net/minecraft/world/entity/monster/cubemob/SulfurCube.java.patch b/paper-server/patches/sources/net/minecraft/world/entity/monster/cubemob/SulfurCube.java.patch index dcbc36966c52..b01e55a522a0 100644 --- a/paper-server/patches/sources/net/minecraft/world/entity/monster/cubemob/SulfurCube.java.patch +++ b/paper-server/patches/sources/net/minecraft/world/entity/monster/cubemob/SulfurCube.java.patch @@ -91,6 +91,35 @@ this.gameEvent(GameEvent.SHEAR, player); heldItem.hurtAndBreak(1, player, hand.asEquipmentSlot()); CriteriaTriggers.PLAYER_SHEARED_EQUIPMENT.trigger((ServerPlayer)player, itemStackToShear, this); +@@ -463,12 +_,26 @@ + + return InteractionResult.SUCCESS; + } else if (isSwallowableItem(heldItem)) { +- boolean itWorked = this.equipItem(heldItem); ++ // Paper start - SulfurCubeSwallowItemEvent ++ org.bukkit.inventory.ItemStack craftSwallowedItem = org.bukkit.craftbukkit.inventory.CraftItemStack.asCraftMirror(this.getItemBySlot(EquipmentSlot.BODY)); ++ org.bukkit.inventory.ItemStack craftHeldItem = org.bukkit.craftbukkit.inventory.CraftItemStack.asCraftMirror(heldItem); ++ io.papermc.paper.event.entity.SulfurCubeSwallowItemEvent event = new io.papermc.paper.event.entity.SulfurCubeSwallowItemEvent( ++ (org.bukkit.entity.SulfurCube) this.getBukkitLivingEntity(), (org.bukkit.entity.Player) player.getBukkitLivingEntity(), craftSwallowedItem, craftHeldItem ++ ); ++ if (!event.callEvent()) { ++ if (player instanceof final ServerPlayer serverPlayer) serverPlayer.containerMenu.forceHeldSlot(hand); ++ return InteractionResult.PASS; ++ } ++ boolean result = craftHeldItem.equals(event.getNewItem()); ++ // Paper end - SulfurCubeSwallowItemEvent ++ boolean itWorked = this.equipItem(result ? heldItem : org.bukkit.craftbukkit.inventory.CraftItemStack.asNMSCopy(event.getNewItem())); // Paper - SulfurCubeSwallowItemEvent + if (itWorked) { +- heldItem.consume(1, player); ++ if (result) heldItem.consume(1, player); // Paper - SulfurCubeSwallowItemEvent + this.gameEvent(GameEvent.ENTITY_INTERACT); + } + ++ if (player instanceof final ServerPlayer serverPlayer) serverPlayer.containerMenu.forceHeldSlot(hand); // Paper - SulfurCubeSwallowItemEvent ++ + return itWorked ? InteractionResult.SUCCESS_SERVER : InteractionResult.PASS; + } else { + return Bucketable.bucketMobPickup(player, hand, this).orElse(super.mobInteract(player, hand)); @@ -525,7 +_,7 @@ if (this.level() instanceof ServerLevel serverLevel) { for (SulfurCubeArchetype.ContactDamage damage : this.contactDamages) { From 9794ee4d4c200b6a6545492e90e288087ba9f2f4 Mon Sep 17 00:00:00 2001 From: kacimiamine Date: Mon, 13 Jul 2026 21:30:01 +0100 Subject: [PATCH 2/2] Fix comments and punctuation --- .../event/entity/SulfurCubeSwallowItemEvent.java | 12 ++++++------ .../entity/monster/cubemob/SulfurCube.java.patch | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/paper-api/src/main/java/io/papermc/paper/event/entity/SulfurCubeSwallowItemEvent.java b/paper-api/src/main/java/io/papermc/paper/event/entity/SulfurCubeSwallowItemEvent.java index 16b1a60ce2b8..633bc669deb2 100644 --- a/paper-api/src/main/java/io/papermc/paper/event/entity/SulfurCubeSwallowItemEvent.java +++ b/paper-api/src/main/java/io/papermc/paper/event/entity/SulfurCubeSwallowItemEvent.java @@ -10,13 +10,13 @@ import org.jspecify.annotations.NullMarked; /** - * Called when a SulfurCube swallows an item - *
- * If the ItemStack is modified the SulfurCube will swallow the new item + * Called when a SulfurCube swallows an item. + *

+ * If the ItemStack is modified, the SulfurCube will swallow the new item * and not remove the original one from the player's inventory. - *
- * If the event is cancelled the SulfurCube will not swallow the item and - * it will not be removed from the player's inventory + *

+ * If the event is cancelled, the SulfurCube will not swallow the item, and + * it will not be removed from the player's inventory. */ @NullMarked public class SulfurCubeSwallowItemEvent extends EntityEvent implements Cancellable { diff --git a/paper-server/patches/sources/net/minecraft/world/entity/monster/cubemob/SulfurCube.java.patch b/paper-server/patches/sources/net/minecraft/world/entity/monster/cubemob/SulfurCube.java.patch index b01e55a522a0..87cf67beb774 100644 --- a/paper-server/patches/sources/net/minecraft/world/entity/monster/cubemob/SulfurCube.java.patch +++ b/paper-server/patches/sources/net/minecraft/world/entity/monster/cubemob/SulfurCube.java.patch @@ -107,8 +107,8 @@ + return InteractionResult.PASS; + } + boolean result = craftHeldItem.equals(event.getNewItem()); -+ // Paper end - SulfurCubeSwallowItemEvent + boolean itWorked = this.equipItem(result ? heldItem : org.bukkit.craftbukkit.inventory.CraftItemStack.asNMSCopy(event.getNewItem())); // Paper - SulfurCubeSwallowItemEvent ++ // Paper end - SulfurCubeSwallowItemEvent if (itWorked) { - heldItem.consume(1, player); + if (result) heldItem.consume(1, player); // Paper - SulfurCubeSwallowItemEvent