onPlayerInteractBlock fires 4 times instead of just 1
Keaft opened this issue ยท 1 comments
Issue description
It would appear that the onPlayerInteractBlock event fires 4 times on a single right click. The script below is enough to reproduce the effect.
Steps to reproduce
Load up an instance of 1.12.2 on the latest forge and crafttweaker with the script and right click any block once.
Script used
https://gist.github.com/Keaft/9d516ffcddb04bbfae31f6a128fd2c1d
The crafttweaker.log file
https://gist.github.com/Keaft/b9b3232bb965c86c38e4e41bea48c709
Minecraft version
1.12
Modloader
Forge
Modloader version
14.23.5.2860
CraftTweaker version
1.12-4.1.20.687
Other relevant information
No response
The latest.log file
https://gist.github.com/Keaft/ab20a39d1db78e7628bfe88fc958d28c
This is normal, Forge fires the event 4 times like so (not in this exact order):
- Once on the
server
for themain_hand
- Once on the
server
for theoff_hand
- Once on the
client
for themain_hand
- Once on the
client
for theoff_hand
The "solution" to make it only fire once is to do:
import crafttweaker.event.PlayerInteractBlockEvent;
events.onPlayerInteractBlock(function(event as PlayerInteractBlockEvent){
if(event.world.remote || event.hand == "off_hand") {
return; // If it is on the client or the off_hand, do not continue.
}
event.player.sendChat("Hello I'm firing!");
});