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

I'm adding a sapling class with twelve different sub-blocks. The saplings show the correct texture when placed in the world, but when in the inventory they always show the icon of the first sapling.

 

I've checked and getIcon() is always being given a metadata value of zero. If I change meta to any other appropriate number then that sapling's icon is shown. I cannot figure out why this is happening. I do the exact same thing with my leaves and logs and it works great.

 

Sapling class:

package arrowsplus;

import java.util.List;

import net.minecraft.block.Block;
import net.minecraft.block.BlockFlower;
import net.minecraft.client.renderer.texture.IconRegister;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.ItemStack;
import net.minecraft.util.Icon;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;

public class BlockArrowTreeSapling extends BlockFlower
{
public static final String[] woodType = new String[] {"aspen", "cottonwood", "alder", "sycamore", "gum", "softmaple",
	"ash", "beech", "hardmaple", "hickory", "mahogany", "sypherus"};
    @SideOnly(Side.CLIENT)
    private Icon[] saplingIcon;

    protected BlockArrowTreeSapling(int par1)
    {
        super(par1);
        this.setCreativeTab(ArrowsPlus.instance.tabArrowsPlus);
        this.setTickRandomly(true);
    }

@Override
public Block func_111022_d(String par1Str)
{
	this.field_111026_f = "arrowsPlus:tree";
	return this;
}

    @SideOnly(Side.CLIENT)
    public Icon getIcon(int side, int meta)
    {
    	//-----------------> Meta is always zero.
        return this.saplingIcon[meta];
    }

    public int damageDropped(int meta)
    {
        return meta;
    }

    @SideOnly(Side.CLIENT)
    public void getSubBlocks(int itemId, CreativeTabs creativeTab, List listSubBlocks)
    {
	listSubBlocks.add(new ItemStack(itemId, 1, 0));
	listSubBlocks.add(new ItemStack(itemId, 1, 1));
	listSubBlocks.add(new ItemStack(itemId, 1, 2));
	listSubBlocks.add(new ItemStack(itemId, 1, 3));
	listSubBlocks.add(new ItemStack(itemId, 1, 4));
	listSubBlocks.add(new ItemStack(itemId, 1, 5));
	listSubBlocks.add(new ItemStack(itemId, 1, 6));
	listSubBlocks.add(new ItemStack(itemId, 1, 7));
	listSubBlocks.add(new ItemStack(itemId, 1, );
	listSubBlocks.add(new ItemStack(itemId, 1, 9));
	listSubBlocks.add(new ItemStack(itemId, 1, 10));
	listSubBlocks.add(new ItemStack(itemId, 1, 11));
    }

    @SideOnly(Side.CLIENT)
    public void registerIcons(IconRegister iconRegister)
    {
	this.saplingIcon = new Icon[woodType.length];
	for (int i = 0; i < this.saplingIcon.length; ++i)
	{
		this.saplingIcon[i] = iconRegister.registerIcon(this.func_111023_E() + "_" + woodType[i] + "_sapling");
	}
    }
   
}

 

They are registered as such in preInit()

		blockArrowTreeSapling = new BlockArrowTreeSapling(modPropertiesManager.modProperties.blockId_ArrowLogSapling).func_111022_d("tree");
	GameRegistry.registerBlock(blockArrowTreeSapling, ItemBlockSapling.class, "Arrow Saplings");

	for (int i = 0; i < 12; i++)
	{
		ItemStack saplingStack = new ItemStack(blockArrowTreeSapling, 1, i);
		LanguageRegistry.addName(saplingStack, saplingNames[i]);
	}

 

The ItemBlock for the saplings

package arrowsplus;

import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;

public class ItemBlockSapling extends ItemBlock
{
public static final String[] saplingNames = new String[] {"Aspen Sapling", "Cottonwood Sapling", "Alder Sapling", "Sycamore Sapling", "Gum Sapling", "Soft Maple Sapling",
	"Ash Sapling", "Beech Sapling", "Hard Maple Sapling", "Hickory Sapling", "Mahogany Sapling", "Sypherus Sapling"};

public ItemBlockSapling(int id) 
{
	super(id);
	setHasSubtypes(true);
	setUnlocalizedName("ItemBlockSapling");
}

@Override
public int getMetadata(int damageValue) 
{
	ArrowsPlus.instance.log(damageValue);
	return damageValue;
}

    public String getUnlocalizedName(ItemStack par1ItemStack)
    {
        return saplingNames[par1ItemStack.getItemDamage()];
    }
}

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.