Paper icon indicating copy to clipboard operation
Paper copied to clipboard

Incorrect properties in PlayerItemConsumeEvent

Open Boy0000 opened this issue 1 year ago • 6 comments

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

  1. Get Item with FoodComponent
  2. 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

Boy0000 avatar Jul 09 '24 20:07 Boy0000

For me getItem() returns what it should, it's getReplacement() that doesn't work properly. Screenshot 2024-07-13 190550 Screenshot 2024-07-13 190612

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"}}]

Nacioszeczek avatar Jul 13 '24 17:07 Nacioszeczek

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

Lulu13022002 avatar Jul 13 '24 17:07 Lulu13022002

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

Nacioszeczek avatar Jul 13 '24 17:07 Nacioszeczek

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

electronicboy avatar Jul 13 '24 19:07 electronicboy

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)

Boy0000 avatar Jul 13 '24 19:07 Boy0000

that only works for a specific case, however, that is generally not how the event has worked for the past few eons

electronicboy avatar Jul 13 '24 19:07 electronicboy

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.

Lulu13022002 avatar Jul 22 '24 13:07 Lulu13022002