-
Bug
-
Resolution: Unresolved
-
Minor
-
None
-
None
-
CraftBukkit version 3655-Spigot-19641c7-8ba5e39 (MC: 1.19.3) (Implementing API version 1.19.3-R0.1-SNAPSHOT)
-
Yes
PlayerItemConsumeEvent claims the following:
> 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.
However, when using PlayerItemConsumeEvent#setItem(), two things happens:
First, the effects of the new item are applied, if any. If the new item does not affect hunger (eg: a potion), the old item's hunger change will appear to take effect, but in actuality no change in hunger will be applied. If the new item does affect hunger when consumed, the hunger change works as intended.
Secondly, the old itemstack is replaced by what seems to be the resulting item from consuming the new item.
- If the new item is something fully consumable like steak, or golden apples, the old itemstack will be replaced with air.
- If the new item is consumable but has a byproduct, like potions or beetroot soup, the old itemstack will be replaced by the byproduct. Note that in creative mode, the byproduct is always just the new item.
- If the new item isn't consumable, the old itemstack will be replaced by the new item.
I'd like to see the effects of changing the itemstack be consistent with what the documentation claims will happen, eg: not affect the player's inventory at all, replace all effects, and not give ghost hunger bars.
Here's the code I used to test: (plugin and source code attached, built with Material.STONE)
@EventHandler public void onConsume(PlayerItemConsumeEvent event) { LOGGER.info("Initial item: " + event.getItem()); ItemStack item = new ItemStack(Material.GOLDEN_APPLE); LOGGER.info("Set to: " + item); event.setItem(item); LOGGER.info("New item: " + event.getItem()); }
I tried golden apples, stone, beetroot soup, and potion as the items.
Logs and videos are here: https://imgur.com/a/iRiShuJ