Jump to content

Recommended Posts

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

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

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