Posted December 14, 20213 yr 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.
December 14, 20213 yr 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 Also: PLEASE use SPOILERS for logs!
December 14, 20213 yr Author 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.
December 14, 20213 yr 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 Also: PLEASE use SPOILERS for logs!
December 14, 20213 yr Author 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"); } }
December 14, 20213 yr 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 Also: PLEASE use SPOILERS for logs!
December 14, 20213 yr 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 Also: PLEASE use SPOILERS for logs!
December 14, 20213 yr Author 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".
December 14, 20213 yr 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 Also: PLEASE use SPOILERS for logs!
December 14, 20213 yr Author 6 minutes ago, OutCraft said: Points to the waypoint or is at the position of the waypoint? Well either would work I guess.
December 14, 20213 yr 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 Also: PLEASE use SPOILERS for logs!
December 14, 20213 yr Author 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.
December 14, 20213 yr Which problems? I thought your method is working Sorry if my Posts are weird sometimes, I just try to help and learn as much as I can Also: PLEASE use SPOILERS for logs!
December 14, 20213 yr Author 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.
December 14, 20213 yr Author 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 December 14, 20213 yr by KylM
December 16, 20213 yr Author I'm not sure if bumping is allowed on this forum, if not sorry. But was just wondering if anyone else got any ideas?
December 24, 20213 yr Sorry but I really have no Idea Sorry if my Posts are weird sometimes, I just try to help and learn as much as I can Also: PLEASE use SPOILERS for logs!
December 24, 20213 yr Author 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.
December 28, 20213 yr 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.