Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

I'd like to modify how player nametags are rendered, so I've started with the goal of cancelling their render in the first place. I'd like to do this by extending RenderPlayer, but I cannot seem to get it working. I've overridden RenderPlayer::renderEntityName to simply return without doing anything, but player nametags continue to render. Is this the wrong method to override? I don't see any calls to it in the source code, but I also don't see anything about rendering nametags in RenderPlayer::doRender.

That should be the method to override. Have you actually replaced the vanilla RenderPlayer instances with your own?

 

A better way to do this would be to subscribe to RenderLivingEvent.Specials.Pre, which is fired just before a living entity's nametag is rendered. You can cancel this to prevent the nametag from being rendered.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

  • Author
6 hours ago, Choonster said:

That should be the method to override. Have you actually replaced the vanilla RenderPlayer instances with your own?

 

A better way to do this would be to subscribe to RenderLivingEvent.Specials.Pre, which is fired just before a living entity's nametag is rendered. You can cancel this to prevent the nametag from being rendered.

Okay, now I have a couple of (probably simple) questions.

 

Why does cancelling RenderLivingEvent.Specials.Pre<AbstractClientPlayer> prevent all nametags from showing, rather than just players?

 

What role does RenderPlayer::renderEntityName have in rendering player names? It seems to handle scores displayed under the player's name and then call Render::renderEntityName, which is also called by RenderLivingBase::renderName. So when a player's nametag needs to be rendered, which is called, RenderPlayer::renderEntityName or RenderLivingBase::renderName?


RenderPlayer::renderEntityName

Spoiler



protected void renderEntityName(AbstractClientPlayer entityIn, double x, double y, double z, String name, double distanceSq)
{
	if (distanceSq < 100.0D)
	{
		Scoreboard scoreboard = entityIn.getWorldScoreboard();
		ScoreObjective scoreobjective = scoreboard.getObjectiveInDisplaySlot(2);

		if (scoreobjective != null)
		{
			Score score = scoreboard.getOrCreateScore(entityIn.getName(), scoreobjective);
			this.renderLivingLabel(entityIn, score.getScorePoints() + " " + scoreobjective.getDisplayName(), x, y, z, 64);
			y += (double)((float)this.getFontRendererFromRenderManager().FONT_HEIGHT * 1.15F * 0.025F);
		}
	}

	super.renderEntityName(entityIn, x, y, z, name, distanceSq);
}


 


RenderLivingBase::renderName

Spoiler



public void renderName(T entity, double x, double y, double z)
{
	if (net.minecraftforge.common.MinecraftForge.EVENT_BUS.post(new net.minecraftforge.client.event.RenderLivingEvent.Specials.Pre<T>(entity, this, x, y, z))) return;
	if (this.canRenderName(entity))
	{
		double d0 = entity.getDistanceSqToEntity(this.renderManager.renderViewEntity);
		float f = entity.isSneaking() ? NAME_TAG_RANGE_SNEAK : NAME_TAG_RANGE;

		if (d0 < (double)(f * f))
		{
			String s = entity.getDisplayName().getFormattedText();
			GlStateManager.alphaFunc(516, 0.1F);
			this.renderEntityName(entity, x, y, z, s, d0);
		}
	}
	net.minecraftforge.common.MinecraftForge.EVENT_BUS.post(new net.minecraftforge.client.event.RenderLivingEvent.Specials.Post<T>(entity, this, x, y, z));
}


 


Render::renderEntityName

Spoiler



protected void renderEntityName(T entityIn, double x, double y, double z, String name, double distanceSq)
{
	this.renderLivingLabel(entityIn, name, x, y, z, 64);
}


 

 

Render::renderLivingLabel

Spoiler

protected void renderLivingLabel(T entityIn, String str, double x, double y, double z, int maxDistance)
{
	double d0 = entityIn.getDistanceSqToEntity(this.renderManager.renderViewEntity);

	if (d0 <= (double)(maxDistance * maxDistance))
	{
		boolean flag = entityIn.isSneaking();
		float f = this.renderManager.playerViewY;
		float f1 = this.renderManager.playerViewX;
		boolean flag1 = this.renderManager.options.thirdPersonView == 2;
		float f2 = entityIn.height + 0.5F - (flag ? 0.25F : 0.0F);
		int i = "deadmau5".equals(str) ? -10 : 0;
		EntityRenderer.drawNameplate(this.getFontRendererFromRenderManager(), str, (float)x, (float)y + f2, (float)z, i, f, f1, flag1, flag);
	}
}

 

 

16 minutes ago, Draconwolver said:

Why does cancelling RenderLivingEvent.Specials.Pre<AbstractClientPlayer> prevent all nametags from showing, rather than just players?

 

Are you subscribing to RenderLivingEvent.Specials.Pre<AbstractClientPlayer> directly, or are you subscribing to RenderLivingEvent.Specials.Pre and checking if the entity is an instance of AbstractClientPlayer? Only the latter will work in this case.

 

Forge only performs generic filtering for events that implement IGenericEvent, which RenderLivingEvent.Specials.Pre doesn't. It's too expensive to do multiple times every frame, so it's generally only done for load-time events.

 

 

22 minutes ago, Draconwolver said:

What role does RenderPlayer::renderEntityName have in rendering player names? It seems to handle scores displayed under the player's name and then call Render::renderEntityName, which is also called by RenderLivingBase::renderName. So when a player's nametag needs to be rendered, which is called, RenderPlayer::renderEntityName or RenderLivingBase::renderName?

 

  • Render#doRender (which is called by every class that overrides it) calls Render#renderName.
  • RenderLivingBase overrides Render#renderName to fire RenderLivingEvent.Specials.Pre/Post and call Render#renderEntityName with the entity's display name.
  • Render#renderEntityName calls Render#renderLivingLabel to render its argument.
  • RenderPlayer overrides Render#renderEntityName to render the player's score with Render#renderLivingLabel and then call the super method.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

  • Author
1 hour ago, Choonster said:

 

Are you subscribing to RenderLivingEvent.Specials.Pre<AbstractClientPlayer> directly, or are you subscribing to RenderLivingEvent.Specials.Pre and checking if the entity is an instance of AbstractClientPlayer? Only the latter will work in this case.

 

Forge only performs generic filtering for events that implement IGenericEvent, which RenderLivingEvent.Specials.Pre doesn't. It's too expensive to do multiple times every frame, so it's generally only done for load-time events.

 

 

 

  • Render#doRender (which is called by every class that overrides it) calls Render#renderName.
  • RenderLivingBase overrides Render#renderName to fire RenderLivingEvent.Specials.Pre/Post and call Render#renderEntityName with the entity's display name.
  • Render#renderEntityName calls Render#renderLivingLabel to render its argument.
  • RenderPlayer overrides Render#renderEntityName to render the player's score with Render#renderLivingLabel and then call the super method.

Thanks, that was helpful. When I listen to the RenderLivingEvent.Specials.Pre event, should I suppress the raw type warning, or use something like RenderLivingEvent.Specials.Pre<? extends EntityLivingBase>?

4 minutes ago, Draconwolver said:

Thanks, that was helpful. When I listen to the RenderLivingEvent.Specials.Pre event, should I suppress the raw type warning, or use something like RenderLivingEvent.Specials.Pre<? extends EntityLivingBase>?

 

Either use a wildcard in the parameter declaration or give the method a generic type argument and use that in the parameter declaration.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.