
KylM
Members-
Posts
21 -
Joined
-
Last visited
Everything posted by KylM
-
[1.16.5] Rendering text in world (Like hologram text)
KylM replied to KylM's topic in Modder Support
bump -
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.pushPose(); ms.translate(pos.getX(), yOffset, pos.getY()); Quaternion q = mc.getEntityRenderDispatcher().cameraOrientation(); ms.mulPose(q); 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); ms.popPose(); } If you need any additional information, please ask.
-
Oh, thanks. This also indeed fixed my texture problem. Thank you very much.
-
Alright, but how would I get the root NBT tag of an ItemStack? If I just use #getOrCreateTag it will just give me the tag and not the item ID etc right?
-
Okay let me explain a bit further: So the idea is you create a gui, it will then store all items from the gui as json and then you can load the exact same gui again. If that makes sense. As for how I create the ItemStack: ItemStack item = ItemStack.of(JsonToNBT.parseTag(itemObject.toString())); with itemObject being a JsonObject (the JSON for example showed in my OP)
-
Do you mean when going from ItemStack to JSON or from JSON to ItemStack?
-
I read them from a file, it's supposed to be like a customizable thing.
-
Because I have a bunch of JSON data of items and I want to turn them into actual ItemStacks. JsonToNBT is the first working class I found that does this.
-
[1.16.5] Hello, when I parse a JSON string to an ItemStack using JsonToNBT#parseTag with JSON seen beneath, the texture of the skull does not get applied. Any way to fix this? All other attributes / properties are being applied just fine. Here is the JSON I am using: { "id": "player_head", "Count": 1, "tag": { "CustomModelData": 100001, "HideFlags": -1, "SkullOwner": { "Id": [ 1334301174, 1630424667, -1957730237, 1373073981 ], "Properties": { "textures": [ { "Value": "ewogICJ0aW1lc3RhbXAiIDogMTYwMTU4MDc5MjcyMiwKICAicHJvZmlsZUlkIiA6ICJlZDUzZGQ4MTRmOWQ0YTNjYjRlYjY1MWRjYmE3N2U2NiIsCiAgInByb2ZpbGVOYW1lIiA6ICIwMTAwMDExMDAxMDAwMDExIiwKICAic2lnbmF0dXJlUmVxdWlyZWQiIDogdHJ1ZSwKICAidGV4dHVyZXMiIDogewogICAgIlNLSU4iIDogewogICAgICAidXJsIiA6ICJodHRwOi8vdGV4dHVyZXMubWluZWNyYWZ0Lm5ldC90ZXh0dXJlL2FmMzgyMzQ1ZmQ3OWZjNzgzNjFjNjFjOTYyMzBjNjk0YzM0NDc5MzU4YWMwYWU0OWM0ZGI3YTYyNGE1YWZlNTQiCiAgICB9CiAgfQp9" } ] } }, "display": { "Name": "{\"italic\":false,\"color\":\"yellow\",\"text\":\"Next \\u003e\"}" } } } Kind regards, Kyllian
-
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.
-
I'm not sure if bumping is allowed on this forum, if not sorry. But was just wondering if anyone else got any ideas?
-
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.
-
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.
-
Yeah, but I'd still be stuck with my other 2 problems though.
-
Well either would work I guess.
-
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".
-
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"); } }
-
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.
-
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.