Posted August 2, 201411 yr I want to say when itemBalloonSword breaks to give new Itemstack itemDeflatedBalloonSword but have no idea how any help would be greatly appreciated.
August 2, 201411 yr Author It's a sword used to kill mobs I need to replace the item once it hits 0 durability or breaks
August 2, 201411 yr 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
August 2, 201411 yr You can try to check if the sword is about to break(only 1 damage left to break) change the item. Probably in onUpdate() method. I think you cannot check if its breaks or hits 0. Although im not sure.
August 2, 201411 yr Author Is there something like getDurability and I can say if it's one to replace the item?
August 2, 201411 yr if(par1ItemStack.getItemDamage() == par1ItemStack.getMaxDamage() - 1){ //Replace item } This should do the trick.
August 2, 201411 yr 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; }
August 2, 201411 yr Author Sorry guys I'm kinda new to this I tried putting it directly in the ballonsword class and it did not work
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.