Jump to content

1.7.2 How would I return if a tool just broke?


Overmyer2013

Recommended Posts

Guest Abrynos

I got the same problem with another item. on certain events the item gets damaged and when the the durability is 0 i want to remove the item, but i have no idea how to do that

Link to comment
Share on other sites

You should note that sometimes, durability reduces by two, such as when you break a block with the sword, you can overcome this by overriding onBlockDestroyed with the same code in ItemSword, but you replace the item once the durability hits getMaxDurability - 2 instead of damaging the ItemStack. Like so:

 

@Override
public boolean onBlockDestroyed(ItemStack stack, World world, Block block, int x, int y, int z, EntityLivingBase entity) {
    if ((double)block.getBlockHardness(world, x, y, z) != 0.0D)
    {
        if (stack.getItemDamage() == stack.getMaxDamage() - 2) {
              // replace item and return true
        }
        stack.damageItem(2, entity);
    }
    return true;
}

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
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
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.

Announcements



×
×
  • Create New...

Important Information

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