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

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

    • They were already updated, and just to double check I even did a cleanup and fresh update from that same page. I'm quite sure drivers are not the problem here. 
    • i tried downloading the drivers but it says no AMD graphics hardware has been detected    
    • Update your AMD/ATI drivers - get the drivers from their website - do not update via system  
    • As the title says i keep on crashing on forge 1.20.1 even without any mods downloaded, i have the latest drivers (nvidia) and vanilla minecraft works perfectly fine for me logs: https://pastebin.com/5UR01yG9
    • Hello everyone, I'm making this post to seek help for my modded block, It's a special block called FrozenBlock supposed to take the place of an old block, then after a set amount of ticks, it's supposed to revert its Block State, Entity, data... to the old block like this :  The problem I have is that the system breaks when handling multi blocks (I tried some fix but none of them worked) :  The bug I have identified is that the function "setOldBlockFields" in the item's "setFrozenBlock" function gets called once for the 1st block of multiblock getting frozen (as it should), but gets called a second time BEFORE creating the first FrozenBlock with the data of the 1st block, hence giving the same data to the two FrozenBlock :   Old Block Fields set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=head] BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@73681674 BlockEntityData : id:"minecraft:bed",x:3,y:-60,z:-6} Old Block Fields set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=foot] BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@6d1aa3da BlockEntityData : {id:"minecraft:bed",x:2,y:-60,z:-6} Frozen Block Entity set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=foot] BlockPos{x=3, y=-60, z=-6} BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@6d1aa3da BlockEntityData : {id:"minecraft:bed",x:2,y:-60,z:-6} Frozen Block Entity set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=foot] BlockPos{x=2, y=-60, z=-6} BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@6d1aa3da BlockEntityData : {id:"minecraft:bed",x:2,y:-60,z:-6} here is the code inside my custom "freeze" item :    @Override     public @NotNull InteractionResult useOn(@NotNull UseOnContext pContext) {         if (!pContext.getLevel().isClientSide() && pContext.getHand() == InteractionHand.MAIN_HAND) {             BlockPos blockPos = pContext.getClickedPos();             BlockPos secondBlockPos = getMultiblockPos(blockPos, pContext.getLevel().getBlockState(blockPos));             if (secondBlockPos != null) {                 createFrozenBlock(pContext, secondBlockPos);             }             createFrozenBlock(pContext, blockPos);             return InteractionResult.SUCCESS;         }         return super.useOn(pContext);     }     public static void createFrozenBlock(UseOnContext pContext, BlockPos blockPos) {         BlockState oldState = pContext.getLevel().getBlockState(blockPos);         BlockEntity oldBlockEntity = oldState.hasBlockEntity() ? pContext.getLevel().getBlockEntity(blockPos) : null;         CompoundTag oldBlockEntityData = oldState.hasBlockEntity() ? oldBlockEntity.serializeNBT() : null;         if (oldBlockEntity != null) {             pContext.getLevel().removeBlockEntity(blockPos);         }         BlockState FrozenBlock = setFrozenBlock(oldState, oldBlockEntity, oldBlockEntityData);         pContext.getLevel().setBlockAndUpdate(blockPos, FrozenBlock);     }     public static BlockState setFrozenBlock(BlockState blockState, @Nullable BlockEntity blockEntity, @Nullable CompoundTag blockEntityData) {         BlockState FrozenBlock = BlockRegister.FROZEN_BLOCK.get().defaultBlockState();         ((FrozenBlock) FrozenBlock.getBlock()).setOldBlockFields(blockState, blockEntity, blockEntityData);         return FrozenBlock;     }  
  • Topics

×
×
  • Create New...

Important Information

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