Chisels & Bits - For Forge

Chisels & Bits - For Forge

108M Downloads

FR/PR suggestion: Prevent LeftClickBlock event cancellation

Belgabor opened this issue ยท 5 comments

commented

I have an issue in my mod Drawers & Bits (Belgabor/DrawersBits#1) because the left click event handler in C&B cancels all left click events with bits.
Could a way be added to allow blocks to prevent the cancellation?

My suggestion would be something like this:

    @SubscribeEvent
    public void interaction(
            final LeftClickBlock event )
    {
        if ( event.getEntityPlayer() != null && event.getUseItem() != Result.DENY )
        {
            final ItemStack is = event.getItemStack();
            if ( is != null && ( is.getItem() instanceof ItemChisel || is.getItem() instanceof ItemChiseledBit ) )
            {
                if ( event.getWorld().isRemote )
                {
                    // this is called when the player is survival - client side.
                    is.getItem().onBlockStartBreak( is, event.getPos(), event.getEntityPlayer() );
                }

                // cancel all interactions, creative is magic.
                IBlockState state = event.getWorld().getBlockState(event.getPos());
                if (state == null || !(state.getBlock() instanceof AllowBitLeftClick))
                    event.setCanceled( true );
            }
        }
    }

with AllowBitLeftClick being a marker interface defined in the API.

commented

Would un-canceling the event at a lower even priority from your mod work?

This just seems particularly special cased if we added a work around for this I would prefer it work for other barrel type mods as well without having to do an overt amount of effort, or add a C&B dependency.

I'm uncertain what a good solution that would work in that scenario would be however... The simplest would probably be to only cancel on supported blocks, then everything will would go back to normal block breaking.... Might be the best solution from compatibilitys sake.

commented

On further thought I think inspecting the block and only canceling when chiseling can be done makes the most sense, this should resolve your issue, as well as resolve incompatibility issues with other mods as well, and I think that is probably the best result over all.

commented

Sounds great.

commented

I now feel silly. After adding more (unrelated) code it suddenly works with my own handler I had to implement, pretty sure I tested that before posting this and it did not work at that time. I blame solar flares.
Still I think you are correct and this should be fixed =)

commented

If you build the latest commit you should be able to test to make sure that this resolves your issue as well, but I have a good hunch it will since I actually tested it with storage drawers.