Jump to content

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


Recommended Posts

Posted (edited)

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
Posted
  On 2/2/2023 at 9:13 PM, 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.

Expand  

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.

  On 2/2/2023 at 9:13 PM, 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).

Expand  

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.

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

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
  • RInventor7 changed the title to Rendering block entity at an angle of 45 degrees [1.19.2]
Posted
  On 2/3/2023 at 8:00 PM, RInventor7 said:

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

Expand  

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.

  On 2/3/2023 at 8:00 PM, 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.

Expand  

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.

  • 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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Title: Understanding ASM, Coremods, and Why Some Mods Break on Refactoring Post text: Hey everyone! I’ve been learning Minecraft modding for a while and ran into a question that I can’t figure out on my own. Hoping someone more experienced can help or give me some guidance. Here’s my issue: With most “normal” Forge mods — for example, those that just add new blocks or items — it’s fairly straightforward to refactor them. I can rename packages, move classes around, or reorganize the project without too much trouble. But as soon as I look at more complex cheat-style mods that use ASM, coremods, or deep game hooks — like Xray or Entity Xray — even a simple refactor breaks everything. For instance, just renaming classes or changing the package structure is enough to stop these kinds of mods from working at all. My question is: What’s fundamentally different about the architecture of these kinds of mods that makes them so fragile when refactoring? Is it the way they use bytecode manipulation, classloading tricks, or mappings that ties them to their original structure? And how can I better understand these kinds of mods so that I can reorganize or refactor them without breaking the core functionality? I’d really appreciate any insights into ASM, coremods, or classloaders — or any guides/resources that could help me understand this better. If you’ve successfully refactored or dissected mods like Xray or Entity Xray before, I’d love to hear your thoughts! Thanks in advance for any advice — I’m looking to deepen my understanding of these kinds of mods. ✌️
    • I can't figure out if you're looking for help trying to steal someone elses work, or cheat at the game....
    • Title: Why Is It So Hard to Rename and Restructure Mods Like Xray or AntiXray? 🤔 Post text: Hey everyone! I’ve been digging into Minecraft modding for a while and have one big question that I can’t figure out on my own. Maybe someone with more experience could help or give me some advice. Here’s the issue: When I take a “normal” Minecraft mod — for example, one that just adds some blocks or new items — I can easily change its structure, package names, or even rebrand it entirely. It’s straightforward. But as soon as I try this with cheat-type mods like XrayMod or AntiXray, everything falls apart. Even if I just rename the classes, refactor the packages, or hide its identity somehow, the mod either breaks or stops working properly. XrayMod in particular is proving to be a nightmare to modify without losing its core function. So my question is — why is this so much harder with cheat mods like Xray? Is there something fundamentally different about how they’re coded, loaded, or protected that prevents simple renaming or restructuring? And if so, how can I actually learn to understand someone else’s cheat mod enough to safely refactor it without breaking the core features? I’ve already been spending over two months trying to figure this out and haven’t gotten anywhere. It feels like there must be some trick or knowledge I’m missing. Would really appreciate any thoughts, tips, or references — maybe there are guides or techniques for understanding cheat-mod internals? Or if you’ve successfully “disguised” a cheat mod like Xray before, I’d love to hear how you did it. Thanks in advance for any help or discussion. ✌️
    • just started making cinamatic contect check it out on my channel or check out my facebook page    Humbug City Minecraft Youtube https://www.youtube.com/watch?v=v2N6OveKwno https://www.facebook.com/profile.php?id=61575866982337  
    • Where did you get the schematic? Source/Link? And do use an own modpack or a pre-configured from curseforge? If yes, which one On a later time, I can make some tests on my own - but I need the schematic and the modpack name
  • Topics

×
×
  • Create New...

Important Information

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