Jump to content

Rendering block entity at an angle of 45 degrees [1.19.2] [SOLVED]


RInventor7

Recommended Posts

Hi! I have a working block entity renderer, but there’s 2 problems with it, that I can’t figure out how to solve. All I wish to do is to rotate the block by 45 degrees. Of course angles can be 0, 45, 90, 135, 180 etc.

@OnlyIn(Dist.CLIENT)
public class MyBlockRender implements BlockEntityRenderer<MyBlockBlockEntity> {
	BlockRenderDispatcher blockRenderer = Minecraft.getInstance().getBlockRenderer();

	public MyBlockRender(BlockEntityRendererProvider.Context renderManager) {
		super();
		blockRenderer = renderManager.getBlockRenderDispatcher();
	}

	@Override
	public void render(MyBlockBlockEntity be, float partialTicks, PoseStack poseStack, MultiBufferSource bufferSource, int combinedLight, int combinedOverlay) {
		BlockState bs = be.getBlockState();
		
		poseStack.pushPose();
		poseStack.translate(0.0, 1.5, 0.0);
		float f = PTMBlock.getRotationInDeg(bs);
		poseStack.mulPose(Vector3f.YP.rotationDegrees(f));

		blockRenderer.renderSingleBlock(bs, poseStack, bufferSource, combinedLight, OverlayTexture.NO_OVERLAY, ModelData.EMPTY, RenderType.cutout());
		poseStack.popPose();
	}

}

1) As my code indicates I move the model up. This immediately will indicate that it renders 2 blocks in 1. How can I stop the original renderer because otherwise (if no translation) it will render 2 models in one and if I rotate the model 45 degrees only my rendered model is at the correct angle.

2) Using 

poseStack.mulPose(Vector3f.YP.rotationDegrees(45f))

is messing up the model location. I want the model to be inside the bounding box but it’s rotated half a block on the side (depending on the angle). Does it got to do something with the actual block model.json or do i just have to use the translate function to center the model?

Edited by RInventor7
Fully solved
Link to comment
Share on other sites

16 hours ago, RInventor7 said:

How can I stop the original renderer because otherwise (if no translation) it will render 2 models in one and if I rotate the model 45 degrees only my rendered model is at the correct angle.

You can set the RenderShape to ENTITYBLOCK_ANIMATED via #getRenderShape. If you want the original model to render occasionally, you can change it via the block state.

16 hours ago, RInventor7 said:

I want the model to be inside the bounding box but it’s rotated half a block on the side (depending on the angle).

You need to translate it to the center and then translate it back. If you want to understand what's going, I suggest rotating the model every 4 or 5 ticks so you can see where the center point is located. Rotation not around the origin point constitutes translating the model to the origin, rotating, then translating back to the original position.

Link to comment
Share on other sites

  • RInventor7 changed the title to Rendering block entity at an angle of 45 degrees [1.19.2] [SOLVED]

The rotating works perfectly. Thank you.

However, setting the RenderType to ENTITYBLOCK_ANIMATED makes the default model invisible which is good, but it makes my rendered model also invisible. If I do not set the RenderType it renders still 2 models in 1. I can render one model (for example a block of glass) and rotate it, but if I render my block I either get 2 models in 1 or nothing. Is it possible to somehow only render 1 model (the one that I render myself) of my block? Maybe it is possible to somehow re-render the original model with rotation instead of rendering a new model with correct rotation?

My block has 5 different states which are defined by the blockstate.json and an IntegerProperty. I’m just trying to rotate the block without using the FACING property because then i’d have to make two json models of all the 5 states (one straight and the other at 45 deg angle) and then rotate them. So the whole idea is to use custom renderer to reduce model files from 20 to 5.

Edited by RInventor7
Link to comment
Share on other sites

  • RInventor7 changed the title to Rendering block entity at an angle of 45 degrees [1.19.2]
18 hours ago, RInventor7 said:

So the whole idea is to use custom renderer to reduce model files from 20 to 5.

So, as a quick tip, it's always better to use model files compared to BERs when possible. the JSON models (along with custom model loaders) can be cached by the chunk which is typically much more efficient to render than having to calculate the same data every tick. 20 models is negligible compared to 1 BER in most cases.

18 hours ago, RInventor7 said:

However, setting the RenderType to ENTITYBLOCK_ANIMATED makes the default model invisible which is good, but it makes my rendered model also invisible.

I mean, that's typically the case since the model isn't loaded by default. You would need to force the model to load yourself via the ModelEvent$RegisterAdditional event on the mod bus.

Link to comment
Share on other sites

  • RInventor7 changed the title to Rendering block entity at an angle of 45 degrees [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.