Jump to content

Recommended Posts

Posted

If you look at the BlockLeaves object it has a function called setGraphicsLevel which apart from the graphics level also changes the texture index. Likewise it has a function isOpaqueCube that returns true or false depending on the graphics level and determines if a block should be transparant or not.

Posted

i have tried using that but i cant seem to get it to work, heres the code

 

  Reveal hidden contents

 

Posted

Can you define what exactly doesn't work?

Assuming you are trying to achieve the same effect as vanilla Minecraft (fancy = transparent block and transparent texture, fast = opaque block/texture), this seems wrong:

 

public void setGraphicsLevel(boolean par1)
{
        this.graphicsLevel = par1;
        this.blockIndexInTexture = this.baseIndexInPNG + 1; <---
}

 

This will always sets the same texture, so you are either always using an opaque or a transparant texture.

Posted

even when its liek this

 

  Reveal hidden contents

 

 

it only give me one texture

Posted

On the wiki (here), there is an example of how to set up the Tick Handler. If you haven't already, go through this. In there is an OnRenderTick method. Inside that I do this for my leaves:

 

  Reveal hidden contents

 

The isWorldLoaded() is just a method checking if the world is loaded (!= null). I then call the leaves' setGraphicsLevel() method which then sets the fancy graphics on/off. I don't use the 'this.blockIndexInTexture' line. Obviously, make sure you change it so that it calls for your leaves block and not mine lol.

 

The code may need cleaning up a bit, but this is how I do it and it works for me. I hope it'll work with you :)

Posted

Have you logged to make sure that function gets called properly? Are you sure baseIndexInPNG + 0 or 1 is the correct texture index?

I just tried and for me this works perfectly:

 

public class CustomLeaves extends BlockLeaves {

public CustomLeaves(int par1, int par2) {
	super(par1, par2);
}

public void setGraphicsLevel(boolean par1) {
        this.graphicsLevel = par1;
        this.blockIndexInTexture = (par1 ? 0 : 16);
    }

public String getTextureFile() {
	return "somecustomtexturefile.png";
}
}

 

Fancy ingots or fast swords tree woosh:

treefancyfast.png

Posted

Btw one quick side note, isOpaqueCube doesn't mean your texture gets rendered with transparancy or not, it determines if it should try to render edges that would be 'invisable' when a block is opaque. If you look at the swords they only render on specific sides (those visable would the block actually be fully opaque) while the ingots version renders them on all sides.

Posted

do i need to add something to my mainmodfile.java? if i do then im an idiot

 

 

  Reveal hidden contents

 

Posted

Does the setGraphicsLevel function get called or not? Are you certain your code for actually generating the tree properly uses your custom leave block?

I don't see you registering a TickHandler anywhere in your main mod file like GeoffNukem suggested, so your function probably just never gets called.

Posted

This is pretty much what I do, maybe not named as they are here, but the important stuff should be there.

 

The @Mod class.

 

  Reveal hidden contents

 

ClientProxy class.

 

  Reveal hidden contents

 

MyTickHandler class.

 

  Reveal hidden contents

 

Your leaves class should be okay.

 

Also remember to change the names of the classes and things to the ones you're using.

 

Hope this helps.

  • 2 months later...
Posted
  On 11/20/2012 at 7:46 PM, Thor597 said:

My problem is that every time I change the fast/fancy graphic settings my block needs a block update or another one of its type to be placed down in order for it to change texture(but it changes in my hand immediately) and I can see through it and into the block underneath when its fancy

 

Which method in your block class do you use to get the texture index?

Don't ask for support per PM! They'll get ignored! | If a post helped you, click the "Thank You" button at the top right corner of said post! |

mah twitter

  Quote

This thread makes me sad because people just post copy-paste-ready code when it's obvious that the OP has little to no programming experience. This is not how learning works.

Posted
  On 11/20/2012 at 8:02 PM, SanAndreasP said:

  Quote

My problem is that every time I change the fast/fancy graphic settings my block needs a block update or another one of its type to be placed down in order for it to change texture(but it changes in my hand immediately) and I can see through it and into the block underneath when its fancy

 

Which method in your block class do you use to get the texture index?

 

Im not entirely sure what you mean by that but here is the block class:

 

package thedecopack.medieval.blocks;

import net.minecraft.src.*;
import cpw.mods.fml.common.Side;
import cpw.mods.fml.common.asm.SideOnly;
import java.util.List;
import java.util.Random;

import thedecopack.medieval.DecoMedieval;

public class BlockMedievalCedarLog extends Block
{
    protected BlockMedievalCedarLog(int par1)
    {
        super(par1, Material.wood);
        this.setCreativeTab(DecoMedieval.medievalTab);
    }

    /**
     * Returns the quantity of items to drop on block destruction.
     */
    public int quantityDropped(Random par1Random)
    {
        return 1;
    }

    /**
     * Returns the ID of the items to drop on destruction.
     */
    public int idDropped(int par1, Random par2Random, int par3)
    {
        return this.blockID;
    }

    /**
     * ejects contained items into the world, and notifies neighbours of an update, as appropriate
     */
    public void breakBlock(World par1World, int par2, int par3, int par4, int par5, int par6)
    {
        byte var7 = 4;
        int var8 = var7 + 1;

        if (par1World.checkChunksExist(par2 - var8, par3 - var8, par4 - var8, par2 + var8, par3 + var8, par4 + var8))
        {
            for (int var9 = -var7; var9 <= var7; ++var9)
            {
                for (int var10 = -var7; var10 <= var7; ++var10)
                {
                    for (int var11 = -var7; var11 <= var7; ++var11)
                    {
                        int var12 = par1World.getBlockId(par2 + var9, par3 + var10, par4 + var11);

                        if (Block.blocksList[var12] != null)
                        {
                            Block.blocksList[var12].beginLeavesDecay(par1World, par2 + var9, par3 + var10, par4 + var11);
                        }
                    }
                }
            }
        }
    }
    
    /**
     * From the specified side and block metadata retrieves the blocks texture. Args: side, metadata
     */
    public int getBlockTextureFromSide(int i)
    {
        if(i == 1 || i == 0)
        {
            return 17;
        }
        else
        {
                return 16;
        }
    }

    @Override
    public boolean canSustainLeaves(World world, int x, int y, int z)
    {
        return true;
    }

    @Override
    public boolean isWood(World world, int x, int y, int z)
    {
        return true;
    }
    
    public String getTextureFile()
    {
    	return DecoMedieval.instance.blockTextureFile();
    }
}

 

Posted
  On 11/20/2012 at 8:50 PM, Thor597 said:

  Quote

  Quote

My problem is that every time I change the fast/fancy graphic settings my block needs a block update or another one of its type to be placed down in order for it to change texture(but it changes in my hand immediately) and I can see through it and into the block underneath when its fancy

 

Which method in your block class do you use to get the texture index?

 

Im not entirely sure what you mean by that but here is the block class:

 

package thedecopack.medieval.blocks;

import net.minecraft.src.*;
import cpw.mods.fml.common.Side;
import cpw.mods.fml.common.asm.SideOnly;
import java.util.List;
import java.util.Random;

import thedecopack.medieval.DecoMedieval;

public class BlockMedievalCedarLog extends Block
{
    protected BlockMedievalCedarLog(int par1)
    {
        super(par1, Material.wood);
        this.setCreativeTab(DecoMedieval.medievalTab);
    }

    /**
     * Returns the quantity of items to drop on block destruction.
     */
    public int quantityDropped(Random par1Random)
    {
        return 1;
    }

    /**
     * Returns the ID of the items to drop on destruction.
     */
    public int idDropped(int par1, Random par2Random, int par3)
    {
        return this.blockID;
    }

    /**
     * ejects contained items into the world, and notifies neighbours of an update, as appropriate
     */
    public void breakBlock(World par1World, int par2, int par3, int par4, int par5, int par6)
    {
        byte var7 = 4;
        int var8 = var7 + 1;

        if (par1World.checkChunksExist(par2 - var8, par3 - var8, par4 - var8, par2 + var8, par3 + var8, par4 + var8))
        {
            for (int var9 = -var7; var9 <= var7; ++var9)
            {
                for (int var10 = -var7; var10 <= var7; ++var10)
                {
                    for (int var11 = -var7; var11 <= var7; ++var11)
                    {
                        int var12 = par1World.getBlockId(par2 + var9, par3 + var10, par4 + var11);

                        if (Block.blocksList[var12] != null)
                        {
                            Block.blocksList[var12].beginLeavesDecay(par1World, par2 + var9, par3 + var10, par4 + var11);
                        }
                    }
                }
            }
        }
    }
    
    /**
     * From the specified side and block metadata retrieves the blocks texture. Args: side, metadata
     */
    public int getBlockTextureFromSide(int i)
    {
        if(i == 1 || i == 0)
        {
            return 17;
        }
        else
        {
                return 16;
        }
    }

    @Override
    public boolean canSustainLeaves(World world, int x, int y, int z)
    {
        return true;
    }

    @Override
    public boolean isWood(World world, int x, int y, int z)
    {
        return true;
    }
    
    public String getTextureFile()
    {
    	return DecoMedieval.instance.blockTextureFile();
    }
}

 

 

I meant your leaves.

Don't ask for support per PM! They'll get ignored! | If a post helped you, click the "Thank You" button at the top right corner of said post! |

mah twitter

  Quote

This thread makes me sad because people just post copy-paste-ready code when it's obvious that the OP has little to no programming experience. This is not how learning works.

Posted

Since it seems that other people have this problem, what i could do is send a pr to forge that adds a loadrenderers event and passes an instance of a renderer class. It will called each time the world is re-rendered. You can then use the graphics setting.

I like collars. XP

Posted
  On 11/20/2012 at 10:39 PM, gravitythief said:

Since it seems that other people have this problem, what i could do is send a pr to forge that adds a loadrenderers event and passes an instance of a renderer class. It will called each time the world is re-rendered. You can then use the graphics setting.

 

That is not needed. All you need is the graphicsLevel boolean variable from an instance of the BlockLeaves class. It will be set to true automatically when the graphic level is fancy, false if it's fast.

 

I would suggest to extend BlockLeaves. You can also get an instance of a leave block and then get the boolean variable from there, like this:

boolean fancy = ((BlockLeaves)Block.blocksList[18]).graphicsLevel

 

Then you can use that boolean in your getTextureFromSideAndMetadata method of your block to determine the fast/fancy texture. Also in isOpaqueCube and in shouldSideBeRendered for correct rendering. Just look at the vanilla leaves code for this.

Don't ask for support per PM! They'll get ignored! | If a post helped you, click the "Thank You" button at the top right corner of said post! |

mah twitter

  Quote

This thread makes me sad because people just post copy-paste-ready code when it's obvious that the OP has little to no programming experience. This is not how learning works.

Posted

What i meant is, in RenderGlobal.class under loadRenderers() There is a specific call to the setGraphicsLevel right before the world is re-rendered. all i have to do is post an event right before or after the call. then in your event listener, you can update the static info in your leaves class.

I like collars. XP

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.