Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

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.

  • 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.

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

 

  • 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?

  • 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.

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...

Important Information

By using this site, you agree to our Terms of Use.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.