Jump to content

[1.16.5] Rendering text in world (Like hologram text)


Recommended Posts

Hello, sometime ago I asked help on this same thing and I figured something out, but the method I'm using is coming with a few problems. Foremost, it entirely breaks when using Optifine Shaders (I used the internal ones). And second of all, while it does render text the exact way I want it to, it doesn't have the transparent background like entity names would. Is there any better way to achieve what I'm trying to achieve? (This is all client side)

Here is my current function: (I call it in RenderWorldLastEvent)

protected void renderNameTag(MathUtils.Point pos, ITextComponent text, MatrixStack ms, IRenderTypeBuffer buffer, float partialTicks, float yOffset) {
        Minecraft mc = Minecraft.getInstance();
        int combinedLightIn = mc.getEntityRenderDispatcher().getPackedLightCoords(mc.player, partialTicks);
        ms.translate(pos.getX(), yOffset, pos.getY());
        Quaternion q = mc.getEntityRenderDispatcher().cameraOrientation();
        ms.scale(-0.025F, -0.025F, 0.025F);
        Matrix4f matrix4f = ms.last().pose();
        float opacity = Minecraft.getInstance().options.getBackgroundOpacity(0.5F);
        int alpha = (int)(opacity * 255.0F) << 24;
        FontRenderer fontrenderer = Minecraft.getInstance().getEntityRenderDispatcher().getFont();
        float width = (float)(-fontrenderer.width(text) / 2);
        //fontrenderer.drawInBatch(text, f2, i, 553648127, false, matrix4f, buffer, false, j, p_225629_5_);

        //fontrenderer.drawInBatch(text, width, 0f, 553648127, false, matrix4f, buffer, false, alpha, combinedLightIn);
        fontrenderer.drawInBatch(text, width, 0f, -1, false, matrix4f, buffer, true, 0, combinedLightIn);


If you need any additional information, please ask.

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.

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.

  • Create New...

Important Information

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