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

[1.16.1] How to apply texture in TileEntityRenderer


Anrza
 Share

Recommended Posts

Hello!

I'm rendering a model with a TileEntityRenderer. The rendering works fine apart from the texture, which looks like all textures in MC pasted together. I've tried to use TextureManager#bindTexture(ResourceLocation), but it doesn't affect the rendering at all.

 

package net.anju.larus.renderer;

import com.mojang.blaze3d.matrix.MatrixStack;
import com.mojang.blaze3d.vertex.IVertexBuilder;
import net.anju.larus.LarusMod;
import net.anju.larus.block.CrucibleBlock;
import net.anju.larus.block.LarusBlocks;
import net.anju.larus.tileentity.CrucibleTileEntity;
import net.minecraft.block.BlockState;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.BlockRendererDispatcher;
import net.minecraft.client.renderer.IRenderTypeBuffer;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.client.renderer.model.ModelRenderer;
import net.minecraft.client.renderer.tileentity.TileEntityRenderer;
import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.vector.Vector3f;
import net.minecraft.world.World;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;

import javax.annotation.ParametersAreNonnullByDefault;

@OnlyIn(Dist.CLIENT)
public class CrucibleTER extends TileEntityRenderer<CrucibleTileEntity> {

    private final CrucibleModel crucible;
    private final ResourceLocation resourceLocation = new ResourceLocation(LarusMod.MODID, "textures/block/crucible/crucible.png");

    public CrucibleTER(TileEntityRendererDispatcher rendererDispatcherIn) {
        super(rendererDispatcherIn);
        this.crucible = new CrucibleModel();
    }

    @Override
    @ParametersAreNonnullByDefault
    public void render(CrucibleTileEntity tileEntityIn, float partialTicks, MatrixStack matrixStackIn, IRenderTypeBuffer bufferIn, int combinedLightIn, int combinedOverlayIn) {
        World world = tileEntityIn.getWorld();
        boolean flag = world != null;
        BlockState blockState = flag ? tileEntityIn.getBlockState() : LarusBlocks.CRUCIBLE.get().getDefaultState();
        if (blockState.get(CrucibleBlock.TILTING)) {
            matrixStackIn.push();
            float rotation = blockState.get(CrucibleBlock.FACING).getHorizontalAngle();
            boolean warm = blockState.get(CrucibleBlock.WARM);
            matrixStackIn.translate(0.5D, 0.5D, 0.5D);
            matrixStackIn.rotate(Vector3f.YP.rotationDegrees(-rotation));
            matrixStackIn.rotate(Vector3f.XP.rotationDegrees(50F * tileEntityIn.getCrucibleAngle(partialTicks)));
            matrixStackIn.translate(-0.5D, -0.5D, -0.5D);
            IVertexBuilder iVertexBuilder = bufferIn.getBuffer(RenderType.getSolid());

            /*float angle = tileEntityIn.getCrucibleAngle(partialTicks);
            angle = 1.0F - angle;
            angle = 1.0F - angle * angle * angle;
            angle = -(angle * ((float) Math.PI / 2F));*/

            crucible.render(matrixStackIn, iVertexBuilder, combinedLightIn, combinedOverlayIn, tileEntityIn.getContentLevel());

            matrixStackIn.pop(); //Anrza: you must #push() before you pop, or it will crash
        }
    }

    private class CrucibleModel {
        private final ModelRenderer bottom;
        private final ModelRenderer front;
        private final ModelRenderer back;
        private final ModelRenderer right;
        private final ModelRenderer left;
        private final ModelRenderer level_1;
        private final ModelRenderer level_2;
        private final ModelRenderer level_3;

        public CrucibleModel() {
            int twi = 48;
            int thi = 16;
            //Bottom
            this.bottom = new ModelRenderer(twi, thi, 0, 0);
            this.bottom.addBox(2, 3, 2, 12, 1, 12, 0);
            //Front
            this.front = new ModelRenderer(twi, thi, 0, 0);
            this.front.addBox(2, 4, 12, 12, 12, 2);
            //Back
            this.back = new ModelRenderer(twi, thi, 0, 0);
            this.back.addBox(2, 4, 2, 12, 12, 2);

            //Left
            this.left = new ModelRenderer(twi, thi, 0, 0);
            this.left.addBox(2, 4, 4, 2, 12, 8);

            //Right
            this.right = new ModelRenderer(twi, thi, 0, 0);
            this.right.addBox(12, 4, 4, 2, 12, 8);


            //Levels
            this.level_1 = new ModelRenderer(twi, thi, 0, 0);
            this.level_1.addBox(4, 4, 4, 8, 2, 8);

            //Levels
            this.level_2 = new ModelRenderer(twi, thi, 0, 0);
            this.level_2.addBox(4, 4, 4, 8, 6, 8);

            //Levels
            this.level_3 = new ModelRenderer(twi, thi, 0, 0);
            this.level_3.addBox(4, 4, 4, 8, 11, 8);
        }

        public void render(MatrixStack matrixStackIn, IVertexBuilder bufferIn, int packedLightIn, int packedOverlayIn, int level) {
            renderDispatcher.textureManager.bindTexture(resourceLocation);
            this.bottom.render(matrixStackIn, bufferIn, packedLightIn, packedOverlayIn);
            this.front.render(matrixStackIn, bufferIn, packedLightIn, packedOverlayIn);
            this.back.render(matrixStackIn, bufferIn, packedLightIn, packedOverlayIn);
            this.left.render(matrixStackIn, bufferIn, packedLightIn, packedOverlayIn);
            this.right.render(matrixStackIn, bufferIn, packedLightIn, packedOverlayIn);
            switch (level) {
                case 1: {
                    level_1.render(matrixStackIn, bufferIn, packedLightIn, packedOverlayIn);
                    break;
                }
                case 2: {
                    level_2.render(matrixStackIn, bufferIn, packedLightIn, packedOverlayIn);
                    break;
                }
                case 3: {
                    level_3.render(matrixStackIn, bufferIn, packedLightIn, packedOverlayIn);
                    break;
                }
            }
        }
    }

}

 

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