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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Sorry, heres the new logs https://paste.ee/p/bTpMZ the ending crash error is the same but instead of the Minecraft crash screen saying the error for drivers its now showing -1 
    • Thanks for the advice, I am also facing this issue, I didn't thought about it before.
    • When I add a search bar to CreativeModeTab, the text box is not rendered even though it's possible to input text. Additionally, the search is performed on all items. This issue has been occurring since 1.21. Is there something missing in my code? https://github.com/mgen256/AdditionalLights/blob/1.21/src/main/java/com/mgen256/al/AdditionalLights.java
    • This question would probably best be asked wherever fabric support is given; these are the Minecraft Forge forums. They aren't the same thing
    • client version: forge-1.7.10-10.13.4.1614-1.7.10 forgegradle version:forge-1.7.10-10.13.4.1614-1.7.10   i can run my mod in forgegradle but i put my mod into a client ,it will crash  cpw.mods.fml.common.LoaderException: java.lang.NoSuchMethodError: com.example.examplemod.items.CommonItem.setUnlocalizedName(Ljava/lang/String;)Lnet/minecraft/item/Item;     at cpw.mods.fml.common.LoadController.transition(LoadController.java:163)     at cpw.mods.fml.common.Loader.preinitializeMods(Loader.java:559)     at cpw.mods.fml.client.FMLClientHandler.beginMinecraftLoading(FMLClientHandler.java:243)     at net.minecraft.client.Minecraft.func_71384_a(Minecraft.java:480)     at net.minecraft.client.Minecraft.func_99999_d(Minecraft.java:878)     at net.minecraft.client.main.Main.main(SourceFile:148)     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)     at java.lang.reflect.Method.invoke(Method.java:497)     at net.minecraft.launchwrapper.Launch.launch(Launch.java:135)     at net.minecraft.launchwrapper.Launch.main(Launch.java:28)     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)     at java.lang.reflect.Method.invoke(Method.java:497)     at oolloo.jlw.Wrapper.invokeMain(Wrapper.java:71)     at oolloo.jlw.Wrapper.main(Wrapper.java:51) Caused by: java.lang.NoSuchMethodError: com.example.examplemod.items.CommonItem.setUnlocalizedName(Ljava/lang/String;)Lnet/minecraft/item/Item;     at com.example.examplemod.items.CommonItem.<init>(CommonItem.java:10)     at com.example.examplemod.proxy.register.ItemRegister.createItem(ItemRegister.java:30)     at com.example.examplemod.proxy.register.ItemRegister.registerItems(ItemRegister.java:18)     at com.example.examplemod.proxy.CommonProxy.preInit(CommonProxy.java:12)     at com.example.examplemod.proxy.ClientProxy.preInit(ClientProxy.java:6)     at com.example.examplemod.ExampleMod.preInit(ExampleMod.java:26)     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)     at java.lang.reflect.Method.invoke(Method.java:497)     at cpw.mods.fml.common.FMLModContainer.handleModStateEvent(FMLModContainer.java:532)     at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)     at java.lang.reflect.Method.invoke(Method.java:497)     at com.google.common.eventbus.EventSubscriber.handleEvent(EventSubscriber.java:74)     at com.google.common.eventbus.SynchronizedEventSubscriber.handleEvent(SynchronizedEventSubscriber.java:47)     at com.google.common.eventbus.EventBus.dispatch(EventBus.java:322)     at com.google.common.eventbus.EventBus.dispatchQueuedEvents(EventBus.java:304)     at com.google.common.eventbus.EventBus.post(EventBus.java:275)     at cpw.mods.fml.common.LoadController.sendEventToModContainer(LoadController.java:212)     at cpw.mods.fml.common.LoadController.propogateStateMessage(LoadController.java:190)     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)     at java.lang.reflect.Method.invoke(Method.java:497)     at com.google.common.eventbus.EventSubscriber.handleEvent(EventSubscriber.java:74)     at com.google.common.eventbus.SynchronizedEventSubscriber.handleEvent(SynchronizedEventSubscriber.java:47)     at com.google.common.eventbus.EventBus.dispatch(EventBus.java:322)     at com.google.common.eventbus.EventBus.dispatchQueuedEvents(EventBus.java:304)     at com.google.common.eventbus.EventBus.post(EventBus.java:275)     at cpw.mods.fml.common.LoadController.distributeStateMessage(LoadController.java:119)     at cpw.mods.fml.common.Loader.preinitializeMods(Loader.java:556)     ... 16 more  
  • Topics

×
×
  • Create New...

Important Information

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