Jump to content

Metadata getTextureFile()


calclavia

Recommended Posts

Is there a metadata sensitive version of getTextureFile()? I am in a situation where I have blocks that use different texture files depending on their metadata. Getting a metadata version of this function would really be helpful.

 

I also stated the problem here in detail: http://minecraftforge.net/forum/index.php/topic,252.msg1807.html#new

Link to comment
Share on other sites

Is there a metadata sensitive version of getTextureFile()? I am in a situation where I have blocks that use different texture files depending on their metadata. Getting a metadata version of this function would really be helpful.

 

I also stated the problem here in detail: http://minecraftforge.net/forum/index.php/topic,252.msg1807.html#new

Just get the metadata of the block and switch it.

Link to comment
Share on other sites

Use the Block.getTextureFromSideAndMetadata(int side, int metadata){} method to set what texture from a spritesheet the block should be using, and then use a custom BlockRenderer to cause a texture update based on metadata.

 

When I needed a metadata sensitive renderer for my block that acts like sand, I passed in the metadata value, stored it in a field, and applied it to all of the places that render the sides of the block.

 

Here's a copy of that file:

 

 

package net.minecraft.src.stoneworld;

import org.lwjgl.opengl.GL11;

import net.minecraft.src.Block;
import net.minecraft.src.Entity;
import net.minecraft.src.EntityFallingSand;
import net.minecraft.src.MathHelper;
import net.minecraft.src.Render;
import net.minecraft.src.RenderBlocks;
import net.minecraft.src.Tessellator;
import net.minecraft.src.World;
import net.minecraft.src.mod_StoneWorld;

public class RenderFallingMud extends Render
{
    private RenderBlocks renderBlocks = new RenderBlocks();
    private int blockMeta;

    public RenderFallingMud()
    {
        this.shadowSize = 0.5F;
    }

    public void doRenderFallingMud(EntityFallingMud fallingmud, double xDouble, double zDouble, double yDouble, float par8, float par9)
    {
    	this.blockMeta = fallingmud.getBlockMetadata();
    	GL11.glPushMatrix();
        GL11.glTranslatef((float)xDouble, (float)zDouble, (float)yDouble);
        this.loadTexture(mod_StoneWorld.blockSpriteLocation);
        Block blockToRender = Block.blocksList[fallingmud.blockID];
        World world = fallingmud.getWorld();
        GL11.glDisable(GL11.GL_LIGHTING);

        if (blockToRender == Block.dragonEgg)
        {
            this.renderBlocks.blockAccess = world;
            Tessellator tessellator = Tessellator.instance;
            tessellator.startDrawingQuads();
            tessellator.setTranslation((double)((float)(-MathHelper.floor_double(fallingmud.posX)) - 0.5F), (double)((float)(-MathHelper.floor_double(fallingmud.posY)) - 0.5F), (double)((float)(-MathHelper.floor_double(fallingmud.posZ)) - 0.5F));
            this.renderBlocks.renderBlockByRenderType(blockToRender, MathHelper.floor_double(fallingmud.posX), MathHelper.floor_double(fallingmud.posY), MathHelper.floor_double(fallingmud.posZ));
            tessellator.setTranslation(0.0D, 0.0D, 0.0D);
            tessellator.draw();
        }
        else
        {
            this.renderBlockFallingMud(blockToRender, world, MathHelper.floor_double(fallingmud.posX), MathHelper.floor_double(fallingmud.posY), MathHelper.floor_double(fallingmud.posZ));
        }

        GL11.glEnable(GL11.GL_LIGHTING);
        GL11.glPopMatrix();
    }

    public void doRender(Entity entity, double xDouble, double yDouble, double zDouble, float par8, float par9)
    {
        this.doRenderFallingMud((EntityFallingMud)entity, xDouble, yDouble, zDouble, par8, par9);
    }
    
    public void renderBlockFallingMud(Block block, World world, int xInt, int yInt, int zInt)
    {
        float var6 = 0.5F;
        float var7 = 1.0F;
        float var8 = 0.8F;
        float var9 = 0.6F;
        Tessellator tessellator = Tessellator.instance;
        tessellator.startDrawingQuads();
        tessellator.setBrightness(block.getMixedBrightnessForBlock(world, xInt, yInt, zInt));
        float var11 = 1.0F;
        float var12 = 1.0F;

        if (var12 < var11)
        {
            var12 = var11;
        }

        tessellator.setColorOpaque_F(var6 * var12, var6 * var12, var6 * var12);
        renderBlocks.renderBottomFace(block, -0.5D, -0.5D, -0.5D, block.getBlockTextureFromSideAndMetadata(0, this.blockMeta));
        var12 = 1.0F;

        if (var12 < var11)
        {
            var12 = var11;
        }

        tessellator.setColorOpaque_F(var7 * var12, var7 * var12, var7 * var12);
        renderBlocks.renderTopFace(block, -0.5D, -0.5D, -0.5D, block.getBlockTextureFromSideAndMetadata(1, this.blockMeta));
        var12 = 1.0F;

        if (var12 < var11)
        {
            var12 = var11;
        }

        tessellator.setColorOpaque_F(var8 * var12, var8 * var12, var8 * var12);
        renderBlocks.renderEastFace(block, -0.5D, -0.5D, -0.5D, block.getBlockTextureFromSideAndMetadata(2, this.blockMeta));
        var12 = 1.0F;

        if (var12 < var11)
        {
            var12 = var11;
        }

        tessellator.setColorOpaque_F(var8 * var12, var8 * var12, var8 * var12);
        renderBlocks.renderWestFace(block, -0.5D, -0.5D, -0.5D, block.getBlockTextureFromSideAndMetadata(3, this.blockMeta));
        var12 = 1.0F;

        if (var12 < var11)
        {
            var12 = var11;
        }

        tessellator.setColorOpaque_F(var9 * var12, var9 * var12, var9 * var12);
        renderBlocks.renderNorthFace(block, -0.5D, -0.5D, -0.5D, block.getBlockTextureFromSideAndMetadata(4, this.blockMeta));
        var12 = 1.0F;

        if (var12 < var11)
        {
            var12 = var11;
        }

        tessellator.setColorOpaque_F(var9 * var12, var9 * var12, var9 * var12);
        renderBlocks.renderSouthFace(block, -0.5D, -0.5D, -0.5D, block.getBlockTextureFromSideAndMetadata(5, this.blockMeta));
        tessellator.draw();
    }
}

 

 

It's basically a clone of RenderFallingSand but I moved BlockRenderer.renderFallingSand into a local method and renamed it to be relevant.

 

Oh and HINT: Use a spritesheet for blocks, not seperate files. It makes things convenient.

I accidentally the everything then NullPointerException.

Link to comment
Share on other sites

Is there a metadata sensitive version of getTextureFile()? I am in a situation where I have blocks that use different texture files depending on their metadata. Getting a metadata version of this function would really be helpful.

 

I also stated the problem here in detail: http://minecraftforge.net/forum/index.php/topic,252.msg1807.html#new

Just get the metadata of the block and switch it.

 

I tried that. It simply keeps switching the texture of the block and goes all crazy when your inventory has two blocks with different texture files.

Link to comment
Share on other sites

Use the Block.getTextureFromSideAndMetadata(int side, int metadata){} method to set what texture from a spritesheet the block should be using, and then use a custom BlockRenderer to cause a texture update based on metadata.

 

When I needed a metadata sensitive renderer for my block that acts like sand, I passed in the metadata value, stored it in a field, and applied it to all of the places that render the sides of the block.

 

Here's a copy of that file:

 

 

package net.minecraft.src.stoneworld;

import org.lwjgl.opengl.GL11;

import net.minecraft.src.Block;
import net.minecraft.src.Entity;
import net.minecraft.src.EntityFallingSand;
import net.minecraft.src.MathHelper;
import net.minecraft.src.Render;
import net.minecraft.src.RenderBlocks;
import net.minecraft.src.Tessellator;
import net.minecraft.src.World;
import net.minecraft.src.mod_StoneWorld;

public class RenderFallingMud extends Render
{
    private RenderBlocks renderBlocks = new RenderBlocks();
    private int blockMeta;

    public RenderFallingMud()
    {
        this.shadowSize = 0.5F;
    }

    public void doRenderFallingMud(EntityFallingMud fallingmud, double xDouble, double zDouble, double yDouble, float par8, float par9)
    {
    	this.blockMeta = fallingmud.getBlockMetadata();
    	GL11.glPushMatrix();
        GL11.glTranslatef((float)xDouble, (float)zDouble, (float)yDouble);
        this.loadTexture(mod_StoneWorld.blockSpriteLocation);
        Block blockToRender = Block.blocksList[fallingmud.blockID];
        World world = fallingmud.getWorld();
        GL11.glDisable(GL11.GL_LIGHTING);

        if (blockToRender == Block.dragonEgg)
        {
            this.renderBlocks.blockAccess = world;
            Tessellator tessellator = Tessellator.instance;
            tessellator.startDrawingQuads();
            tessellator.setTranslation((double)((float)(-MathHelper.floor_double(fallingmud.posX)) - 0.5F), (double)((float)(-MathHelper.floor_double(fallingmud.posY)) - 0.5F), (double)((float)(-MathHelper.floor_double(fallingmud.posZ)) - 0.5F));
            this.renderBlocks.renderBlockByRenderType(blockToRender, MathHelper.floor_double(fallingmud.posX), MathHelper.floor_double(fallingmud.posY), MathHelper.floor_double(fallingmud.posZ));
            tessellator.setTranslation(0.0D, 0.0D, 0.0D);
            tessellator.draw();
        }
        else
        {
            this.renderBlockFallingMud(blockToRender, world, MathHelper.floor_double(fallingmud.posX), MathHelper.floor_double(fallingmud.posY), MathHelper.floor_double(fallingmud.posZ));
        }

        GL11.glEnable(GL11.GL_LIGHTING);
        GL11.glPopMatrix();
    }

    public void doRender(Entity entity, double xDouble, double yDouble, double zDouble, float par8, float par9)
    {
        this.doRenderFallingMud((EntityFallingMud)entity, xDouble, yDouble, zDouble, par8, par9);
    }
    
    public void renderBlockFallingMud(Block block, World world, int xInt, int yInt, int zInt)
    {
        float var6 = 0.5F;
        float var7 = 1.0F;
        float var8 = 0.8F;
        float var9 = 0.6F;
        Tessellator tessellator = Tessellator.instance;
        tessellator.startDrawingQuads();
        tessellator.setBrightness(block.getMixedBrightnessForBlock(world, xInt, yInt, zInt));
        float var11 = 1.0F;
        float var12 = 1.0F;

        if (var12 < var11)
        {
            var12 = var11;
        }

        tessellator.setColorOpaque_F(var6 * var12, var6 * var12, var6 * var12);
        renderBlocks.renderBottomFace(block, -0.5D, -0.5D, -0.5D, block.getBlockTextureFromSideAndMetadata(0, this.blockMeta));
        var12 = 1.0F;

        if (var12 < var11)
        {
            var12 = var11;
        }

        tessellator.setColorOpaque_F(var7 * var12, var7 * var12, var7 * var12);
        renderBlocks.renderTopFace(block, -0.5D, -0.5D, -0.5D, block.getBlockTextureFromSideAndMetadata(1, this.blockMeta));
        var12 = 1.0F;

        if (var12 < var11)
        {
            var12 = var11;
        }

        tessellator.setColorOpaque_F(var8 * var12, var8 * var12, var8 * var12);
        renderBlocks.renderEastFace(block, -0.5D, -0.5D, -0.5D, block.getBlockTextureFromSideAndMetadata(2, this.blockMeta));
        var12 = 1.0F;

        if (var12 < var11)
        {
            var12 = var11;
        }

        tessellator.setColorOpaque_F(var8 * var12, var8 * var12, var8 * var12);
        renderBlocks.renderWestFace(block, -0.5D, -0.5D, -0.5D, block.getBlockTextureFromSideAndMetadata(3, this.blockMeta));
        var12 = 1.0F;

        if (var12 < var11)
        {
            var12 = var11;
        }

        tessellator.setColorOpaque_F(var9 * var12, var9 * var12, var9 * var12);
        renderBlocks.renderNorthFace(block, -0.5D, -0.5D, -0.5D, block.getBlockTextureFromSideAndMetadata(4, this.blockMeta));
        var12 = 1.0F;

        if (var12 < var11)
        {
            var12 = var11;
        }

        tessellator.setColorOpaque_F(var9 * var12, var9 * var12, var9 * var12);
        renderBlocks.renderSouthFace(block, -0.5D, -0.5D, -0.5D, block.getBlockTextureFromSideAndMetadata(5, this.blockMeta));
        tessellator.draw();
    }
}

 

 

It's basically a clone of RenderFallingSand but I moved BlockRenderer.renderFallingSand into a local method and renamed it to be relevant.

 

Oh and HINT: Use a spritesheet for blocks, not seperate files. It makes things convenient.

 

That's not my problem. I have no problem rendering the block in the world with different texture files. The problem is that the block does not render properly when it is being held as an item. The problem is I can not set the render texture file when it is being rendered as an item. Changing the texture from getTextureFile simply causes all metadata blocks of the same block to change their texture thus causing crazy flickering of textures. Anyway of doing that properly? I tried using IItemRender and RenderInvBlocks I have no idea how I would do this.

Link to comment
Share on other sites

As far as I know it should do that automatically if you map the block metadata properly to an item that stores it.

 

My block has no problem having different textures in the inventory based on the ItemStack's damage value.

I accidentally the everything then NullPointerException.

Link to comment
Share on other sites

Yes I am. Just to clarify my problem:

 

I have a three 3D model tile entity that uses the same block. It uses metadata. The block uses a tile entity special renderer. In that renderer I can specify the texture of the block by using bindTextureByName function. Now I want to render that model as a 3D item you can hold in your hands. I can render it properly like shown in the picture, but I can not find a way to define/assign the correct texture to the correct model because there is not function like bindTextureByName when using the IItemRenderer implementations.

Link to comment
Share on other sites

Yes I am. Just to clarify my problem:

 

I have a three 3D model tile entity that uses the same block. It uses metadata. The block uses a tile entity special renderer. In that renderer I can specify the texture of the block by using bindTextureByName function. Now I want to render that model as a 3D item you can hold in your hands. I can render it properly like shown in the picture, but I can not find a way to define/assign the correct texture to the correct model because there is not function like bindTextureByName when using the IItemRenderer implementations.

 

Okay, assuming you're trying to use an actual item inside the inventory to render the held item, and not something odd (it was a little ambiguous), then you have access to the ItemStack in the inventory, and if you have access to an ItemStack then you can get the metadata value of whatever the ItemStack is and evaluate that.

I accidentally the everything then NullPointerException.

Link to comment
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now


  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Hello, I installed minecraft 1.16.2, then i downloaded forge 1.16.2-33.0.20 and it just won t open...no error message...
    • [29may2023 23:10:06.337] [main/INFO] [cpw.mods.modlauncher.Launcher/MODLAUNCHER]: ModLauncher running: args [--username, Fabu10th, --version, 1.19.3-forge-44.1.23, --gameDir, C:\Users\fabuo\AppData\Roaming\.minecraft, --assetsDir, C:\Users\fabuo\AppData\Roaming\.minecraft\assets, --assetIndex, 2, --uuid, 1f7b7b2f9e814cf4b23dfa2f0ccb79a1, --accessToken, ????????, --clientId, N2EyZmZhMTUtYjA0OC00N2RkLTg2NTgtZDM2YTUwNTZlODFj, --xuid, 2535425619212215, --userType, msa, --versionType, release, --launchTarget, forgeclient, --fml.forgeVersion, 44.1.23, --fml.mcVersion, 1.19.3, --fml.forgeGroup, net.minecraftforge, --fml.mcpVersion, 20221207.122022] [29may2023 23:10:06.341] [main/INFO] [cpw.mods.modlauncher.Launcher/MODLAUNCHER]: ModLauncher 10.0.8+10.0.8+main.0ef7e830 starting: java version 17.0.3 by Microsoft; OS Windows 10 arch amd64 version 10.0 [29may2023 23:10:07.130] [main/INFO] [optifine.OptiFineTransformationService/]: OptiFineTransformationService.onLoad [29may2023 23:10:07.131] [main/INFO] [optifine.OptiFineTransformationService/]: OptiFine ZIP file URL: union:/C:/Users/fabuo/AppData/Roaming/.minecraft/mods/OptiFine_1.19.3_HD_U_I3.jar%23265!/ [29may2023 23:10:07.138] [main/INFO] [optifine.OptiFineTransformationService/]: OptiFine ZIP file: C:\Users\fabuo\AppData\Roaming\.minecraft\mods\OptiFine_1.19.3_HD_U_I3.jar [29may2023 23:10:07.140] [main/INFO] [optifine.OptiFineTransformer/]: Target.PRE_CLASS is available [29may2023 23:10:07.185] [main/INFO] [mixin/]: SpongePowered MIXIN Subsystem Version=0.8.5 Source=union:/C:/Users/fabuo/AppData/Roaming/.minecraft/libraries/org/spongepowered/mixin/0.8.5/mixin-0.8.5.jar%2398!/ Service=ModLauncher Env=CLIENT [29may2023 23:10:07.190] [main/INFO] [optifine.OptiFineTransformationService/]: OptiFineTransformationService.initialize [29may2023 23:10:07.783] [main/WARN] [net.minecraftforge.fml.loading.moddiscovery.ModFileParser/LOADING]: Mod file C:\Users\fabuo\AppData\Roaming\.minecraft\libraries\net\minecraftforge\fmlcore\1.19.3-44.1.23\fmlcore-1.19.3-44.1.23.jar is missing mods.toml file [29may2023 23:10:07.787] [main/WARN] [net.minecraftforge.fml.loading.moddiscovery.ModFileParser/LOADING]: Mod file C:\Users\fabuo\AppData\Roaming\.minecraft\libraries\net\minecraftforge\javafmllanguage\1.19.3-44.1.23\javafmllanguage-1.19.3-44.1.23.jar is missing mods.toml file [29may2023 23:10:07.791] [main/WARN] [net.minecraftforge.fml.loading.moddiscovery.ModFileParser/LOADING]: Mod file C:\Users\fabuo\AppData\Roaming\.minecraft\libraries\net\minecraftforge\lowcodelanguage\1.19.3-44.1.23\lowcodelanguage-1.19.3-44.1.23.jar is missing mods.toml file [29may2023 23:10:07.794] [main/WARN] [net.minecraftforge.fml.loading.moddiscovery.ModFileParser/LOADING]: Mod file C:\Users\fabuo\AppData\Roaming\.minecraft\libraries\net\minecraftforge\mclanguage\1.19.3-44.1.23\mclanguage-1.19.3-44.1.23.jar is missing mods.toml file [29may2023 23:10:07.935] [main/INFO] [net.minecraftforge.fml.loading.moddiscovery.JarInJarDependencyLocator/]: Found 8 dependencies adding them to mods collection [29may2023 23:10:08.445] [main/INFO] [optifine.OptiFineTransformationService/]: OptiFineTransformationService.transformers [29may2023 23:10:08.451] [main/INFO] [optifine.OptiFineTransformer/]: Targets: 395 [29may2023 23:10:09.288] [main/INFO] [optifine.OptiFineTransformationService/]: additionalClassesLocator: [optifine., net.optifine.] [29may2023 23:10:10.427] [main/INFO] [mixin/]: Compatibility level set to JAVA_17 [29may2023 23:10:10.610] [main/INFO] [mixin/]: Successfully loaded Mixin Connector [ca.spottedleaf.starlight.mixin.MixinConnector] [29may2023 23:10:10.610] [main/INFO] [cpw.mods.modlauncher.LaunchServiceHandler/MODLAUNCHER]: Launching target 'forgeclient' with arguments [--version, 1.19.3-forge-44.1.23, --gameDir, C:\Users\fabuo\AppData\Roaming\.minecraft, --assetsDir, C:\Users\fabuo\AppData\Roaming\.minecraft\assets, --uuid, 1f7b7b2f9e814cf4b23dfa2f0ccb79a1, --username, Fabu10th, --assetIndex, 2, --accessToken, ????????, --clientId, N2EyZmZhMTUtYjA0OC00N2RkLTg2NTgtZDM2YTUwNTZlODFj, --xuid, 2535425619212215, --userType, msa, --versionType, release] [29may2023 23:10:10.650] [main/INFO] [Rubidium/]: Loaded configuration file for Rubidium: 30 options available, 0 override(s) found [29may2023 23:10:10.684] [main/WARN] [mixin/]: Reference map 'yungsextras.refmap.json' for yungsextras.mixins.json could not be read. If this is a development environment you can ignore this message [29may2023 23:10:10.686] [main/WARN] [mixin/]: Reference map 'yungsextras.refmap.json' for yungsextras_forge.mixins.json could not be read. If this is a development environment you can ignore this message [29may2023 23:10:10.703] [main/WARN] [mixin/]: Reference map 'xlpackets.refmap.json' for xlpackets.mixins.json could not be read. If this is a development environment you can ignore this message [29may2023 23:10:10.718] [main/WARN] [mixin/]: Reference map 'configured.refmap.json' for configured.mixins.json could not be read. If this is a development environment you can ignore this message [29may2023 23:10:10.728] [main/WARN] [mixin/]: Reference map 'simplyswords-common-refmap.json' for simplyswords-common.mixins.json could not be read. If this is a development environment you can ignore this message [29may2023 23:10:10.729] [main/WARN] [mixin/]: Reference map 'simplyswords-forge-refmap.json' for simplyswords.mixins.json could not be read. If this is a development environment you can ignore this message [29may2023 23:10:10.767] [main/WARN] [mixin/]: Reference map 'apexcore.refmap.json' for apexcore.mixins.json could not be read. If this is a development environment you can ignore this message
    • I'm looking for someone who for the most part would be taking over my mods main development. With work I just can't give it the time it deserves but I think it will be a good mod to fill the void of BuildCraft while still having its own unique twist. It is currently still only on 1.16.5 only because I just haven't had the time to try and get an update plus there were features I was working on that I had wanted to hammer out first. Not to mention I'm just not very good at Java or Programming in general. I can get things done and they mostly work but I am just not skilled enough to keep my brain child alive and honestly optimized. My only real requirement is that if I choose to come back I want to be able to jump back in and do so. I have a basic outline of how I want things to work in general for the things not added yet that were planned features and I also have some started but not yet finished ideas in. I'm currently working on getting a repo up on github that has my most current code so that way its easier for everyone involved to contribute. I'm sure the best first step would be to update to the newest version of forge first before doing this to give the next person a good head start but I'm sure alot of my stuff needs rewritten anyways so I figured I'd do this now as it sits.  Any other questions or details can be worked out through messages but if you are interested please drop a reply. Here is the link to the curseforge page which you can use to get to the github repo: https://www.curseforge.com/minecraft/mc-mods/mechanicraft
    • Hi, I am new to minecraft modding and have been following this guide on youtube (https://www.youtube.com/watch?v=aYH_81TXJxg&t=15s) and the textures for the modded items are not showing up. The game launches successfully and no errors are given. When I copied from the original GitHub it works perfectly but mine doesn't even though as far as I am aware they are exactly the same. Can someone please tell me what I am doing wrong? My code GitHub: https://github.com/BitFireStream/TutorialMod The guides GitHub: https://github.com/Tutorials-By-Kaupenjoe/Forge-Tutorial-1.19.3/tree/2-items
    • Hello. I have encountered an issue whist attempting to play on Forge 1.19.4 on the latest stable release beta as of 05/29/23. Everytime I attempt to load Minecraft Forge with mods installed, I recieve the following crash report:    The game crashed whilst rendering overlay Error: java.lang.IllegalStateException: Failed to create model for minecraft:hanging_sign   I have tried: Deleting all post-install custom installations Reinstalling Minecraft (deleting all files within Roaming/.minecraft folder and reinstalling) Updating Java Runtime Environment Uninstalling Java via Control Panel and downloading and installing newest recommended version (Java 8 Update 371)   Below I have included both the crash log I recieved, as well as the debug.log. I hope someone can help! crash-client.txt debug.log
  • Topics

×
×
  • Create New...

Important Information

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