Jump to content

Custom block entity renderer not working [1.19.2] [SOLVED]


Recommended Posts

Posted (edited)

Hi! I managed to make a custom block entity render for my block entity. The renderer is correctly registered and it runs on every tick as it should be. The problem is that it’s not doing anything I have set it to do. What am I doing wrong? I just wish to move the block model, scale it smaller and rotate it 45 degrees. Thanks in advance.

package com.rinventor.transportmod.entities.render.block;

import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.math.Vector3f;
import com.rinventor.transportmod.core.base.PTMBlock;
import com.rinventor.transportmod.core.init.ModBlocks;
import com.rinventor.transportmod.objects.blockentities.MyBlockEntity;

import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.client.renderer.blockentity.BlockEntityRenderer;
import net.minecraft.client.renderer.blockentity.BlockEntityRendererProvider;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;

@OnlyIn(Dist.CLIENT)
public class MyBlockRender implements BlockEntityRenderer<MyBlockEntity>
{
	public MyBlockRender(BlockEntityRendererProvider.Context renderManager) {
		super();
        }
	
	@Override
	public void render(MyBlockEntity be, float partialTicks, PoseStack poseStack, MultiBufferSource bufferSource, int combinedLight, int combinedOverlay) {
		BlockState blockstate = be.getBlockState();
		poseStack.pushPose();
      
		if (blockstate.getBlock() == ModBlocks.MY_BLOCK.get()) {
			float f1 = 45.0F;
			poseStack.mulPose(Vector3f.YP.rotationDegrees(f1));
			poseStack.translate(0.5D, 0.5D, 0.5D);
			poseStack.scale(-0.6666667F, -0.6666667F, -0.6666667F);
		}
      	    poseStack.popPose();
	}
	
}

 

Edited by RInventor7
Posted (edited)

Thanks for the replay. You just saved me from a lot of extra work. Thank you so much! The following code works (at least I can now see the something rendered in game):

package com.rinventor.mymod.entities.render.block;

import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.math.Vector3f;
import com.rinventor.mymod.objects.blockentities.MyBlockBlockEntity;

import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.client.renderer.block.BlockRenderDispatcher;
import net.minecraft.client.renderer.blockentity.BlockEntityRenderer;
import net.minecraft.client.renderer.blockentity.BlockEntityRendererProvider;
import net.minecraft.client.renderer.texture.OverlayTexture;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;

@OnlyIn(Dist.CLIENT)
public class MyBlockRender implements BlockEntityRenderer<MyBlockBlockEntity>
{
	public MyBlockRender(BlockEntityRendererProvider.Context renderManager) {
		super();
    }
	
	@Override
	public void render(MyBlockBlockEntity be, float partialTicks, PoseStack poseStack, MultiBufferSource bufferSource, int combinedLight, int combinedOverlay) {
		BlockRenderDispatcher blockRenderer = Minecraft.getInstance().getBlockRenderer();
		BlockState blockstate = be.getBlockState();

		poseStack.pushPose();
		float f1 = 45.0F;
		poseStack.mulPose(new Vector3f().rotationDegrees(f1));
		
		blockRenderer.renderSingleBlock(blockstate, poseStack, bufferSource, combinedLight, OverlayTexture.NO_OVERLAY, be.getModelData(), RenderType.cutout());
		
		poseStack.popPose();
		
	}
	
}

 

Edited by RInventor7
  • RInventor7 changed the title to Custom block entity renderer not working [1.19.2] [SOLVED]

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



×
×
  • Create New...

Important Information

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