Jump to content

[1.16] How to display a texture like a name tag


Zemelua

Recommended Posts

I want to display a texture like a name tag. Specifically, it displays the texture on a black background of nametag with the same transparency as the characters on the name tag. I've just looked at the vanilla code that displays the name tag, but I'm running into a problem.

Textures appear semi-transparent when they overlap clouds or the ocean. To be honest, I don't understand the rendering system. I've followed the method that vanilla displays the characters in a name tag, but it's too complicated. I understand that MatrixStack is a class for rotating and moving objects to display, but Buffer? RenderSystem?

Is there a tutorial to understand those rendering systems? Also, which vanilla method is used to set the transparency etc. to display
 1. characters, 
 2. black translucent background
of the name tag?

 

Current code:

public void renderFocusedHealth(MatrixStack matrixStack, EntityRenderer<?> entityRenderer, Entity entity) {
		double d0 = entityRenderer.getRenderManager().squareDistanceTo(entity);
		if (net.minecraftforge.client.ForgeHooksClient.isNameplateInRenderDistance(entity, d0) && this.minecraft.pointedEntity == entity) {
			float f = entity.getHeight() + 0.5F;
			matrixStack.push();
			matrixStack.translate(0.0D, (double) f, 0.0D);
			matrixStack.rotate(entityRenderer.getRenderManager().getCameraOrientation());
			matrixStack.scale(-0.025F, -0.025F, 0.025F);

			this.minecraft.getTextureManager().bindTexture(UMUClientIngameGUI.GUI_ICONS_LOCATION);

			blit(matrixStack, 0, 0, 87, 0, 9, 9);

			matrixStack.pop();
		}
	}


@SubscribeEvent
	public void onRenderNameplate(RenderNameplateEvent event) {
		renderFocusedHealth(event.getMatrixStack(), event.getEntityRenderer(), event.getEntity());
	}

 

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.