SpongePowered / SpongeAPI

A Minecraft plugin API
http://www.spongepowered.org/
MIT License
1.14k stars 342 forks source link

InteractItemEvent provides a snapshot instead the real ItemStack #1780

Open Eufranio opened 6 years ago

Eufranio commented 6 years ago

When we are listening to InteractItemEvents, we're probably expecting to do something with the ItemStack in use. In the current API, the event only provides a ItemStackSnapshot, so we cannot modify the ItemStack. An workaround would be getting the item in the hand of the player, but there's another problem where the interact may still have an ItemStack, but wasn't directly caused by a player.

I vote for add a new getter for the real ItemStack in the event, or change the return of the current getItemStack to the real ItemStack. Other than that, I don't really see the point of getting only a copy of the stack.

Faithcaio commented 6 years ago

With an ItemStack you cannot change the type. So probably a setter is better here.

Eufranio commented 6 years ago

So, if we want to simply decrease the stack size for example, we'd do event.setItemStack(event.getItemStack().setStackSize(event.getItemStack().getStackSize() - 1))?

ryantheleach commented 6 years ago

Maybe something like this method?

https://github.com/SpongePowered/SpongeAPI/blob/a4aaeec0007ebd9c3570e41382454e81f875e0a1/src/main/java/org/spongepowered/api/event/block/InteractBlockEvent.java#L92-L106

Eufranio commented 6 years ago

hum?