Posted June 24, 201411 yr I have an Item for which I give a maxDamage. I want to make it a durable item where its health decreases everytime you right click it. For some reason the durability doesnt show up. Here is my class minus the imports public class ApplePickingGlove extends CustomItem{ public ApplePickingGlove(){ super(); setUnlocalizedName("Apple Picking Glove"); this.maxStackSize = 1; this.setMaxDamage(20); this.setNoRepair(); } @Override public ItemStack onItemRightClick(ItemStack itemStack, World world, EntityPlayer player) { ItemStack itemstack = player.getCurrentEquippedItem(); if (itemstack != null && itemstack.getItem() == CommonProxy.applePickingGlove){ ItemStack item = new ItemStack(CommonProxy.applePickingGlove, 2, (itemstack.getItemDamage()+1)); if (item.getItemDamage() >= item.getMaxDamage()){ item.stackSize --; } } return itemStack; }
June 24, 201411 yr See that parameter passed in called itemStack? Use that. That is the ItemStack of your item. We all stuff up sometimes... But I seem to be at the bottom of that pot.
June 24, 201411 yr Author I tried @Override public ItemStack onItemRightClick(ItemStack itemStack, World world, EntityPlayer player) { if (itemStack != null && itemStack.getItem() == CommonProxy.applePickingGlove){ itemStack = new ItemStack(CommonProxy.applePickingGlove, 2, (itemStack.getItemDamage()+1)); if (itemStack.getItemDamage() >= itemStack.getMaxDamage()){ itemStack.stackSize --; } } return itemStack; } and still no durability
June 25, 201411 yr And your still doing it wrong... Try this: @Override public ItemStack onItemRightClick(ItemStack itemStack, World world, EntityPlayer player) { if (itemStack != null && itemStack.getItem() == CommonProxy.applePickingGlove){ if (itemStack.getItemDamage() >= itemStack.getMaxDamage()){ } } return itemStack; } We all stuff up sometimes... But I seem to be at the bottom of that pot.
June 25, 201411 yr Author Still no durability shows up when I hit f3 + H and on each right click the durability is not decreasd by 1
June 25, 201411 yr Author This worked But is there another way @Override public ItemStack onItemRightClick(ItemStack itemStack, World world, EntityPlayer player) { if (itemStack != null && itemStack.getItem() == CommonProxy.applePickingGlove){ itemStack.damageItem(1, player); } return itemStack; }
June 25, 201411 yr That is how you are supposed to do it... We all stuff up sometimes... But I seem to be at the bottom of that pot.
June 25, 201411 yr Author The problem with that method is that I cannot change the amount that durability drops by. I want durability of the item to be affected differently depending on which block the item interacts with. Say drop durability by 5 if you right click cobblestone but drop it by 1 if you right click leaves.
June 26, 201411 yr The problem with that method is that I cannot change the amount that durability drops by. I want durability of the item to be affected differently depending on which block the item interacts with. Say drop durability by 5 if you right click cobblestone but drop it by 1 if you right click leaves. What you want is to use onItemUse(). So public boolean onItemUse(ItemStack itemStack, EntityPlayer player, World world, int x, int y, int z, int par7, float par8, float par9, float par10) { Block target = world.getBlock(x, y, z); if (target == Blocks.leaves) { itemStack.damageItem(1, player); else if (target == Blocks.cobblestone) itemStack.damageItem(5, player); } Lead DivineRPG Developer
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.