Jump to content

[1.7.2] [Solved] Custom Leaves always render transparent


SackCastellon

Recommended Posts

Here are two images to see the problem:

 

width=800 height=476https://dl.dropboxusercontent.com/u/184200482/img/tree_fancy.png[/img]

 

width=800 height=475https://dl.dropboxusercontent.com/u/184200482/img/tree_fast.png[/img]

 

As you can see my leaves always render transparent.

 

Here's my code:


package com.sackcastellon.treeoflife.block;

import com.sackcastellon.treeoflife.TreeOfLife;

import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.init.Items;
import net.minecraft.item.ItemStack;
import net.minecraft.util.IIcon;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;

public class BlockLeaves extends net.minecraft.block.BlockLeaves
{
    public static final String[][] field_150130_N = new String[][] {{"leaves"}, {"leavesOpaque"}};
    public static final String[] field_150131_O = new String[] {"ToL"};
    
    public BlockLeaves()
    {
        this.setCreativeTab(TreeOfLife.tabTol);
        this.setHardness(0.2F);
        this.setLightOpacity(1);
        this.setStepSound(soundTypeGrass);
    }
    
    /**
     * Returns the color this block should be rendered. Used by leaves.
     */
    @SideOnly(Side.CLIENT)
    public int getRenderColor(int p_149741_1_)
    {
        return 65280;
    }

    /**
     * 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_)
    {
        return 65280;
    }

    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(Items.apple, 1, 0));
        }
    }

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

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

        return j;
    }

    /**
     * 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] : ((p_149691_2_ & 3) == 3 ? this.field_150129_M[this.field_150127_b][3] : ((p_149691_2_ & 3) == 2 ? this.field_150129_M[this.field_150127_b][2] : this.field_150129_M[this.field_150127_b][0]));
    }

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

            for (int j = 0; j < field_150130_N[i].length; ++j)
            {
                this.field_150129_M[i][j] = p_149651_1_.registerIcon("treeoflife:" + field_150130_N[i][j]);
            }
        }
    }

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

 

Thanks for helping

Link to comment
Share on other sites

Hi

 

Vanilla changes the icon depending on the graphics level.  One has transparency, the other doesn't.  Also shouldSideBeRendered and isOpaque cube, to stop the "inside" of the foliage being rendered unnecessarily

 

Take a look at this code from 1.6.4

BlockLeavesBase::
    /**
     * 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
     */
    public boolean shouldSideBeRendered(IBlockAccess par1IBlockAccess, int par2, int par3, int par4, int par5)
    {
        int i1 = par1IBlockAccess.getBlockId(par2, par3, par4);
        return !this.graphicsLevel && i1 == this.blockID ? false : super.shouldSideBeRendered(par1IBlockAccess, par2, par3, par4, par5);
    }
BlockLeaves::
    
    private int iconType;  /** 1 for fast graphic. 0 for fancy graphics. used in iconArray. */
    private Icon[][] iconArray = new Icon[2][];

    public static final String[][] field_94396_b = new String[][] {{"leaves_oak", "leaves_spruce", "leaves_birch", "leaves_jungle"}, {"leaves_oak_opaque", "leaves_spruce_opaque", "leaves_birch_opaque", "leaves_jungle_opaque"}};

    /**
     * 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.graphicsLevel;
    }

    /**
     * From the specified side and block metadata retrieves the blocks texture. Args: side, metadata
     */
    public Icon getIcon(int par1, int par2)
    {
        return (par2 & 3) == 1 ? this.iconArray[this.iconType][1] : ((par2 & 3) == 3 ? this.iconArray[this.iconType][3] : ((par2 & 3) == 2 ? this.iconArray[this.iconType][2] : this.iconArray[this.iconType][0]));
    }

 

-TGG

Link to comment
Share on other sites

Minecraft still has that call for the "fancy" setting, in BlockLeaves (setGraphicsLevel), which only applies to vanilla leaves, sadly.

Basically, before returning the IIcon for your block, do

setGraphicsLevel(Minecraft.getMinecraft().gameSettings.fancyGraphics)

, then return the corresponding IIcon.

 

And for my sake, please deobfuscate your code.

Link to comment
Share on other sites

Minecraft still has that call for the "fancy" setting, in BlockLeaves (setGraphicsLevel), which only applies to vanilla leaves, sadly.

Basically, before returning the IIcon for your block, do

setGraphicsLevel(Minecraft.getMinecraft().gameSettings.fancyGraphics)

, then return the corresponding IIcon.

 

And for my sake, please deobfuscate your code.

 

Wait, so the setLightOpacity has no correlation either? Must've misread the javadoc.

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.

Announcements



×
×
  • Create New...

Important Information

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