Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

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;
                }
            }
        }
    }

}

 

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

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.