Posted July 2, 20178 yr Hello again, I have a tool that i would like to change the name of as it gets damaged. I have tried overriding getUnlocalizeName but that does not give the expected results, it always gives the unlocalized name for the item with 0 damage. So my question is how can i accomplish this.
July 2, 20178 yr Please show your item code. Overriding "getUnlocalizedName" is the correct way to change the name, so your code must be doing something wrong.
July 7, 20178 yr Author Sorry for the delay i took a short break from modding. Here is the code i use: @Override public String getUnlocalizedName(ItemStack stack) { return "item." + this.getRegistryName().getResourcePath() + "_" + (stack.getMetadata() % 25); } But it is always the same unlocalized name.
July 7, 20178 yr Author Here is the full item class. And i did not know that could be a problem so i will fix it ASAP. package net.drok.poverhaul.item; import javax.annotation.Nullable; import net.drok.poverhaul.POHMod; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.entity.EntityLivingBase; import net.minecraft.item.IItemPropertyGetter; import net.minecraft.item.Item; import net.minecraft.item.ItemElytra; import net.minecraft.item.ItemStack; import net.minecraft.util.NonNullList; import net.minecraft.util.ResourceLocation; import net.minecraft.world.World; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; public class ItemRock extends Item { public ItemRock() { this.setRegistryName(new ResourceLocation(POHMod.MODID, "rock")); this.setHasSubtypes(true); this.setMaxDamage(110); this.addPropertyOverride(new ResourceLocation("sharpness"), new IItemPropertyGetter() { @SideOnly(Side.CLIENT) public float apply(ItemStack stack, @Nullable World worldIn, @Nullable EntityLivingBase entityIn) { return stack.getMetadata(); } }); } @Override public boolean showDurabilityBar(ItemStack stack) { return true; } @Override public String getUnlocalizedName(ItemStack stack) { return "item." + this.getRegistryName().getResourcePath() + "_" + (stack.getMetadata() % 25); } @SideOnly(Side.CLIENT) public void getSubItems(CreativeTabs tab, NonNullList<ItemStack> items) { if (this.isInCreativeTab(tab)) { items.add(new ItemStack(this, 1, 0)); items.add(new ItemStack(this, 1, 25)); items.add(new ItemStack(this, 1, 50)); items.add(new ItemStack(this, 1, 100)); } } }
July 7, 20178 yr Author Hmm it seems that the two lines of code i tested both return 0 even though the item is clearly damaged ingame. I used: stack.getMetadata() and stack.getItemDamage() Is this not the proper way of getting how damaged the item is?
July 7, 20178 yr Author Ok the max stack size is 1 but both methods still return zero no matter what.
July 7, 20178 yr Author Ugh nevermind im an idiot it works i just didnt realize that i needed to spawn in new items for it to update. Thank you for all the help!
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.