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 create command to renderNameTag and is not perfetcly.

 

Text is rear of entity or no.

width=800 height=450IoQrmSw.png?1 [/img]

 

	public static void renderName(Entity entity, String string, int distance, float partialTicks)
{
	RenderManager renderManager = Minecraft.getMinecraft().getRenderManager();
	Entity player = Minecraft.getMinecraft().getRenderViewEntity();
	FontRenderer fontRenderer = renderManager.getFontRenderer();
	Tessellator tessellator = Tessellator.getInstance();
	WorldRenderer worldRenderer = tessellator.getWorldRenderer();

	double d3 = Utils.getDistanceBetweenBlocks(player.getPosition(), entity.getPosition());

	if (d3 <= (double)(distance))
	{
		float scale = (float) (0.016666668F * getDistanceScalled(d3));
		int string_length = fontRenderer.getStringWidth(string) / 2;

		double playerX = player.lastTickPosX + (player.posX - player.lastTickPosX);
		double playerY = player.lastTickPosY + (player.posY - player.lastTickPosY);
		double playerZ = player.lastTickPosZ + (player.posZ - player.lastTickPosZ);
		double entityX = entity.lastTickPosX + (entity.posX - entity.lastTickPosX);
		double entityY = entity.lastTickPosY + (entity.posY - entity.lastTickPosY);
		double entityZ = entity.lastTickPosZ + (entity.posZ - entity.lastTickPosZ);
		double diffX = entityX - playerX * (double) partialTicks;
		double diffY = entityY - playerY * (double) partialTicks;
		double diffZ = entityZ - playerZ * (double) partialTicks;

		GlStateManager.pushMatrix();

		GlStateManager.translate(diffX + 0.0D, diffY + (entity.height + 0.75D), diffZ);
		GlStateManager.rotate(-player.rotationYaw, 0.0F, 1.0F, 0.0F);
		GlStateManager.rotate(player.rotationPitch, 1.0F, 0.0F, 0.0F);
		GlStateManager.scale(-scale, -scale, scale);

		GlStateManager.depthMask(false);
		GlStateManager.disableTexture2D();
		GlStateManager.disableLighting();
		GlStateManager.disableBlend();

		Minecraft.getMinecraft().ingameGUI.drawRect(-string_length - 2, -2, fontRenderer.getStringWidth(string) + 1 -string_length, fontRenderer.FONT_HEIGHT, 0x50000000);
		Minecraft.getMinecraft().ingameGUI.drawRect(-string_length - 1, -1, fontRenderer.getStringWidth(string) -string_length, fontRenderer.FONT_HEIGHT - 1, 0x50FF0000);
		fontRenderer.drawString(string, -string_length, 0, -1);

		GlStateManager.enableTexture2D();
		GlStateManager.enableLighting();
		GlStateManager.disableBlend();
		GlStateManager.depthMask(true);

		GlStateManager.popMatrix();
	}
}

 

I use in public void onRenderLiving(RenderLivingEvent.Post event).

  • 6 months later...

Hi,

 

I want to draw a nametag on a given position in the World:

 

 

	

/**
* x,y,z the Position(BlockPos)
* string, the String to render
*/

public static void renderName(double x, double y, double z, String string, float partialTicks){

	RenderManager renderManager = Minecraft.getMinecraft().getRenderManager();
	Entity player = Minecraft.getMinecraft().thePlayer;
	FontRenderer fontRenderer = renderManager.getFontRenderer();
	//Tessellator tessellator = Tessellator.getInstance();

	//float scale = (float) (0.016666668F * getDistanceScalled(d3));
	int string_length = fontRenderer.getStringWidth(string) / 2;

	double playerX = player.lastTickPosX + (player.posX - player.lastTickPosX);
	double playerY = player.lastTickPosY + (player.posY - player.lastTickPosY);
	double playerZ = player.lastTickPosZ + (player.posZ - player.lastTickPosZ);

	double diffX = x - playerX * (double) partialTicks;
	double diffY = y - playerY * (double) partialTicks;
	double diffZ = z - playerZ * (double) partialTicks;

	GlStateManager.pushMatrix();

	GlStateManager.translate(diffX, diffY + 2D, diffZ);
	GlStateManager.rotate(-player.rotationYaw, 0.0F, 1.0F, 0.0F);
	GlStateManager.rotate(player.rotationPitch, 1.0F, 0.0F, 0.0F);
	//GlStateManager.scale(-scale, -scale, scale);

	GlStateManager.depthMask(false);
	GlStateManager.disableTexture2D();
	GlStateManager.disableLighting();
	GlStateManager.disableBlend();

	//Minecraft.getMinecraft().ingameGUI.drawRect(-string_length - 2, -2,fontRenderer.getStringWidth(string) + 1 - string_length, fontRenderer.FONT_HEIGHT, 0x50000000);
	//Minecraft.getMinecraft().ingameGUI.drawRect(-string_length - 1, -1,fontRenderer.getStringWidth(string) - string_length, fontRenderer.FONT_HEIGHT - 1, 0x50FF0000);
	fontRenderer.drawString(string, -string_length, 0, -1);

	GlStateManager.enableTexture2D();
	GlStateManager.enableLighting();
	GlStateManager.disableBlend();
	GlStateManager.depthMask(true);
	GlStateManager.popMatrix();
}

 

 

The problem is, that the string is buzzing around and other self definded things to render are gray now... Whats the mistake?

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

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.