Posted February 16, 201411 yr I have an item that takes damage when held. The only problem it bounces up and down and that dosen't look so cool. [spoiler=My item code:] package fluffy.lantern.items; import net.minecraft.client.renderer.texture.IconRegister; import net.minecraft.entity.Entity; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemReed; import net.minecraft.item.ItemStack; import net.minecraft.world.World; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import fluffy.lantern.Lantern; import fluffy.lantern.handler.TickHandler; public class ItemCandleLanternon extends ItemReed{ public ItemCandleLanternon(int id) { super(id, Lantern.lanternOn); this.canRepair = false; this.setMaxDamage(Lantern.lanternFuelCapacity); } public int getItemStackLimit() { return 1; } public boolean isItemTool(ItemStack ist) { return false; } public void onUpdate(ItemStack par1ItemStack, World par2World, Entity par3Entity, int par4, boolean par5) { if (!par2World.isRemote) { int damage = par1ItemStack.getItemDamage(); EntityPlayer player = (EntityPlayer)par3Entity; if (!player.capabilities.isCreativeMode && (player.getCurrentEquippedItem() != null && player.getCurrentEquippedItem().itemID == par1ItemStack.itemID)){ if (damage >= this.getMaxDamage()) { this.killItemLantern(par2World, player, par1ItemStack); return; }else{ par1ItemStack.setItemDamage(damage + 1); } } } super.onUpdate(par1ItemStack, par2World, par3Entity, par4, par5); } private void killItemLantern(World world, EntityPlayer p, ItemStack ist) { world.playSoundAtEntity(p, "fluffy:Lanternoff", 0.7F, 1F); ist.setItemDamage(this.getMaxDamage()); ist.itemID = Lantern.lanternoffItem.itemID; } @SideOnly(Side.CLIENT) public void registerIcons(IconRegister icon) { this.itemIcon = icon.registerIcon("Fluffy:Lanternon"); } }
February 16, 201411 yr Don't use the item's damage field to store constantly changing data; use the ItemStack's NBT instead. http://i.imgur.com/NdrFdld.png[/img]
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.