Jump to content

Recommended Posts

Posted

Hello, so I am trying to render a nametag so serve as the purpose of a "waypoint". I created a function based on the code of how Minecraft renders nametags above players. The text seems to be appearing just "fine" and is placed correctly but there's a few problems:

1) The text itself is kind of hard to see. I tried figuring out how to change the opacity for example but I only managed to change the opacity of the box in its whole which did not help.

2) When I apply a color to my TextComponent, the color cannot be seen.

3) The text seems to be rotating in the wrong direction compared to the player's YAW.

Image of current result

-> As you can also see in the image, there's some weird thing going on with the lighting of the text. Some letters are rendered darker than the other based on my rotation.

Code: (The function below is the one I talked about earlier. The stuff in the event is just some circle calculations to calculate the position of where I want my waypoint rendered but also shows my parameters ofcourse)

@SubscribeEvent
    public void renderNametag(RenderWorldLastEvent event) {

        if (waypoint!=null) {
            Minecraft mc = Minecraft.getInstance();
            IRenderTypeBuffer.Impl renderTypeBuffer = Minecraft.getInstance().renderBuffers().bufferSource();
            TextComponent txt = new TranslationTextComponent("Test");
            txt.withStyle(TextFormatting.GREEN);

            //Pos Calc
            MathUtils.Point closest = null;
            MathUtils.Point targetPoint = new MathUtils.Point(waypoint.getX(), waypoint.getZ());
            int r = 5;
            for (MathUtils.Point point : MathUtils.getCircleLineIntersectionPoint(new MathUtils.Point(mc.player.xo, mc.player.zo), new MathUtils.Point(waypoint.getX(), waypoint.getZ()), new MathUtils.Point(mc.player.xo, mc.player.zo), r)) {
                if (closest==null || MathUtils.distance(targetPoint, point)<MathUtils.distance(targetPoint, closest)) {
                    closest = point;
                }
            }
            if (closest!=null) {
                renderNameTag(new MathUtils.Point(closest.getX()-mc.player.xo, closest.getY()-mc.player.zo), txt, event.getMatrixStack(), renderTypeBuffer, 0);
                return;
            }
            System.out.println("ERROR");
        }

    }

    protected void renderNameTag(MathUtils.Point pos, ITextComponent text, MatrixStack ms, IRenderTypeBuffer buffer, int p_225629_5_) {
        Minecraft mc = Minecraft.getInstance();
        float f = 0f;
        int i = 0;
        ms.pushPose();
        //ms.translate(pos.getX()-mc.player.xo, (double)f, pos.getZ()-mc.player.zo);
        ms.translate(pos.getX(), 0, pos.getY());
        //ms.translate(2, f, 0);
        Quaternion q = mc.getEntityRenderDispatcher().cameraOrientation();
        ms.mulPose(q);
        ms.scale(-0.025F, -0.025F, 0.025F);
        Matrix4f matrix4f = ms.last().pose();
        float f1 = Minecraft.getInstance().options.getBackgroundOpacity(0.5F);
        int j = (int)(f1 * 255.0F) << 24;
        FontRenderer fontrenderer = Minecraft.getInstance().font;
        float f2 = (float)(-fontrenderer.width(text) / 2);
        fontrenderer.drawInBatch(text, f2, i, 553648127, false, matrix4f, buffer, false, j, p_225629_5_);
        fontrenderer.drawInBatch(new StringTextComponent(""), f2, (float)i, /*553648127*/-1, false, matrix4f,buffer, true, 0, p_225629_5_);

        ms.popPose();
    }

 

If anyone knows how the FontRenderer#drawInBatch works, please help me because I'm having a tough time figuring it out.

Posted

Hi!

net.minecraft.client.renderer.debug.DebugRenderer has a method for rendering text in the air, it's called renderFloatingText

Sorry if my Posts are weird sometimes, I just try to help and learn as much as I can :D

Also: PLEASE use SPOILERS for logs!

Posted
2 hours ago, OutCraft said:

Hi!

net.minecraft.client.renderer.debug.DebugRenderer has a method for rendering text in the air, it's called renderFloatingText

I'm not sure if this is what I need though, when I use this function I get a result that's way off what I'm trying to achieve.

Posted
2 hours ago, OutCraft said:

renderFloatingText

just renders a "Name tag" in the air. You need it with color, right? 

Sorry if my Posts are weird sometimes, I just try to help and learn as much as I can :D

Also: PLEASE use SPOILERS for logs!

Posted
2 minutes ago, OutCraft said:

just renders a "Name tag" in the air. You need it with color, right? 

Yeah, I do. The code of how I adapted my event is below.

This gives however, like I said, a weird result. The text doesn't seem to be rendering in the 3D location I put it in but instead kinda floats about a fixed point and rotates in some weird ways.

Here's what I mean:

Image

@SubscribeEvent
    public void renderNametag(RenderWorldLastEvent event) {

        if (waypoint!=null) {
            Minecraft mc = Minecraft.getInstance();
            IRenderTypeBuffer.Impl renderTypeBuffer = Minecraft.getInstance().renderBuffers().bufferSource();
            TextComponent txt = new TranslationTextComponent("Test");
            txt.withStyle(TextFormatting.GREEN);

            //Pos Calc
            MathUtils.Point closest = null;
            MathUtils.Point targetPoint = new MathUtils.Point(waypoint.getX(), waypoint.getZ());
            int r = 5;
            for (MathUtils.Point point : MathUtils.getCircleLineIntersectionPoint(new MathUtils.Point(mc.player.xo, mc.player.zo), new MathUtils.Point(waypoint.getX(), waypoint.getZ()), new MathUtils.Point(mc.player.xo, mc.player.zo), r)) {
                if (closest==null || MathUtils.distance(targetPoint, point)<MathUtils.distance(targetPoint, closest)) {
                    closest = point;
                }
            }
            if (closest!=null) {
                DebugRenderer.renderFloatingText("test", closest.getX(), mc.player.yo, closest.getY(), 0xFFFFFF);
                //renderNameTag(new MathUtils.Point(closest.getX()-mc.player.xo, closest.getY()-mc.player.zo), txt, event.getMatrixStack(), renderTypeBuffer, 0);
                return;
            }
            System.out.println("ERROR");
        }

    }

 

Posted
5 minutes ago, KylM said:
DebugRenderer.renderFloatingText("test", closest.getX(), mc.player.yo, closest.getY(), 0xFFFFFF);

Why closest.getX() and closest.getY()? Just pass in waypoint.getX() and waypoint.getY()

Sorry if my Posts are weird sometimes, I just try to help and learn as much as I can :D

Also: PLEASE use SPOILERS for logs!

Posted
8 minutes ago, KylM said:
            //Pos Calc
            MathUtils.Point closest = null;
            MathUtils.Point targetPoint = new MathUtils.Point(waypoint.getX(), waypoint.getZ());
            int r = 5;
            for (MathUtils.Point point : MathUtils.getCircleLineIntersectionPoint(new MathUtils.Point(mc.player.xo, mc.player.zo), new MathUtils.Point(waypoint.getX(), waypoint.getZ()), new MathUtils.Point(mc.player.xo, mc.player.zo), r)) {
                if (closest==null || MathUtils.distance(targetPoint, point)<MathUtils.distance(targetPoint, closest)) {
                    closest = point;
                }
            }

I don't understand what you're calculating

Sorry if my Posts are weird sometimes, I just try to help and learn as much as I can :D

Also: PLEASE use SPOILERS for logs!

Posted
10 minutes ago, OutCraft said:

Why closest.getX() and closest.getY()? Just pass in waypoint.getX() and waypoint.getY()

After adapting I still get a weird result though. The text just seems to be doing about the same it was doing before. It rotates around and isn't in the position I want it in at all.

Just to clarify: the idea is that the text always faces the player (meaning it's not weirdly rotated away from the player) and always points to the "waypoint".

Posted
Just now, KylM said:

points to the "waypoint"

Points to the waypoint or is at the position of the waypoint? 

Sorry if my Posts are weird sometimes, I just try to help and learn as much as I can :D

Also: PLEASE use SPOILERS for logs!

Posted

Then look at how DebugRenderer renders the color and make the same in your renderNameTag function, if DebugRenderer isn't working for you 

Sorry if my Posts are weird sometimes, I just try to help and learn as much as I can :D

Also: PLEASE use SPOILERS for logs!

Posted
12 minutes ago, OutCraft said:

Then look at how DebugRenderer renders the color and make the same in your renderNameTag function, if DebugRenderer isn't working for you 

Yeah, but I'd still be stuck with my other 2 problems though.

Posted
20 minutes ago, OutCraft said:

Which problems? I thought your method is working 

Problems 1 and 3 mentioned in the OP:

1) The text itself is kind of hard to see. I tried figuring out how to change the opacity for example, but I only managed to change the opacity of the box in its whole which did not help.

3) The text seems to be rotating in the wrong direction compared to the player's YAW.

Posted (edited)

It seems that the following post seemed to be trying to do about the same as I am. It had a simple solution of using EntityRenderer#drawNameplate, but that function doesn't exist in 1.16.5, and I can't find any renames or alternatives for it except for the original method I mentioned in my OP, but that method is protected and requires an entity.

 

Edited by KylM
Posted
2 hours ago, OutCraft said:

Sorry but I really have no Idea :(

Yeah, no problem, I'm just trying to see if anyone else on the forum knows any solutions since I really can't figure this out.

Posted

I think you want to use some magic number like 0xF00000 or 0xF000F0 for the packedLight instead of 0, but I'm not sure, and I also don't know much about the packedLight system

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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Sorry for the late response, but the game opened and I made a world but it's stuck at 0% Here's the latest.log https://mclo.gs/peEb1R8 I disabled The Factory Must Grow and soulsweapons
    • Hey everyone! Two of my friends downloaded this modpack and are having an issue with the blocks loading in correctly. Grass looks like bamboo, waystones look like two barrels stacked on eachother, and wheat looks like water and stairs. What is this problem? How can we fix it? Neither of my other friends or myself had this issue. 
    • I removed Yung's cave biome mod and It wasnt in one of those biomes however the log file said the same line (([25Apr2025 21:20:15.500] [Flywheel Task Executor #5/WARN] [Embeddium-MixinTaintDetector/]: Mod(s) [oculus] are modifying Embeddium class me.jellysquid.mods.sodium.client.render.vertex.serializers.VertexSerializerRegistryImpl, which may cause instability.))
    • Note: i had a couple of ideas, but i just don't know how to execute them. The main idea was to make the new block (let's exemplify with a mixer) be essentially a clone of the mechanical mixer (different texture tho) that would have a different recipe type (instead of mixing, advanced_mixing) and i would copy all the create mod recipes and edit the processing time while also adding the tier dependent ones.
    • Hi! Before everything, thank you for even reading. I'm coming here in need of help making a few aspects for a create mod addon. It's an addon that aims to add almost the full periodic table with realistic ways of obtaining all the elements and capability of almost full automation. For what purpose? A techy armor and to go to the moon and rocky planets of the solar system. It'll have 3 different tiers of machines (mixer, millstone, crushing wheels): basic (just the normal create mod machines but renamed), advanced (25% faster and has recipes only possible for this tier and above) end elite (75% faster than basic and recipes only available for this tier). The problem is, I'm not a coder. I know less than the basics. I know how to do everything else but these machine tiers and i need some help if you can.
  • Topics

  • Who's Online (See full list)

×
×
  • Create New...

Important Information

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