Jump to content

Item Blocks and Names


rob_bb

Recommended Posts

 

Hi, I am using the following code to create an item block, and to name the items. 

 

The problem I am having is the code creates a blank line in the item name, and I assume it is because I am using addInformation().

 

How do I give each item in a multiblock it's own name?

 

 

public class TreeSmall_Logs_IB extends ItemBlock {

public static final String	blockType[]	= { "banana", "orange" };

public TreeSmall_Logs_IB(int par1) {
	super(par1);
	this.setMaxDamage(0);
	this.setHasSubtypes(true);
}

@Override
public int getMetadata(int metadata) {
	return metadata;
}

@Override
public String getUnlocalizedName(ItemStack itemstack) {
	int i = MathHelper.clamp_int(itemstack.getItemDamage(), 0, 3);
	return new StringBuilder().append(blockType[i]).append("Log").toString();
}

    @SuppressWarnings({ "unchecked", "rawtypes" })
@Override
@SideOnly(Side.CLIENT)
    public void addInformation (ItemStack stack, EntityPlayer player, List list, boolean par4)
{
    	switch (stack.getItemDamage() % blockType.length)
    	{
    	case 0: 
    		list.add("Banana Tree Wood");
    		break;
    	case 1:
    		list.add("Orange Tree Wood");
    		break;
    	}
}
}

Link to comment
Share on other sites

Short answer:

Add your blockType array to your main mod class as private static final string[] using the names you want to display.

Put this code in your main mod class after the registerRenderers() function is called. TreeSmall_Logs is whatever the name of your block class will be.

 

GameRegistry.registerBlock(TreeSmall_Logs, TreeSmall_Logs_IB.class);
ItemStack multiBlockStack = new ItemStack(treeSmallLogs, 1, ix);
LanguageRegistry.addName(multiBlockStack, blockType[multiBlockStack.getItemDamage()]);

 

Now go to your TreeSmall_Logs_IB class and add the method:

 

@Override
public String getItemNameIS(ItemStack itemstack) {
	if(itemstack.getItemDamage() > 1)
                            return getItemName() + "." + blockType[0];
                return getItemName() + "." + blockType[itemstack.getItemDamage()];
}

 

 

Longer more detailed and explanatory answer...

go here:

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

Yay tutorials?

Read my thoughts on my summer mod work and tell me what you think!

http://www.minecraftforge.net/forum/index.php/topic,8396.0.html

 

I absolutely love her when she smiles

Link to comment
Share on other sites

Ok, I have that sorted, because I am using 1.5.1 the code is a little different, here is the code for any one interested:

 

 

 

 

public class TreeSmall_Saplings_IB extends ItemBlock {

 

public static final String[] blockType = { "banana_sapling", "orange_sapling" };

 

public TreeSmall_Saplings_IB(int iblock_id) {

super(iblock_id);

this.setMaxDamage(0);

this.setHasSubtypes(true);

}

 

@Override

public int getMetadata(int metadata) {

return metadata;

}

 

@Override

@SideOnly(Side.CLIENT)

public String getUnlocalizedName(ItemStack itemstack) {

return this.getUnlocalizedName()  + blockType[itemstack.getItemDamage()];

}

 

}

 

 

 

 

But I now have another problem.  Using this code to create saplings:  http://paste.minecraftforge.net/view/9901cb84

 

and code similar to the above for the ItemBlock, I get the correct names, and I get the correct icon when I plant a sapling, but in the creative tab I get the same icon for both saplings, that being the first icon.    Any clues as to why both items have the same icon?

 

 

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.



×
×
  • Create New...

Important Information

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