Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FR/PR suggestion: Prevent LeftClickBlock event cancellation #93

Closed
Belgabor opened this issue Jul 19, 2016 · 5 comments
Closed

FR/PR suggestion: Prevent LeftClickBlock event cancellation #93

Belgabor opened this issue Jul 19, 2016 · 5 comments
Labels

Comments

@Belgabor
Copy link

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.

@AlgorithmX2
Copy link
Collaborator

AlgorithmX2 commented Jul 19, 2016

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.

@AlgorithmX2
Copy link
Collaborator

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.

@Belgabor
Copy link
Author

Sounds great.

@Belgabor
Copy link
Author

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 =)

@AlgorithmX2
Copy link
Collaborator

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants