Jump to content

Help with Leaves


gooball60

Recommended Posts

Hello, I have been having issues with leaves lately. So far, I have two leaf types - palm and apple blossom. The problem is that there is only one type in the game. On top of that, it also displays the opaque version in the creative tab.

 

They also decay eventually even when I place them on my own. I have not tested them with trees yet, so I'm sure even more problems will arise then. Oh yeah, the leaves don't change to the opaque texture when set to fast graphics. I know this is a lot in one post, but I have had these problems for weeks, and I'm getting desperate.

 

My leaf block:

 

package net.goocraft.mod.biome.features;


import java.util.List;

import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.goocraft.mod.GooCraft;
import net.minecraft.block.BlockLeaves;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.IIcon;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;

public class GooCraftLeaf extends BlockLeaves
{
    public static final String[][] names = new String[][] {{"AppleBlossomLeaves", "AppleBlossomLeavesOpaque"}, {"PalmLeaves", "PalmLeavesOpaque"}};
    public static final String[] types = new String[] {"AppleBlossom", "Palm"};
    protected IIcon[][] icon = new IIcon[2][];
    
    public GooCraftLeaf()
    {
        this.setCreativeTab(CreativeTabs.tabDecorations);
        this.setHardness(0.2F);
        this.setLightOpacity(1);
        this.setStepSound(soundTypeGrass);
        this.setTickRandomly(true);
    }
    

    protected void dropBlockAsItemWithChance(World par1, int par2, int par3, int par4, int par5, int par6)
    {
        if ((par5 & 3) == 0 && par1.rand.nextInt(par6) == 0)
        {
            this.dropBlockAsItem(par1, par2, par3, par4, new ItemStack(Items.apple, 1, 0));
        }
    }

    protected int func_150123_b(int par1)
    {
        int j = super.func_150123_b(par1);

        if ((par1 & 3) == 3)
        {
            j = 40;
        }

        return j;
    }

    @SideOnly(Side.CLIENT)
    public void getSubBlocks(Item par1, CreativeTabs par2, List par3)
    {
        par3.add(new ItemStack(par1, 1, 0));
        par3.add(new ItemStack(par1, 1, 1));
    }

    protected ItemStack createStackedBlock(int par1)
    {
        return new ItemStack(this, 1, par1 & 3);
    }
    
    public boolean isOpaqueCube()
    {
    	return false;
    }
    
    @SideOnly(Side.CLIENT)
    public IIcon getIcon(int par1, int par2)
    {
        this.setGraphicsLevel(Minecraft.getMinecraft().gameSettings.fancyGraphics);
    	return (par2 & 3) == 1 ? this.icon[this.field_150127_b][1] : ((par2 & 3) == 3 ? this.icon[this.field_150127_b][3] : ((par2 & 3) == 2 ? this.icon[this.field_150127_b][2] : this.icon[this.field_150127_b][0]));
    }

    @SideOnly(Side.CLIENT)
    @Override
    public void registerBlockIcons(IIconRegister par1)
    {
    	for (int i = 0; i < names.length; ++i)
        {
            this.icon[i] = new IIcon[names[i].length];

            for (int j = 0; j < names[i].length; ++j)
            {
                this.icon[i][j] = par1.registerIcon(GooCraft.modid + ":" + names[i][j]);
            }
        }
    }

    public String[] func_150125_e()
    {
        return types;
    }
}

 

And the item code:

 

package net.goocraft.mod.items;

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

public class ItemGooCraftLeaves extends ItemBlock {

private final static String[] names = {"AppleBlossom", "Palm"};

public ItemGooCraftLeaves(Block id) {
	super(id);
	setHasSubtypes(true);
}

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

@Override
public String getUnlocalizedName(ItemStack itemstack) {
	return getUnlocalizedName() + "." + names[itemstack.getItemDamage()];
}

}

 

Any help is appreciated.

Link to comment
Share on other sites

 

On top of that, it also displays the opaque version in the creative tab.

 

Oh yeah, the leaves don't change to the opaque texture when set to fast graphics.

Don't override 'isOpaqueCube()' that handles the opacity based on graphics level for you in the BlockLeaves base class.

 

ALso, the only statements you need in the constructor is the setCreativeTab one. Everything else is, again, in the base class you used.

Link to comment
Share on other sites

Ok, so I changed this:

 

public static final String[][] names = new String[][] {{"AppleBlossomLeaves", "AppleBlossomLeavesOpaque"}, {"PalmLeaves", "PalmLeavesOpaque"}};

 

To this:

 

public static final String[][] names = new String[][] {{"AppleBlossomLeaves", "PalmLeaves"}, {"AppleBlossomLeavesOpaque", "PalmLeavesOpaque"}};

 

And everthing seems to be working fine, even the graphics. Only one problem, The palm leaf texture shows up on the icon, but not on the block itself, the block has the same texture as the apple blossom. Also, the leaves still decay when I place them. I know they aren't supposed to decay when placed by a player, they only decay when they are on a tree and someone mines the trunk away. Now what?

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.