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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Hi everyone, I'm currently developing a Forge 1.21 mod for Minecraft and I want to display a custom HUD overlay for a minigame. My goal: When the game starts, all players should see an item/block icon (from the base game, not a custom texture) plus its name/text in the HUD – similar to how the bossbar overlay works. The HUD should appear centered above the hotbar (or at a similar prominent spot), and update dynamically (icon and name change as the target item changes). What I've tried: I looked at many online tutorials and several GitHub repos (e.g. SeasonHUD, MiniHUD), but most of them use NeoForge or Forge versions <1.20 that provide the IGuiOverlay API (e.g. implements IGuiOverlay, RegisterGuiOverlaysEvent). In Forge 1.21, it seems that neither IGuiOverlay nor RegisterGuiOverlaysEvent exist anymore – at least, I can't import them and they are missing from the docs and code completion. I tried using RenderLevelStageEvent as a workaround but it is probably not intended for custom HUDs. I am not using NeoForge, and switching the project to NeoForge is currently not an option for me. I tried to look at the original minecraft source code to see how elements like hearts, hotbar etc are drawn on the screen but I am too new to Minecraft modding to understand. What I'm looking for: What is the correct way to add a custom HUD element (icon + text) in Forge 1.21, given that the previous overlay API is missing? Is there a new recommended event, callback, or method in Forge 1.21 for custom HUD overlays, or is everyone just using a workaround? Is there a minimal open-source example repo for Forge 1.21 that demonstrates a working HUD overlay without relying on NeoForge or deprecated Forge APIs? My ideal solution: Centered HUD element with an in-game item/block icon (from the base game's assets, e.g. a diamond or any ItemStack / Item) and its name as text, with a transparent background rectangle. It should be visible to the players when the mini game is running. Easy to update the item (e.g. static variable or other method), so it can change dynamically during the game. Any help, code snippets, or up-to-date references would be really appreciated! If this is simply not possible right now in Forge 1.21, it would also help to know that for sure. Thank you very much in advance!
    • The simple answer is there is not an easy way. You would need to know how to program in Java, as well as at least some familiarity with how Forge works so you could port the differences. You would also need the sourcecode for the original mod, and permission from the author to modify it, if they did not use some sort of open source license. So it's not impossible, but it would take some effort, but doing so would open up a whole new world of possibilities for you!
    • Does it still crash if you remove holdmyitems? Looks like that mod doesn't work on a server as far as I can tell from the error.  
    • Crashes the server when trying to start. Error code -1. Log  
  • Topics

  • Who's Online (See full list)

    • There are no registered users currently online
×
×
  • Create New...

Important Information

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