Jump to content

Recommended Posts

Posted

I created some custom leaves for a tree in my mod. They are working fine, but they are rendering strangely. All my code for the leaves was based directly off the vanilla code. I even went through and changed all my variables to the vanilla equivalents after noticing the issues.  I switched over to vanilla textures as well. I have no clue what is causing this, and am hoping that one of you has experienced and been able to solve this issue already.

For some reason you are able to see through the leaves, kinda like an old school tnt x-ray machine. On the right are normal Oak leaves, the left are my leaves. The opaque textures for fast aren't working as well.

Fast:

gA0SOVM.png

Fancy:

7jRk11a.png

I add the block like this in my main blocks class,

	public static Block WDLeaves = new BlockWDLeaves().setBlockTextureName("wdleaves").setBlockName("wdleaves");
GameRegistry.registerBlock(WDLeaves, ItemWDLeaves.class, Reference.MODID + "_" + WDLeaves.getUnlocalizedName().substring(5));

All of the associated classes.

GenericWDLeaves:

 

package worlddomination.blocks;

 

import java.util.ArrayList;

import java.util.Random;

 

import net.minecraft.block.Block;

import net.minecraft.block.BlockLeavesBase;

import net.minecraft.block.material.Material;

import net.minecraft.creativetab.CreativeTabs;

import net.minecraft.entity.player.EntityPlayer;

import net.minecraft.init.Blocks;

import net.minecraft.item.Item;

import net.minecraft.item.ItemStack;

import net.minecraft.util.IIcon;

import net.minecraft.world.ColorizerFoliage;

import net.minecraft.world.IBlockAccess;

import net.minecraft.world.World;

import net.minecraftforge.common.IShearable;

import cpw.mods.fml.relauncher.Side;

import cpw.mods.fml.relauncher.SideOnly;

 

public abstract class GenericWDLeaves extends BlockWDLeavesBase implements IShearable

{

    int[] field_150128_a;

    @SideOnly(Side.CLIENT)

    protected int field_150127_b;

    protected IIcon[][] field_150129_M = new IIcon[2][];

    private static final String __OBFID = "CL_00000263";

 

    public GenericWDLeaves()

    {

        super(Material.leaves, false);

        this.setTickRandomly(true);

        this.setCreativeTab(CreativeTabs.tabDecorations);

        this.setHardness(0.2F);

        this.setLightOpacity(1);

        this.setStepSound(soundTypeGrass);

    }

 

    @SideOnly(Side.CLIENT)

    public int getBlockColor()

    {

        return ColorizerFoliage.getFoliageColorBasic();

    }

 

    /**

    * Returns the color this block should be rendered. Used by leaves.

    */

    @SideOnly(Side.CLIENT)

    public int getRenderColor(int p_149741_1_)

    {

        return ColorizerFoliage.getFoliageColorBasic();

    }

 

    /**

    * Returns a integer with hex for 0xrrggbb with this color multiplied against the blocks color. Note only called

    * when first determining what to render.

    */

    @SideOnly(Side.CLIENT)

    public int colorMultiplier(IBlockAccess p_149720_1_, int p_149720_2_, int p_149720_3_, int p_149720_4_)

    {

        int l = 0;

        int i1 = 0;

        int j1 = 0;

 

        for (int k1 = -1; k1 <= 1; ++k1)

        {

            for (int l1 = -1; l1 <= 1; ++l1)

            {

                int i2 = p_149720_1_.getBiomeGenForCoords(p_149720_2_ + l1, p_149720_4_ + k1).getBiomeFoliageColor(p_149720_2_ + l1, p_149720_3_, p_149720_4_ + k1);

                l += (i2 & 16711680) >> 16;

                i1 += (i2 & 65280) >> 8;

                j1 += i2 & 255;

            }

        }

 

        return (l / 9 & 255) << 16 | (i1 / 9 & 255) << 8 | j1 / 9 & 255;

    }

 

    public void breakBlock(World p_149749_1_, int p_149749_2_, int p_149749_3_, int p_149749_4_, Block p_149749_5_, int p_149749_6_)

    {

        byte b0 = 1;

        int i1 = b0 + 1;

 

        if (p_149749_1_.checkChunksExist(p_149749_2_ - i1, p_149749_3_ - i1, p_149749_4_ - i1, p_149749_2_ + i1, p_149749_3_ + i1, p_149749_4_ + i1))

        {

            for (int j1 = -b0; j1 <= b0; ++j1)

            {

                for (int k1 = -b0; k1 <= b0; ++k1)

                {

                    for (int l1 = -b0; l1 <= b0; ++l1)

                    {

                        Block block = p_149749_1_.getBlock(p_149749_2_ + j1, p_149749_3_ + k1, p_149749_4_ + l1);

                        if (block.isLeaves(p_149749_1_, p_149749_2_ + j1, p_149749_3_ + k1, p_149749_4_ + l1))

                        {

                            block.beginLeavesDecay(p_149749_1_, p_149749_2_ + j1, p_149749_3_ + k1, p_149749_4_ + l1);

                        }

                    }

                }

            }

        }

    }

 

    /**

    * Ticks the block if it's been scheduled

    */

    public void updateTick(World p_149674_1_, int p_149674_2_, int p_149674_3_, int p_149674_4_, Random p_149674_5_)

    {

        if (!p_149674_1_.isRemote)

        {

            int l = p_149674_1_.getBlockMetadata(p_149674_2_, p_149674_3_, p_149674_4_);

 

            if ((l & 8) != 0 && (l & 4) == 0)

            {

                byte b0 = 4;

                int i1 = b0 + 1;

                byte b1 = 32;

                int j1 = b1 * b1;

                int k1 = b1 / 2;

 

                if (this.field_150128_a == null)

                {

                    this.field_150128_a = new int[b1 * b1 * b1];

                }

 

                int l1;

 

                if (p_149674_1_.checkChunksExist(p_149674_2_ - i1, p_149674_3_ - i1, p_149674_4_ - i1, p_149674_2_ + i1, p_149674_3_ + i1, p_149674_4_ + i1))

                {

                    int i2;

                    int j2;

 

                    for (l1 = -b0; l1 <= b0; ++l1)

                    {

                        for (i2 = -b0; i2 <= b0; ++i2)

                        {

                            for (j2 = -b0; j2 <= b0; ++j2)

                            {

                                Block block = p_149674_1_.getBlock(p_149674_2_ + l1, p_149674_3_ + i2, p_149674_4_ + j2);

 

                                if (!block.canSustainLeaves(p_149674_1_, p_149674_2_ + l1, p_149674_3_ + i2, p_149674_4_ + j2))

                                {

                                    if (block.isLeaves(p_149674_1_, p_149674_2_ + l1, p_149674_3_ + i2, p_149674_4_ + j2))

                                    {

                                        this.field_150128_a[(l1 + k1) * j1 + (i2 + k1) * b1 + j2 + k1] = -2;

                                    }

                                    else

                                    {

                                        this.field_150128_a[(l1 + k1) * j1 + (i2 + k1) * b1 + j2 + k1] = -1;

                                    }

                                }

                                else

                                {

                                    this.field_150128_a[(l1 + k1) * j1 + (i2 + k1) * b1 + j2 + k1] = 0;

                                }

                            }

                        }

                    }

 

                    for (l1 = 1; l1 <= 4; ++l1)

                    {

                        for (i2 = -b0; i2 <= b0; ++i2)

                        {

                            for (j2 = -b0; j2 <= b0; ++j2)

                            {

                                for (int k2 = -b0; k2 <= b0; ++k2)

                                {

                                    if (this.field_150128_a[(i2 + k1) * j1 + (j2 + k1) * b1 + k2 + k1] == l1 - 1)

                                    {

                                        if (this.field_150128_a[(i2 + k1 - 1) * j1 + (j2 + k1) * b1 + k2 + k1] == -2)

                                        {

                                            this.field_150128_a[(i2 + k1 - 1) * j1 + (j2 + k1) * b1 + k2 + k1] = l1;

                                        }

 

                                        if (this.field_150128_a[(i2 + k1 + 1) * j1 + (j2 + k1) * b1 + k2 + k1] == -2)

                                        {

                                            this.field_150128_a[(i2 + k1 + 1) * j1 + (j2 + k1) * b1 + k2 + k1] = l1;

                                        }

 

                                        if (this.field_150128_a[(i2 + k1) * j1 + (j2 + k1 - 1) * b1 + k2 + k1] == -2)

                                        {

                                            this.field_150128_a[(i2 + k1) * j1 + (j2 + k1 - 1) * b1 + k2 + k1] = l1;

                                        }

 

                                        if (this.field_150128_a[(i2 + k1) * j1 + (j2 + k1 + 1) * b1 + k2 + k1] == -2)

                                        {

                                            this.field_150128_a[(i2 + k1) * j1 + (j2 + k1 + 1) * b1 + k2 + k1] = l1;

                                        }

 

                                        if (this.field_150128_a[(i2 + k1) * j1 + (j2 + k1) * b1 + (k2 + k1 - 1)] == -2)

                                        {

                                            this.field_150128_a[(i2 + k1) * j1 + (j2 + k1) * b1 + (k2 + k1 - 1)] = l1;

                                        }

 

                                        if (this.field_150128_a[(i2 + k1) * j1 + (j2 + k1) * b1 + k2 + k1 + 1] == -2)

                                        {

                                            this.field_150128_a[(i2 + k1) * j1 + (j2 + k1) * b1 + k2 + k1 + 1] = l1;

                                        }

                                    }

                                }

                            }

                        }

                    }

                }

 

                l1 = this.field_150128_a[k1 * j1 + k1 * b1 + k1];

 

                if (l1 >= 0)

                {

                    p_149674_1_.setBlockMetadataWithNotify(p_149674_2_, p_149674_3_, p_149674_4_, l & -9, 4);

                }

                else

                {

                    this.removeLeaves(p_149674_1_, p_149674_2_, p_149674_3_, p_149674_4_);

                }

            }

        }

    }

 

    /**

    * A randomly called display update to be able to add particles or other items for display

    */

    @SideOnly(Side.CLIENT)

    public void randomDisplayTick(World p_149734_1_, int p_149734_2_, int p_149734_3_, int p_149734_4_, Random p_149734_5_)

    {

        if (p_149734_1_.canLightningStrikeAt(p_149734_2_, p_149734_3_ + 1, p_149734_4_) && !World.doesBlockHaveSolidTopSurface(p_149734_1_, p_149734_2_, p_149734_3_ - 1, p_149734_4_) && p_149734_5_.nextInt(15) == 1)

        {

            double d0 = (double)((float)p_149734_2_ + p_149734_5_.nextFloat());

            double d1 = (double)p_149734_3_ - 0.05D;

            double d2 = (double)((float)p_149734_4_ + p_149734_5_.nextFloat());

            p_149734_1_.spawnParticle("dripWater", d0, d1, d2, 0.0D, 0.0D, 0.0D);

        }

    }

 

    private void removeLeaves(World p_150126_1_, int p_150126_2_, int p_150126_3_, int p_150126_4_)

    {

        this.dropBlockAsItem(p_150126_1_, p_150126_2_, p_150126_3_, p_150126_4_, p_150126_1_.getBlockMetadata(p_150126_2_, p_150126_3_, p_150126_4_), 0);

        p_150126_1_.setBlockToAir(p_150126_2_, p_150126_3_, p_150126_4_);

    }

 

    /**

    * Returns the quantity of items to drop on block destruction.

    */

    public int quantityDropped(Random p_149745_1_)

    {

        return p_149745_1_.nextInt(20) == 0 ? 1 : 0;

    }

 

    public Item getItemDropped(int p_149650_1_, Random p_149650_2_, int p_149650_3_)

    {

        return Item.getItemFromBlock(Blocks.sapling);

    }

 

    /**

    * Drops the block items with a specified chance of dropping the specified items

    */

    public void dropBlockAsItemWithChance(World p_149690_1_, int p_149690_2_, int p_149690_3_, int p_149690_4_, int p_149690_5_, float p_149690_6_, int p_149690_7_)

    {

        if (!p_149690_1_.isRemote)

        {

            int j1 = this.func_150123_b(p_149690_5_);

 

            if (p_149690_7_ > 0)

            {

                j1 -= 2 << p_149690_7_;

 

                if (j1 < 10)

                {

                    j1 = 10;

                }

            }

 

            if (p_149690_1_.rand.nextInt(j1) == 0)

            {

                Item item = this.getItemDropped(p_149690_5_, p_149690_1_.rand, p_149690_7_);

                this.dropBlockAsItem(p_149690_1_, p_149690_2_, p_149690_3_, p_149690_4_, new ItemStack(item, 1, this.damageDropped(p_149690_5_)));

            }

 

            j1 = 200;

 

            if (p_149690_7_ > 0)

            {

                j1 -= 10 << p_149690_7_;

 

                if (j1 < 40)

                {

                    j1 = 40;

                }

            }

 

            this.func_150124_c(p_149690_1_, p_149690_2_, p_149690_3_, p_149690_4_, p_149690_5_, j1);

        }

    }

 

    protected void func_150124_c(World p_150124_1_, int p_150124_2_, int p_150124_3_, int p_150124_4_, int p_150124_5_, int p_150124_6_) {}

 

    protected int func_150123_b(int p_150123_1_)

    {

        return 20;

    }

 

    /**

    * Called when the player destroys a block with an item that can harvest it. (i, j, k) are the coordinates of the

    * block and l is the block's subtype/damage .

    */

    public void harvestBlock(World p_149636_1_, EntityPlayer p_149636_2_, int p_149636_3_, int p_149636_4_, int p_149636_5_, int p_149636_6_)

    {

        {

            super.harvestBlock(p_149636_1_, p_149636_2_, p_149636_3_, p_149636_4_, p_149636_5_, p_149636_6_);

        }

    }

 

    /**

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

    */

    public int damageDropped(int p_149692_1_)

    {

        return p_149692_1_ & 3;

    }

 

    /**

    * Is this block (a) opaque and (b) a full 1m cube?  This determines whether or not to render the shared face of two

    * adjacent blocks and also whether the player can attach torches, redstone wire, etc to this block.

    */

    public boolean isOpaqueCube()

    {

        return !this.field_150121_P;

    }

 

    /**

    * Gets the block's texture. Args: side, meta

    */

    @SideOnly(Side.CLIENT)

    public abstract IIcon getIcon(int var1, int var2);

 

    /**

    * Pass true to draw this block using fancy graphics, or false for fast graphics.

    */

    @SideOnly(Side.CLIENT)

    public void setGraphicsLevel(boolean p_150122_1_)

    {

        this.field_150121_P = p_150122_1_;

        this.field_150127_b = p_150122_1_ ? 0 : 1;

    }

 

    /**

    * Returns an item stack containing a single instance of the current block type. 'i' is the block's subtype/damage

    * and is ignored for blocks which do not support subtypes. Blocks which cannot be harvested should return null.

    */

    protected ItemStack createStackedBlock(int p_149644_1_)

    {

        return new ItemStack(Item.getItemFromBlock(this), 1, p_149644_1_ & 3);

    }

 

    public abstract String[] func_150125_e();

 

 

    @Override

    public boolean isShearable(ItemStack item, IBlockAccess world, int x, int y, int z)

    {

        return true;

    }

 

    @Override

    public ArrayList<ItemStack> onSheared(ItemStack item, IBlockAccess world, int x, int y, int z, int fortune)

    {

        ArrayList<ItemStack> ret = new ArrayList<ItemStack>();

        ret.add(new ItemStack(this, 1, world.getBlockMetadata(x, y, z) & 3));

        return ret;

    }

 

    @Override

    public void beginLeavesDecay(World world, int x, int y, int z)

    {

 

        int i2 = world.getBlockMetadata(x, y, z);

 

        if ((i2 & 8) == 0)

        {

            world.setBlockMetadataWithNotify(x, y, z, i2 | 8, 4);

        }

        world.setBlockMetadataWithNotify(x, y, z, world.getBlockMetadata(x, y, z) | 8, 4);

    }

 

    @Override

    public boolean isLeaves(IBlockAccess world, int x, int y, int z)

    {

        return true;

    }

}

 

BlockWDLeaves:

 

package worlddomination.blocks;

 

import java.util.List;

 

import worlddomination.core.WorldDominationItem;

import worlddomination.util.Reference;

import net.minecraft.block.BlockLeaves;

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

import cpw.mods.fml.relauncher.Side;

import cpw.mods.fml.relauncher.SideOnly;

 

public class BlockWDLeaves extends BlockLeaves

{

    public static final String[][] field_150132_N = new String[][] {{"leaves_rubber"}, {"leaves_rubber_opaque"}};

    public static final String[] field_150133_O = new String[] {"rubber"};

    private static final String __OBFID = "CL_00000276";

 

    protected void func_150124_c(World p_150124_1_, int p_150124_2_, int p_150124_3_, int p_150124_4_, int p_150124_5_, int p_150124_6_)

    {

        if ((p_150124_5_ & 3) == 0 && p_150124_1_.rand.nextInt(p_150124_6_) == 0)

        {

            this.dropBlockAsItem(p_150124_1_, p_150124_2_, p_150124_3_, p_150124_4_, new ItemStack(WorldDominationItem.Sap, 1, 0));

        }

    }

 

    /**

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

    */

    public int damageDropped(int p_149692_1_)

    {

        return super.damageDropped(p_149692_1_) + 4;

    }

 

    /**

    * Get the block's damage value (for use with pick block).

    */

    public int getDamageValue(World p_149643_1_, int p_149643_2_, int p_149643_3_, int p_149643_4_)

    {

        return p_149643_1_.getBlockMetadata(p_149643_2_, p_149643_3_, p_149643_4_) & 3;

    }

 

    /**

    * Gets the block's texture. Args: side, meta

    */

    @SideOnly(Side.CLIENT)

    public IIcon getIcon(int p_149691_1_, int p_149691_2_)

    {

        return (p_149691_2_ & 3) == 1 ? this.field_150129_M[this.field_150127_b][1] : this.field_150129_M[this.field_150127_b][0];

    }

 

    /**

    * returns a list of blocks with the same ID, but different meta (eg: wood returns 4 blocks)

    */

    @SideOnly(Side.CLIENT)

    public void getSubBlocks(Item p_149666_1_, CreativeTabs p_149666_2_, List p_149666_3_)

    {

        p_149666_3_.add(new ItemStack(p_149666_1_, 1, 0));

    }

 

    @SideOnly(Side.CLIENT)

    public void registerBlockIcons(IIconRegister p_149651_1_)

    {

        for (int i = 0; i < field_150132_N.length; ++i)

        {

            this.field_150129_M = new IIcon[field_150132_N.length];

 

            for (int j = 0; j < field_150132_N.length; ++j)

            {

                this.field_150129_M[j] = p_149651_1_.registerIcon(Reference.MODID + ":" + field_150132_N[j]);

            }

        }

    }

 

    public String[] func_150125_e()

    {

        return field_150133_O;

    }

}

 

BlockWDLeavesBase:

 

package worlddomination.blocks;

 

import cpw.mods.fml.relauncher.Side;

import cpw.mods.fml.relauncher.SideOnly;

import net.minecraft.block.Block;

import net.minecraft.block.material.Material;

import net.minecraft.world.IBlockAccess;

 

public class BlockWDLeavesBase extends Block

{

    protected boolean field_150121_P;

    private static final String __OBFID = "CL_00000326";

 

    protected BlockWDLeavesBase(Material p_i45433_1_, boolean p_i45433_2_)

    {

        super(p_i45433_1_);

        this.field_150121_P = p_i45433_2_;

    }

 

    /**

    * Is this block (a) opaque and (b) a full 1m cube?  This determines whether or not to render the shared face of two

    * adjacent blocks and also whether the player can attach torches, redstone wire, etc to this block.

    */

    public boolean isOpaqueCube()

    {

        return false;

    }

 

    /**

    * Returns true if the given side of this block type should be rendered, if the adjacent block is at the given

    * coordinates.  Args: blockAccess, x, y, z, side

    */

    @SideOnly(Side.CLIENT)

    public boolean shouldSideBeRendered(IBlockAccess p_149646_1_, int p_149646_2_, int p_149646_3_, int p_149646_4_, int p_149646_5_)

    {

        Block block = p_149646_1_.getBlock(p_149646_2_, p_149646_3_, p_149646_4_);

        return !this.field_150121_P && block == this ? false : super.shouldSideBeRendered(p_149646_1_, p_149646_2_, p_149646_3_, p_149646_4_, p_149646_5_);

    }

}

 

 

ItemWDLeaves

 

package worlddomination.items;

 

import net.minecraft.block.Block;

import net.minecraft.item.ItemBlock;

import net.minecraft.item.ItemStack;

import net.minecraft.util.IIcon;

import worlddomination.blocks.BlockWDLeaves;

import worlddomination.core.WorldDominationBlock;

import cpw.mods.fml.relauncher.Side;

import cpw.mods.fml.relauncher.SideOnly;

 

public class ItemWDLeaves extends ItemBlock {

 

    private final Block field_150940_b;

    private static final String __OBFID = "CL_00000046";

   

public ItemWDLeaves(Block p_i45344_1_) {

super(p_i45344_1_);

this.field_150940_b = p_i45344_1_;

        this.setMaxDamage(0);

        this.setHasSubtypes(true);

}

    /**

    * Returns the metadata of the block which this Item (ItemBlock) can place

    */

    public int getMetadata(int par1)

    {

        return par1 | 4;

    }

 

    /**

    * Returns the unlocalized name of this item. This version accepts an ItemStack so different stacks can have

    * different names based on their damage or NBT.

    */

    public String getUnlocalizedName(ItemStack par1ItemStack)

    {

        int i = par1ItemStack.getItemDamage();

 

        if (i < 0 || i >= ((BlockWDLeaves) this.field_150940_b).func_150125_e().length)

        {

            i = 0;

        }

 

        return super.getUnlocalizedName() + "." + ((BlockWDLeaves) this.field_150940_b).func_150125_e();

    }

 

    /**

    * Gets an icon index based on an item's damage value

    */

    @SideOnly(Side.CLIENT)

    public IIcon getIconFromDamage(int par1)

    {

        return this.field_150940_b.getIcon(0, par1);

    }

 

    @SideOnly(Side.CLIENT)

    public int getColorFromItemStack(ItemStack par1ItemStack, int par2)

    {

        return this.field_150940_b.getRenderColor(par1ItemStack.getItemDamage());

    }

}

 

 

Thanks for any help, as always.

Posted

Thanks for the help, i must have forgot to override it. I am however, still having problems trying to get the opaque textures to show when i have the graphics on fast.

Posted

there is a method in the leaves class called setGraphicsLevel(boolean p_150122_1_) that is used to check if fancy graphics in enabled

Ok, so i need to call this function and assign it a value? I tried what minecraft does in there Global Renderer, but im getting all kinds of static issues. How am i supposed to use this function?

Posted

there is a method in the leaves class called setGraphicsLevel(boolean p_150122_1_) that is used to check if fancy graphics in enabled

Hi

 

There were a couple of recent posts in this forum (1-2 weeks ago?) with exactly the same symptoms, you could try a search for those

 

eg

 

http://www.minecraftforge.net/forum/index.php/topic,18775.msg94918.html#msg94918

 

-TGG

Thanks everyone, i was able to solve this issue. if anyone is interested the solution is as easy as putting this.setGraphicsLevel(Minecraft.getMinecraft().gameSettings.fancyGraphics); in your getIcon Method right before you return the 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...

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

Announcements



×
×
  • Create New...

Important Information

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