Jump to content

1.16.5 Rotate text behind the player's camera.


idev

Recommended Posts

Hello, I have been suffering for 6 hours and cannot find a good, working solution.

I need the text above the creature to always face the camera. I went through a lot of code examples and even tried to find the source code of the tag item in the game and render it. But I didn't find anything I needed.

As far as I understand, the new version does not have MatrixStack.rotate, I need it judging by the examples. I tried GlStateManager and don't know how to pass the required matrixStack to fontRenderer.draw (matrixStack, ...)

What should I do? Now I stopped at the option that is shown in the code below, but it does not do what I need.

@Mod.EventBusSubscriber(modid = XCraft.MODID, value = Dist.CLIENT)
public class ClientEventHandler {
    @SubscribeEvent
    public static void potion(RenderLivingEvent.Post<? extends LivingEntity, ? extends EntityModel<?>> event) {
        HealthBar.renderInWorld(event.getMatrixStack(), event.getEntity());
    }
}


public class HealthBar {
    public static void renderInWorld(MatrixStack matrixStack, LivingEntity entity) {
        ClientPlayerEntity playerEntity = Minecraft.getInstance().player;
        assert playerEntity != null;

        FontRenderer fontRenderer = Minecraft.getInstance().font;
        assert fontRenderer != null;

        ITextComponent name = entity.getName();
        fontRenderer.draw(matrixStack, name,  0, 0, 0xffffff);
    }
}

12.png

13.png

Edited by idev
Link to comment
Share on other sites

I don't know how, but setting: mappings channel: 'snapshot', version: '20210309-1.16.5' build.gradlew helped me. In short, I deployed the project on a new one and it all worked. I thought it was a bug or a flaw, maybe it is

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.

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.