Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

 

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;
    	}
}
}

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

  • Author

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?

 

 

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

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.