Jump to content

[1.8] Cancel Block Break And Break Animation - ItemSword


EverythingGames
 Share

Recommended Posts

I need to be able to have an item that cannot break any blocks - that can be achieved with events or overriding the Item class' methods. However, the server is still telling the client to render the break animation (the block's break stages), and the client is also still spawning block-break particles. Is there a way to cancel everything before the block is broken (kind of like when the block is first clicked) so that it looks seamless as though the player had not clicked at all? I know ItemSword does this, although I cannot find any place where ItemSword is referenced in the Call Hierarchy (besides where instances of it are created for registration). If someone could please elaborate on how I would get this done, I would appreciate it Thanks.

Development of Plugins [2012 - 2014] Development of Mods [2012 - Current]

Link to comment
Share on other sites

For the client I think you need to go as far back as the MouseEvent to be able to properly cancel everything. That should then be enough already, since the server doesn't even get told about any interaction.

But you could put in a safety check there, using PlayerInteractEvent with LEFT_CLICK_BLOCK.

Link to comment
Share on other sites

Did you look inside the vanilla ItemSword class? It has this method in it (overriding the default behavior in class Item):

 

    public float getStrVsBlock(ItemStack stack, Block block)
    {
        if (block == Blocks.web)
        {
            return 15.0F;
        }
        else
        {
            Material material = block.getMaterial();
            return material != Material.plants && material != Material.vine && material != Material.coral && material != Material.leaves && material != Material.gourd ? 1.0F : 1.5F;
        }
    } 

The debugger is a powerful and necessary tool in any IDE, so learn how to use it. You'll be able to tell us more and get better help here if you investigate your runtime problems in the debugger before posting.

Link to comment
Share on other sites

Did you look inside the vanilla ItemSword class? It has this method in it (overriding the default behavior in class Item):

 

    public float getStrVsBlock(ItemStack stack, Block block)
    {
        if (block == Blocks.web)
        {
            return 15.0F;
        }
        else
        {
            Material material = block.getMaterial();
            return material != Material.plants && material != Material.vine && material != Material.coral && material != Material.leaves && material != Material.gourd ? 1.0F : 1.5F;
        }
    } 

 

This works when you return 0.0F - if you are in survival. My item does not need to be able to interact with blocks (or blocks with inventory / other capabilities on left / right click). diesieben07 gave the perfect solution, MouseEvents. This stops vanilla packets from being sent and rendering / particles from being spawned on the client. Perfect solution, considering the personal MouseListener I wrote for Forge is uninterrupted by canceling vanilla Mouse actions. Thanks for the help.

Development of Plugins [2012 - 2014] Development of Mods [2012 - Current]

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.