FancyMcPlugins / FancyNpcs

FancyNpcs is a simple, lightweight and fast npc plugin using packets
https://modrinth.com/plugin/fancynpcs
MIT License
98 stars 23 forks source link

Improve NPC interactions and extend NpcInteractEvent API #97

Closed Grabsky closed 3 months ago

Grabsky commented 3 months ago
  1. NPC interactions logic has been cleaned-up a bit; this should also fix problem described in #91.
  2. New method has been added: NpcInteractEvent#getInteractionType, which returns: a) NpcInteractEvent.InteractionType.LEFT_CLICK for left-click interactions. b) NpcInteractEvent.InteractionType.RIGHT_CLICK for right-click interactions. c) NpcInteractEvent.InteractionType.CUSTOM for interactions forced by API.

Marked as DRAFT because I have not fully tested these changes yet.

Grabsky commented 3 months ago

Should I also move event logic to PacketReader for version 1.20.1? This should hopefully decrease number of reports by users running outdated version of Paper (or fork), where PlayerUseUnknownEntityEvent#getClickedRelativePosition does not exist.

OakLoaf commented 3 months ago

Should I also move event logic to PacketReader for version 1.20.1? This should hopefully decrease number of reports by users running outdated version of Paper (or fork), where PlayerUseUnknownEntityEvent#getClickedRelativePosition does not exist.

It makes sense to put the logic within the PacketReader as you said

OliverSchlueter commented 3 months ago

I'm fine with both. Up to you, if you want to add a packetreader for 1.20.1 too.

Grabsky commented 3 months ago

Decided NOT to implement PacketReader for version 1.20.1 for following reason:

Addition of the PlayerUseUnknownEntityEvent#getClickedRelativePosition introduced number of internal changes to the ServerboundInteractPacket class and most notably, ServerboundInteractPacket.ActionType class and getActionType method are no longer public, which makes it tricky to handle both in the runtime and compilation-wise.

Other than that, I tested these changes on versions 1.19.4 - 1.20.4 and everything seems to work correctly. Marking as ready for review.