Jump to content

[Solved]Damaged item names


Naiten

Recommended Posts

I'm making a multiple item, and i managed to set different icons for it, but i'm stuck at names... Here's the code.

package net.railowar.src;

import java.util.List;

import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.client.renderer.texture.IconRegister;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.Icon;
import net.minecraft.util.MathHelper;
import net.minecraft.world.World;

public class ItemWideRails extends Item
{
    public static final String[] wNames = new String[] {"Straight", "Right", "Left", "S", "Z"};
    public static final String[] wTex = new String[] {"rails", "rails_r", "rails_l", "rails_s", "rails_z"};
    @SideOnly(Side.CLIENT)
    private Icon[] ico;
    
    public ItemWideRails(int par1)
    {
        super(par1);
        this.setHasSubtypes(true);
        this.setMaxDamage(0);
        this.maxStackSize = 1;
        setCreativeTab(CreativeTabs.tabTransport);
        setUnlocalizedName("Rails");
    }
    
    @SideOnly(Side.CLIENT)
    public Icon getIconFromDamage(int par1)
    {
        int j = MathHelper.clamp_int(par1, 0, 4);
        return this.ico[j];
    }

    public String getUnlocalizedName(ItemStack par1ItemStack)
    {
        int i = MathHelper.clamp_int(par1ItemStack.getItemDamage(), 0, 4);
        return super.getUnlocalizedName() + "." + wNames[i];
    }

@SideOnly(Side.CLIENT)
public void getSubItems(int par1, CreativeTabs par2CreativeTabs, List par3List)
    {
        for (int j = 0; j < 5; ++j)
        {
            par3List.add(new ItemStack(par1, 1, j));
        }
    }

    @SideOnly(Side.CLIENT)
    public void updateIcons(IconRegister par1IconRegister)
    {
        this.ico = new Icon[wTex.length];
        for (int i = 0; i < wTex.length; ++i)
        {
            this.ico[i] = par1IconRegister.registerIcon("RoW:" + wTex[i]);
        }
    }
}

Please, help.

If i helped you, don't forget pressing "Thank You" button. Thanks for your time.

Link to comment
Share on other sites

In your item constructor, put:

 

LanguageRegistry.addName(this, "Your Item Name Here");

 

EDIT: Ah, wait, I missed a word - let me get back to you on this.

 

EDIT 2: Check this out - it looks like you need to pass in the names one at a time while also passing in an ItemStack with the desired damage value:

http://www.minecraftforge.net/wiki/Metadata_Based_Subblocks#Block_and_Language_Registration

Link to comment
Share on other sites

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.