Paper
Paper copied to clipboard
Incorrect properties in PlayerItemConsumeEvent
Expected behavior
PlayerItemConsumeEvent#getItem should return the ItemStack that was consumed PlayerItemConsumeEvent#getReplacement should by default return the FoodComponent#getUsingConvertsTo ItemStack
Observed/Actual behavior
PlayerItemConsumeEvent#getItem returns the FoodComponent#getUsingConvertsTo PlayerItemConsumeEvent#getReplacement returns null
Steps/models to reproduce
- Get Item with FoodComponent
- Eat it whilst listening to PlayerConsumeItemEvent
https://github.com/PaperMC/Paper/assets/62521371/4e601f9a-30d0-4d2e-8a22-4aab2132c6ad
Plugin and Datapack List
[22:44:59 INFO]: Server Plugins (5):
[22:44:59 INFO]: Bukkit Plugins:
[22:44:59 INFO]: - HMCColor, LuckPerms, Oraxen, PlaceholderAPI, ProtocolLib
> datapack list
[22:45:13 INFO]: There are 4 data pack(s) enabled: [vanilla (built-in)], [file/bukkit (world)], [file/oraxen_custom_armor (world)], [paper (built-in)]
[22:45:13 INFO]: There are no more data packs available
Paper version
> version
[22:45:27 INFO]: Checking version, please wait...
[22:45:27 INFO]: This server is running Paper version 1.21-38-master@1f5db50 (2024-06-27T20:15:58Z) (Implementing API version 1.21-R0.1-SNAPSHOT)
You are 11 version(s) behind
Download the new version at: https://papermc.io/downloads/paper
Previous version: git-Paper-430 (MC: 1.20.4)
Other
No response
For me getItem() returns what it should, it's getReplacement() that doesn't work properly.
Eatable grass block to test:
/give @s minecraft:grass_block[minecraft:food={nutrition:0,saturation:0,can_always_eat:true,using_converts_to:{id:"minecraft:dirt"}}]
Those two are not really equivalent however using_convert_to will add a new item once the food is consumed setReplacement will override the whole stack with the new stack and work in creative mode too
There's still a weird case, where if you set a replacement, eat the grass block with only 1 in hand, it gets replaced, with 2 or more in hand it gets both replaced and a dirt is added
the event fires before all of the logic is ran, so the replacement can't be prepopulated is the dealio, IIRC, so, that's sadly a WAI
You can definetly pre-populate the getReplacement by reading for a food component on the item. But yeah i was considering whether replacement in the event was too different than usingConvertsTo, and it seems so. Since its handling the entire stack (though it does feel pointless due to usingConvertsTo covering every scenario i can see being useful)
that only works for a specific case, however, that is generally not how the event has worked for the past few eons
Closing this one since it's not doable and doing that would result in breaking the food component. Plugins are still free to mess with the two values if they want.