Jump to content

Some things invisible behind rendered text


Schauweg

Recommended Posts

So I have this problem with my custom Nametag.

Some stuff is invisible behind it like chests and coloured glass as seen in the picture. 

weirdRendering.png.f28904cf01d80f3d721d83485d9aeeff.png

I also think thats related to this bug since I use the RenderNameplateEvent

 

Here is my code

@SubscribeEvent
public void onNameplateRender(RenderNameplateEvent event){
	if (event.getEntity() instanceof TNTEntity && event.getEntity() != null){
		TNTEntity entity = (TNTEntity)(event.getEntity());
		EntityRendererManager manager = Minecraft.getInstance().getRenderManager();
		IRenderTypeBuffer renderTypeBuffer = event.getRenderTypeBuffer();

		renderTag(manager, entity, ticksToTime(entity.getFuse()), event.getMatrixStack(), renderTypeBuffer);
	}
}

@SuppressWarnings("rawtypes")
private void renderTag(EntityRendererManager manager, Entity entity, String text, MatrixStack stack, IRenderTypeBuffer impl) {
	float height = entity.getHeight();

	stack.push();
	stack.translate(0.0D, height + 0.5F, 0.0D);
	stack.rotate(manager.getCameraOrientation());
	stack.scale(-0.025F, -0.025F, 0.025F);

	Matrix4f matrix4f = stack.getLast().getMatrix();
	FontRenderer fontRenderer = manager.getFontRenderer();
	float offset = (float)(-fontRenderer.getStringWidth(text) / 2);

	fontRenderer.renderString(text, offset, 0F, 553648127, false, matrix4f, impl, true, 1056964608, 15728640);
	fontRenderer.renderString(text, offset, 0F, -1, false, matrix4f, impl, false, 1056964608, 15728640);

	stack.pop();
}

private String ticksToTime(int ticks){
	if(ticks > 20*3600){
		int h = ticks/20/3600;
		return h+" h";
	} else if(ticks > 20*60){
		int m = ticks/20/60;
		return m+" m";
	} else {
		int s = ticks / 20;
		int ms = (ticks % 20) / 2;
		return s+"."+ms+" s";
	}
}

Do you maybe have an idea to get around this issue?

Link to comment
Share on other sites

This issue has to do with the fact of see through text vs normal text rendering. Normal text rendering prioritizes all 'special' models behind the text to unload since the text is technically a solid object. See through text prioritizes the normal text to render behind any 'special' models making them appear to cut off the text. You have the correct implementation of using a see through rendered text with a normal rendered text, there is just one tiny error. To render the background of the text, you have to set the color equal to a value higher than 0. 1056964608 on the second renderString renders the background of the text as normal instead of making it transparent. So, you appear with the rendering bug. The way to fix it is just to change it to:

fontRenderer.renderString(text, offset, 0F, 553648127, false, matrix4f, impl, true, 1056964608, 15728640);
fontRenderer.renderString(text, offset, 0F, -1, false, matrix4f, impl, false, 0, 15728640);

This should solve your issue.

  • Thanks 1
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
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.