npc-lib
npc-lib copied to clipboard
NPC Interact Event
Hi, is there any solution to nullify several times event popup at one click?
Can you provide more information? I do not understand the problem completely... 🤔
if the player clicks on an NPC, the interact event executes 4 times.
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.
On some entities the client will send both interact and interact_at so you will have to check for the action and the hand.
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 :)