Security Craft

Security Craft

54M Downloads

[1.12.2 Bug] Sentry Remote Access Tool opens GUI on right-clicking disguised sentry

LorenaGdL opened this issue ยท 2 comments

commented

Even though in the EventsHandler there's already code to handle interaction with disguised sentries, right-clicking a disguised sentry with the SRAT not only binds/unbinds the sentry but it also opens the GUI.

After some testing, it seems the onItemRightClick() method of the SRAT is being called in addition to the onItemUse() one. Although the handler is configured to cancel the onRightClickBlock() event, somehow calls go further down the stack. Might be because the default cancellation result of the event is EnumActionResult.PASS. If the cancellation result is manually set to EnumActionResult.SUCCESS, issue seems to be fixed.

That would be SCEventHandler,java line 392+:

//outside !world.isRemote for properly checking the interaction
//all the sentry functionality for when the sentry is disguised
List<EntitySentry> sentries = world.getEntitiesWithinAABB(EntitySentry.class, new AxisAlignedBB(event.getPos()));

    if(!sentries.isEmpty()){
        event.setCanceled(sentries.get(0).processInteract(event.getEntityPlayer(), event.getHand())); //cancel if an action was taken
        event.setCancellationResult(EnumActionResult.SUCCESS);              
    }

However, I haven't tested thoroughly, and I'm not really sure if setting the cancellation result for all interactions with disguised sentries may cause problems with other items (it doesn't seem so at first sight, but you know your mod better than anyone). Just in case, this version also fixes the issue:

//outside !world.isRemote for properly checking the interaction
//all the sentry functionality for when the sentry is disguised
List<EntitySentry> sentries = world.getEntitiesWithinAABB(EntitySentry.class, new AxisAlignedBB(event.getPos()));

    if(!sentries.isEmpty()){
        if(PlayerUtils.isHoldingItem(event.getEntityPlayer(), SCContent.remoteAccessSentry)) {
            event.setCanceled(true);
            event.setCancellationResult(EnumActionResult.SUCCESS);              
            event.getEntityPlayer().getHeldItemMainhand().getItem().onItemUse(event.getEntityPlayer(), world, event.getPos(), event.getHand(), EnumFacing.NORTH, 0.0f, 0.0f, 0.0f);
        }
        else {
            event.setCanceled(sentries.get(0).processInteract(event.getEntityPlayer(), event.getHand())); //cancel if an action was taken
        }
    }

--
P.S. Happy New Year :)

commented

Oh, sorry. I forgot about this one. Thanks for reminding me. The first fix is less "invasive", as the cancellation result only affects canceled events. My tests don't show anything out of the ordinary so it should be fine.

commented

Ping, in case you wanna take a look at this before next release