Jump to content

Recommended Posts

Posted

When viewed in-game, they show as 'tile.MultiBlock_UN.name'.

Here is the code for my Block:

 

public class MultiBlock extends Block{
public static final String[] blockNames = new String[] {"knowledgeBlock", "ulGemBlock", "redGemBlock", "blueGemBlock", "farmObsidian"};
public static final String[] blockTextureNames = new String[] {"knowledge", "gemBlock", "redGemBlock", "blueGemBlock", "FarmObsidian"};
@SideOnly(Side.CLIENT)
private Icon[] block_b;
public MultiBlock(int par1, Material par2Material) {
	super(par1, par2Material);
	this.setCreativeTab(unbase.TabUnLogic);
	this.setUnlocalizedName("MultiBlock_UN");
}
//Start Multi-Block and Texture code
	/**
     * Gets the block's texture. Args: side, meta
     */
	@Override
    @SideOnly(Side.CLIENT)
    public Icon getIcon(int p_149691_1_, int p_149691_2_)
    {
        if (p_149691_2_ < 0 || p_149691_2_ >= this.block_b.length)
        {
            p_149691_2_ = 0;
        }

        return this.block_b[p_149691_2_];
    }

    /**
     * Determines the damage on the item the block drops. Used in cloth and wood.
     */
	@Override
    public int damageDropped(int p_149692_1_)
    {
        return p_149692_1_;
    }

    /**
     * returns a list of blocks with the same ID, but different meta (eg: wood returns 6 blocks)
     */
	@Override
    @SideOnly(Side.CLIENT)
    public void getSubBlocks(int p_149666_1_, CreativeTabs p_149666_2_, List p_149666_3_)
    {
        p_149666_3_.add(new ItemStack(p_149666_1_, 1, 0));
        p_149666_3_.add(new ItemStack(p_149666_1_, 1, 1));
        p_149666_3_.add(new ItemStack(p_149666_1_, 1, 2));
        p_149666_3_.add(new ItemStack(p_149666_1_, 1, 3));
    }

	@Override
    @SideOnly(Side.CLIENT)
    public void registerIcons(IconRegister p_149651_1_)
    {
        this.block_b = new Icon[blockTextureNames.length];

        for (int i = 0; i < this.block_b.length; ++i)
        {
            this.block_b[i] = p_149651_1_.registerIcon("unlogic:" + blockTextureNames[i]);
        }
    }
	//End Multi-Block Code
}

 

And the code for my ItemBlock:

 

public class MultiBlockItem extends ItemBlock{

public MultiBlockItem(int par1) {
	super(par1);
        this.setMaxDamage(0); //Stops bad things from happening
        this.setHasSubtypes(true); //Tells it that it has metadata versions
}
@SideOnly(Side.CLIENT)
public Icon getIconFromDamage(int par1) //Gets the texture
{
	return null;
}
public int getMetadata(int par1) //Returns the metadata value
{
         return par1;
}
public String getItemNameIS(ItemStack is) //Gets the item incode name from an itemstack
{
         String[] types = {"knowledgeBlock", "ulGemBlock", "redGemBlock", "blueGemBlock", "farmObsidian"};
         return "MultiBlock" + types[is.getItemDamage()];
}
}

 

And the code for registering the names in the Language Registry:

 

                LanguageRegistry.instance().addStringLocalization("tile.MultiBlock_UN.knowledgeBlock.name", "en_US", "Solidified Knowledge");
                LanguageRegistry.instance().addStringLocalization("tile.MultiBlock_UN.ulGemBlock.name", "en_US", "UnLogic Gem Block");
                LanguageRegistry.instance().addStringLocalization("tile.MultiBlock_UN.redGemBlock.name", "en_US", "Ruby? Block");
                LanguageRegistry.instance().addStringLocalization("tile.MultiBlock_UN.blueGemBlock.name", "en_US", "Sapphire? Block");
                LanguageRegistry.instance().addStringLocalization("tile.MultiBlock_UN.farmObsidian.name", "en_US", "Obsidian Farmland");

 

If I helped please press the Thank You button.

 

Check out my mods at http://www.curse.com/users/The_Fireplace/projects

Posted

There seems to be an error in the method you are using to register the different sub-Names. You could use LanguageRegistry.instance().addStringLocalization("tile.MultiBlock_UN.name", "en_US", "Solidified Knowledge");

 

But then they would all have the same Name...

 

Make sure you add an extra Localization for every sub block. This could be done when You are adding them to their Creative Tab.

PM's regarding modding questions should belong in the Modder Support sub-forum and won't be answered.

Posted

To register subtype names using the LanguageRegistry, you actually have to create an instance of each ItemStack with the appropriate metadata/damage value, and register the name for it:

for (int i = 0; i < numSubBlocksYouHave; ++i) {
ItemStack stack = new ItemStack(yourBlock, 1, i);
// easiest if you have a static array of Strings for the names
// otherwise you can't use a for loop very well
LanguageRegistry.addName(stack, yourBlock.names[i]);
}

In 1.6.4, in most cases you can also just use the vanilla ItemBlockWithMetadata directly, unless you need some special handling of onItemUse or the like.

 

You may want to consider switching to a language file, though, since that's the way of the future.

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.