Jump to content

Recommended Posts

Posted

Is there any way to add a name tag-type-thing to a block, where the name hovers over it? How would I do so?

 

Note: I would like to be able to do this to any block, even vanilla ones

 

Thanks

Creator of the MyFit, MagiCraft, Tesseract gun, and Papa's Wingeria mod.

Posted

1) Where would I get the instance of the block that should have a name tag?

2) Do I need to make a new renderer that renders name tags for blocks?

Creator of the MyFit, MagiCraft, Tesseract gun, and Papa's Wingeria mod.

Posted

So I copy pasted the renderLivingLabel from Render and tweaked it for a block:

FontRenderer fontrenderer = Minecraft.getMinecraft().fontRendererObj;
				int x = pos.getX();
				int y = pos.getY();
				int z = pos.getZ();
				RenderManager renderManager = Minecraft.getMinecraft().getRenderManager();
	            float f = 1.6F;
	            float f1 = 0.016666668F * f;
	            GlStateManager.pushMatrix();
	            GlStateManager.translate((float)x + 0.0F, (float)y + 1, (float)z);
	            GL11.glNormal3f(0.0F, 1.0F, 0.0F);
	            GlStateManager.rotate(-renderManager.playerViewY, 0.0F, 1.0F, 0.0F);
	            GlStateManager.rotate(renderManager.playerViewX, 1.0F, 0.0F, 0.0F);
	            GlStateManager.scale(-f1, -f1, f1);
	            GlStateManager.disableLighting();
	            GlStateManager.depthMask(false);
	            GlStateManager.disableDepth();
	            GlStateManager.enableBlend();
	            GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0);
	            Tessellator tessellator = Tessellator.getInstance();
	            WorldRenderer worldrenderer = tessellator.getWorldRenderer();
	            int i = 0;

	            if (str.equals("deadmau5"))
	            {
	                i = -10;
	            }

	            int j = fontrenderer.getStringWidth(str) / 2;
	            GlStateManager.disableTexture2D();
	            worldrenderer.begin(7, DefaultVertexFormats.POSITION_COLOR);
	            worldrenderer.pos((double)(-j - 1), (double)(-1 + i), 0.0D).color(0.0F, 0.0F, 0.0F, 0.25F).endVertex();
	            worldrenderer.pos((double)(-j - 1), (double)(8 + i), 0.0D).color(0.0F, 0.0F, 0.0F, 0.25F).endVertex();
	            worldrenderer.pos((double)(j + 1), (double)(8 + i), 0.0D).color(0.0F, 0.0F, 0.0F, 0.25F).endVertex();
	            worldrenderer.pos((double)(j + 1), (double)(-1 + i), 0.0D).color(0.0F, 0.0F, 0.0F, 0.25F).endVertex();
	            tessellator.draw();
	            GlStateManager.enableTexture2D();
	            fontrenderer.drawString(str, -fontrenderer.getStringWidth(str) / 2, i, 553648127);
	            GlStateManager.enableDepth();
	            GlStateManager.depthMask(true);
	            fontrenderer.drawString(str, -fontrenderer.getStringWidth(str) / 2, i, -1);
	            GlStateManager.enableLighting();
	            GlStateManager.disableBlend();
	            GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
	            GlStateManager.popMatrix();

 

But nothing shows up. I have declared pos and str elsewhere and I'm sure it's being called. What am I doing wrong?

Creator of the MyFit, MagiCraft, Tesseract gun, and Papa's Wingeria mod.

Posted

Ah ok thanks, for all wondering, here is the final code:

FontRenderer fontrenderer = Minecraft.getMinecraft().fontRendererObj;
				EntityPlayer player = Minecraft.getMinecraft().thePlayer;
				double x = ((pos.getX() - player.posX) + 0.5) ;
				double y = ((pos.getY() - player.posY) + 0.5);
				double z = ((pos.getZ() - player.posZ) + 0.5);
				RenderManager renderManager = Minecraft.getMinecraft().getRenderManager();
	            float f = 1.6F;
	            float f1 = 0.016666668F * f;
	            GlStateManager.pushMatrix();
	            GlStateManager.translate((float)x + 0.0F, (float)y + 1, (float)z);
	            GL11.glNormal3f(0.0F, 1.0F, 0.0F);
	            GlStateManager.rotate(-renderManager.playerViewY, 0.0F, 1.0F, 0.0F);
	            GlStateManager.rotate(renderManager.playerViewX, 1.0F, 0.0F, 0.0F);
	            GlStateManager.scale(-f1, -f1, f1);
	            GlStateManager.disableLighting();
	            GlStateManager.depthMask(false);
	            GlStateManager.disableDepth();
	            GlStateManager.enableBlend();
	            GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0);
	            Tessellator tessellator = Tessellator.getInstance();
	            WorldRenderer worldrenderer = tessellator.getWorldRenderer();
	            int i = 0;

	            if (str.equals("deadmau5"))
	            {
	                i = -10;
	            }

	            int j = fontrenderer.getStringWidth(str) / 2;
	            GlStateManager.disableTexture2D();
	            worldrenderer.begin(7, DefaultVertexFormats.POSITION_COLOR);
	            worldrenderer.pos((double)(-j - 1), (double)(-1 + i), 0.0D).color(0.0F, 0.0F, 0.0F, 0.25F).endVertex();
	            worldrenderer.pos((double)(-j - 1), (double)(8 + i), 0.0D).color(0.0F, 0.0F, 0.0F, 0.25F).endVertex();
	            worldrenderer.pos((double)(j + 1), (double)(8 + i), 0.0D).color(0.0F, 0.0F, 0.0F, 0.25F).endVertex();
	            worldrenderer.pos((double)(j + 1), (double)(-1 + i), 0.0D).color(0.0F, 0.0F, 0.0F, 0.25F).endVertex();
	            tessellator.draw();
	            GlStateManager.enableTexture2D();
	            fontrenderer.drawString(str, -fontrenderer.getStringWidth(str) / 2, i, 553648127);
	            GlStateManager.enableDepth();
	            GlStateManager.depthMask(true);
	            fontrenderer.drawString(str, -fontrenderer.getStringWidth(str) / 2, i, -1);
	            GlStateManager.enableLighting();
	            GlStateManager.disableBlend();
	            GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
	            GlStateManager.popMatrix();

Creator of the MyFit, MagiCraft, Tesseract gun, and Papa's Wingeria mod.

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.