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

When I try to place down my block with metadata, it always places down the first metadata.

 

My BlockLeaf class:

public class CanadiaLeaf extends BlockLeaves{

public static final String[][] leafTypes = new String[][] {{"LeafMaple", "LeafRedCedar"}, {"leafMapleOpaque", "leafRedCedarOpaque"}};
public static final String[] leaves = new String[] {"Maple", "RedCedar"};

protected void func_150124_c(World world, int x, int y, int z, int side, int meta)
    {
        if (meta == 1)
        {
            this.dropBlockAsItem(world, x, y, z, new ItemStack(Canadia.maplesap, 1, 0));
        }
    }

    /**
     * Determines the damage on the item the block drops. Used in cloth and wood.
     */

public Item getItemDropped(int p_149650_1_, Random p_149650_2_, int p_149650_3_)
    {
        return Item.getItemFromBlock(Canadia.blockSapling);
    }


    public int damageDropped(int i)
    {
        return super.damageDropped(i) + 0;
    }

    /**
     * Get the block's damage value (for use with pick block).
     */
    public int getDamageValue(World world, int x, int y, int z)
    {
        return world.getBlockMetadata(x, y, z);
    }

    /**
     * returns a list of blocks with the same ID, but different meta (eg: wood returns 4 blocks)
     */
    @SideOnly(Side.CLIENT)
    public void getSubBlocks(Item item, CreativeTabs tab, List list)
    {
    	for(int i = 0; i < leaves.length; i++){
		list.add(new ItemStack(item, 1, i));
	}
    }

    @SideOnly(Side.CLIENT)
    public void registerBlockIcons(IIconRegister iconregister)
    {
        for (int i = 0; i < leafTypes.length; ++i)
        {
            this.field_150129_M[i] = new IIcon[leafTypes[i].length];

            for (int j = 0; j < leafTypes[i].length; ++j)
            {
                this.field_150129_M[i][j] = iconregister.registerIcon(Canadia.MODID + ":" + this.getUnlocalizedName().substring(5) + leafTypes[i][j]);
            }
        }
    }

@Override
public IIcon getIcon(int side, int meta) {
	return (meta & 3) == 1 ? this.field_150129_M[this.field_150127_b][1] : this.field_150129_M[this.field_150127_b][0];
}

@Override
public String[] func_150125_e() {
	return leaves;
}

@Override
public boolean renderAsNormalBlock() {
	return false;
}

@Override
public boolean isOpaqueCube(){
	return false;

}

@Override
public boolean shouldSideBeRendered(IBlockAccess blockaccess, int x, int y, int z, int side){
	return true;
}
}

 

 

And my ItemBlockLeaf class:

 

public class ItemLeafBlocks extends ItemBlock {

public static final String[] leaves = new String[] {"Maple", "RedCedar"};

public ItemLeafBlocks(Block block) {
	super(block);
	this.setHasSubtypes(true);
}

public String getUnlocalizedName(ItemStack itemstack){
	int i = itemstack.getItemDamage();
	if (i < 0 || i >= leaves.length){
		i = 0;
	}

	return super.getUnlocalizedName() + "." + leaves[i];
}

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

 

Thanks for your help!

You need to extend ItemBlockWithMetadata for your block's item, not ItemBlock; also, the default implementation for Block#damageDropped simply returns zero - calling super for that method is pointless; instead, you should just return i directly, as that is the metadata.

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.