juliarn / npc-lib

Asynchronous, high-performance Minecraft NPC library for 1.8-1.21 servers.
MIT License
296 stars 50 forks source link

NPC Interact Event #74

Closed arthurr0 closed 1 year ago

arthurr0 commented 2 years ago

Hi, is there any solution to nullify several times event popup at one click?

derklaro commented 2 years ago

Can you provide more information? I do not understand the problem completely... 🤔

arthurr0 commented 2 years ago

if the player clicks on an NPC, the interact event executes 4 times.

virustotalop commented 2 years ago

If I remember correctly this happens due to the client sending interact packets for the main hand, off hand and maybe other things now I'm not quite sure. I've handled this issue with a debouncer before so that code only gets called once. Not sure if you've solved your issue @arthurr0 but hopefully that clarifies.

SplotyCode commented 1 year ago

On some entities the client will send both interact and interact_at so you will have to check for the action and the hand. grafik

derklaro commented 1 year ago

Note that v3 is already only calling this for INTERACT, so you only need to check if the interact action was made with the main hand to prevent double action. It might be an idea to only call the event if the action was performed with the main hand, although if somewhere in the future minecraft actually starts to differentiate between main and off hand, that could be a missing feature. So leaving the hand in will call the event twice, but simply checking for the hand will prevent any issues like this :)