Paper
Paper copied to clipboard
Add InteractionResult API
Exposes the InteractionResult API to Paper. Allows certain events to create "overrides" for the returned InteractionResult where the event is called. Allows plugin devs to use a more specific approach to handling the return value of the event without directly canceling it.
The enum InteractionResult in io.papermc.paper.world.interaction.InteractionResult has the following Enum Values:
- SUCCESS
- SUCCESS_NO_ITEM_USED
- CONSUME
- CONSUME_PARTIAL
- PASS
- FAIL
The override of the InteractionResult will only occur when the event isn't canceled. Getters inside the events modified return null for when no override is present.
I'll be fixing the paper-api test later today. Also planning on one last sweep to make sure that I got all the events I can
Can you lay out some functionality this adds to the API? Like what is possible with this that is new?
Modifying the result/return value of those methods allows to define what happens to the item and/or entity, and the client. For example:
Overriding the InteractionResult with the new API to SUCCESS would make it so the client swings its arm, instead of SUCCESS_NO_ITEM_USED which would still return a success but without swinging the arm. PASS would make it do nothing, FAIL would make it cancel whatever it's doing, etc. Its basically to add more detail to the interaction-based events. CONSUME iirc consumes the entire stack, and CONSUME_PARTIAL will only consume 1 of the item(if the stack has a higher amt value of 1).
Doesn't the Java client run these checks on its own too? Specifically, when deciding whether to swing the arm or not.. that's how the offhand functionality works, by checking the interactionresult of both hands, and seeing which of them would result in what
This generally looks inherently dangerous in the long run, and fairly bad in the short term
You have no idea what the actual interaction result from the event is, and so you're generally going to have to emulate these interactions in order to determine what will happen to safely know if you can return such a result without having wider implications
I can add getters for the InteractionResults, however I've been quite busy lately so it will be a while