Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

[1.7.10]Set Block and Item name based on metadata


grand_mind1
 Share

Recommended Posts

Hi, I'm trying to add some extra wool into the game. I want to set the ItemBlock and Block's name based on what color it is (e.g. Black Wool instead of just Wool). The only way I can think of doing this is to have different unlocalized names for each color, but this seems quite inefficient. Is there a better way I can do this?

Thanks!

Link to comment
Share on other sites

Thanks for your help, but I I've done something wrong. My items are now named "Unnamed" with the following code in my ItemBlock class:

@Override
    public String getItemStackDisplayName(ItemStack itemStack)
    {
        return itemStack.getDisplayName().replace("@", StatCollector.translateToLocal("pandm.color" + itemStack.getItemDamage()));
    }

This is my lang file:

 

 

tile.pandm:BlockModWool.name=Special @ Wool

pandm.color.0=Black
pandm.color.1=Blue
pandm.color.2=Brown
pandm.color.3=Cyan
pandm.color.4=Grey
pandm.color.5=Green
pandm.color.6=Light Blue
pandm.color.7=Lime
pandm.color.8=Magenta
pandm.color.9=Orange
pandm.color.10=Pink
pandm.color.11=Purple
pandm.color.12=Red
pandm.color.13=Silver
pandm.color.14=White
pandm.color.15=Yellow

 

 

Link to comment
Share on other sites

I think you have all missed something very simple,

 

when you register your blocks you you specify a item class to associate with it for itemstacks (the second param)

GameRegistry.registerBlock(woolslab1, MetaItem.class, "woolslab1");

 

here is my meta item class

 

public class MetaItem extends ItemBlockWithMetadata{

public MetaItem(Block blk) {
	super(blk,blk);
}

@Override
public String getUnlocalizedName(ItemStack stack) {
	return getUnlocalizedName()+stack.getItemDamage();
}
}

 

then add the names to the lang file and its done

 

Link to comment
Share on other sites

You could also call translate more than once.

private String[] names={"color.black","color.white", /*...*/};

translate("wool.name") + translate(names [item.getItemDamage ()]);

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

Which is basically what I said, but not limited to the english language. Other languages might have the color behind the "Wool", who knows.

 

Touche.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

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

 Share



×
×
  • Create New...

Important Information

By using this site, you agree to our Privacy Policy.