Jump to content

Recommended Posts

Posted

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.

Posted

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.

Posted

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));
        }
    }
	
}

 

Posted

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?

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.