Jump to content

[UNSOLVED] Language registry does not accept metadata for blocks


Recommended Posts

Thanks in advance for any help.


I'm trying to register a name for my block for each of it's metadatas. (Similar to wool)

I'm following the tutorial on the wiki http://www.minecraftforge.net/wiki/Metadata_Based_Subblocks, but can't seem to get past adding names for metadatas on a block.


in ModMymod.java

LanguageRegistry.addName(new ItemStack(multiBlock, 1, 0), "block zero");
LanguageRegistry.addName(new ItemStack(multiBlock, 1, 1), "block one");
LanguageRegistry.addName(new ItemStack(multiBlock, 1, 2), "block two");
GameRegistry.registerBlock(multiBlock, "mymod.multiblock");


However, addName refuses to accept an ItemStack of Blocks. I looked into the code for addName, and I believe the problem is due to it trying to return an Item from the ItemStack, and not checking for Blocks.


in LanguageRegistery.java

public void addNameForObject(Object objectToName, String lang, String name)
    String objectName;
    if (objectToName instanceof Item) {
    } else if (objectToName instanceof Block) {
    } else if (objectToName instanceof ItemStack) {
        objectName=((ItemStack)objectToName).getItem().getUnlocalizedName((ItemStack)objectToName); <-------- DOES NOT CHECK FOR BLOCKS
    } else {
        throw new IllegalArgumentException(String.format("Illegal object for naming %s",objectToName));
    addStringLocalization(objectName, lang, name);

public static void addName(Object objectToName, String name)
    instance().addNameForObject(objectToName, "en_US", name);


I tried to find how vanilla minecraft implements it for wool/cloth blocks, but to no success.

Link to comment
Share on other sites

I tested to see if .getItem() for an ItemStack of Blocks returns null, and it does.


ItemStack is = new ItemStack(block_multi, 1, 0);


Prints "null."


This tutorial should point you in the right direction:




It may say it is for 1.5.x, but it has been working for me on forge build 758


I checked the tutorial, and it looks like it has some sort of ItemBlock to fill that null in. I'll check it to see if it fixes the problem.

Link to comment
Share on other sites

your item must return different strings from getUnlocalizedName or language registry can't tell your items apart and see them as one item. if you have a block with different IDs and you want to have it different titles you have to implement your own ItemBlock.


to ItemStack of "blocks" - it's never a block, it's always an instance of an Item class, usually ItemBlock class (or its child).


mnn.getNativeLang() != English

If I helped you please click on the "thank you" button.

Link to comment
Share on other sites

  • 2 months later...

I have an answer for you. This is strait for my code and works for me



    		for(int count = 0 ;count < wanditem.WandCount; count++)
    			String tempName = wanditem.subNames[count] + " wand";



Link to comment
Share on other sites

This is how I got mine to work




private static final String[] urotarkItemNames = { "Urotark", "Pearl", "Sapphire", "Muscovite", "Ruby", "Uriotyke", "Gilder", "Selovar", "Parfilian", "Barium", "Radium", "Gallum", "Vanadium", "Scandium", "Bismuth", "Indium" };


    public static void setNames(LanguageRegistry registry) {


// the the 16 is the amount of metadatas there are in this case there are 16

        for (int ix = 0; ix < 16; ix++) {

            // meta set 1

            ItemStack urotarkitemStack = new ItemStack(urotark, 1, ix);

            LanguageRegistry.addName(urotarkitemStack, urotarkItemNames[urotarkitemStack.getItemDamage()]);




if (You.likescoding == false){

Link to comment
Share on other sites

Some o' my code:

(and if someone yells at me for this not being right, it's what vanilla uses.)



Item Class:

public static final String[] Names = new String[] {"earth", "water", "fire", "air"};
public String getUnlocalizedName(ItemStack par1ItemStack)
        int i = MathHelper.clamp_int(par1ItemStack.getItemDamage(), 0, itemNumberDamage);
        return super.getUnlocalizedName() + "." + Names[i];

Where itemNumberDamage = Highest damage value used



Main class:

baseElements = new BaseElementsArray(baseElementsID).setUnlocalizedName("baseElements").setCreativeTab(tabElements);
public void loadPre(FMLPreInitializationEvent event) {
LanguageRegistry.addStringLocalization("item.baseElements.earth.name", "en_us", "Earth");
LanguageRegistry.addStringLocalization("item.baseElements.wind.name", "en_us", "Wind");
LanguageRegistry.addStringLocalization("item.baseElements.fire.name", "en_us", "Fire");
LanguageRegistry.addStringLocalization("item.baseElements.air.name", "en_us", "Air");

Uses "item.(what you have in setUnlocalizedName).(a string from the string array).name"

Legend of Zelda Mod[updated September 20th to 3.1.1]

Extra Achievements(Minecraft 1.8!)[updated April 3rd to 2.3.0]

Fancy Cheeses[updated May 8th to 0.5.0]

Link to comment
Share on other sites

As mentioned above, it's much simpler to use an array. The way I handle it is to use the mod name as part of the registration process:


// Define the names for our metadata. Remember, each item is limited to 16 meta blocks

private static final String[] metaBlockNames = {
  "First Block", "Second Block", "Third Block", "Fourth Block"

private static final String modName = "MyMod";
public static Block myBlock;
private static int blockID;  // this gets read in from the config

public void modLoad(FMLInitializationEvent event)
    // Create an instance of our block and register it

    myBlock = new BlockMyBlock(blockID).setUnlocalizedName("myblockBlock");
    GameRegistry.registerBlock(myBlock, ItemBlockMyBlock.class, myBlock.getUnlocalizedName2());

    // Register the different meta blocks

    for (int a = 0; a < metaBlockNames.length; x++)
        LanguageRegistry.addName(new ItemStack(myBlock, 1, a), modName + metaBlockNames[a]);


protected String getModName()
    // Provides access to the mod name for use in sub classes such 
    // such as BlockMyBlock for regestering Icons

    return modName;

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.

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.


  • Create New...

Important Information

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