CraftTweaker

CraftTweaker

186M Downloads

onPlayerRightClickItem runs twice when looking at a block

CalaMariGold opened this issue ยท 7 comments

commented

Issue description

events.onPlayerRightClickItem(function(event as crafttweaker.event.PlayerRightClickItemEvent){
    if(!event.world.isRemote()){
        server.commandManager.executeCommand(server, "say test");
    }
});

test will output twice but only when looking at a block.

Steps to reproduce

see desc

Script used

see desc

The crafttweaker.log file

see desc

Minecraft version

1.12

Modloader

Forge

Modloader version

14.23.5.2860

CraftTweaker version

4.1.20.703

Other relevant information

No response

The latest.log file

see desc

commented

The event is being fired for both the main hand, and the offhand, you can get the current hand using event.hand, and check if it is main_hand or off_hand, these strings may not be correct, it has been a while since i did 1.12, so do println(event.hand); to check what it actually is.

commented

@jaredlll08 I tried that as well. It still fires twice when looking at a block.

events.onPlayerRightClickItem(function(event as crafttweaker.event.PlayerRightClickItemEvent){
    if(!event.world.isRemote()){
        if(event.hand == "MAIN_HAND"){
            server.commandManager.executeCommand(server, "say test");
        }
    }
});
commented

Is that what was meant by checking for hand? I don't believe it has to do with offhand/main hand as it only happens when looking at a block.

commented

That is what I meant when I said check the hand.

According to the forge docs on the event:

Note that this is NOT fired if the player is targeting a block {@link RightClickBlock} or entity {@link EntityInteract} {@link EntityInteractSpecific}.

Your event shouldn't even be firing if you are hovering over a block, do you happen to have a PlayerRightClickBlock event by chance?

commented

I do, but it doesn't run without a specific item in hand. This issue only occurs when I have the right click item event in my code.

Does seem a bit strange that the docs say it shouldn't even fire at all, I don't think that should be intended behavior. How would a player know they need to be looking at air to right click items?

commented

remove all your scripts besides the one that does the right click item event handler and see if it still happens, if it does, then there is nothing you nor I can do, it is a bug with forge

commented

Tracked down the issue being due to Immersive Combat re-posting the RightClick event. Apologies for the report!