Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

Metadata getTextureFile()


calclavia
 Share

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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
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.

 Share



×
×
  • Create New...

Important Information

By using this site, you agree to our Privacy Policy.