Jump to content

Recommended Posts

Posted

Hi.

I am working on a mod and wanted to render some text during the LevelLastRenderEvent. I am trying to draw the Text using Minecraft.getInstance().font.draw(), by passing in the PoseStack from the event, as well as my Text.

For some reason I can't get it to actually render anything.
I am not quite sure what the x and y coordinates mean, that the method requires, but I tried many different values. I also looked at some other mods and tried to find an example of this actually being done, but I haven't really found something helpful...
Are the x and y parameters of the function world coordinates (like block coordinates) or are they relative to something else?

Ho do I find the correct coordinates to use?

Also, why is it not rendering anything at all for me right now?

 

Here is how I am trying to render the text at the moment.

PoseStack matrixStack = event.getPoseStack();

String text = "Collectable XP: ";
text += entity.getCollectedXP();

LogHelper.info("Render: " + text);

matrixStack.pushPose();

matrixStack.scale(1, 1, 1);

instance.font.draw(matrixStack, text, 7, 100, 0xffffff);

matrixStack.popPose();

This is inside an eventhandler for the LevelLastRenderEvent and with the LogHelper printing it to the log, I can see that it is definitively getting to this point and executing it.

The logging of this is just temporary, so I know that its actually trying to render...

Posted

For 1.18? See OverlayRegistry for how to register an IIngameOverlay as part of the in game gui.

e.g. see ForgeInGameGui.HUD_TEXT that draws the debug text when you press F3 (amongst other things).

 

If you really do want to draw text in the world, look at the some vanilla code that does this, e.g. EntityRenderer.renderNameTag()

Boilerplate:

If you don't post your logs/debug.log we can't help you. For curseforge you need to enable the forge debug.log in its minecraft settings. You should also post your crash report if you have one.

If there is no error in the log file and you don't have a crash report then post the launcher_log.txt from the minecraft folder. Again for curseforge this will be in your curseforge/minecraft/Install

Large files should be posted to a file sharing site like https://gist.github.com  You should also read the support forum sticky post.

Posted

Yes. It is for 1.18.2.

I do want to render the text in world, as the text will show some data about a specific type of blockentity.

Basically I want to draw some text above the block, when it is being looked at by the player. The text will show information about the blockentity.

I have looked at EntityRenderer.renderNameTag() now, but I am still having problems.

Unfortunately all the parameters in both the renderNameTag method, as well as all of the methods of the Font class do not have meaningful names, which makes it a lot harder to find out how something is working. I am still not sure what some of the parameters do.

I have now tried to use the method font.drawInBatch instead of font.draw, as this is what the renderNameTag method uses, but I still can't get any text to actually show up ingame.

Posted

This isn't really my area of expertise but..

 

You will need to do more than just drawing the text, you also need to change the pose (translate, rotate, etc.) to match where to draw it in the world.

e.g. for the entity rendering this is done in the EntityRendererDispatcher.render(). But renderNameTag() makes some additional changes so the text is correctly aligned to the camera.

 

For blocks I guess you can get the basic logic by looking at where it calls BlockEntityRendererDispatcher.render() in LevelRenderer.render().

 

Boilerplate:

If you don't post your logs/debug.log we can't help you. For curseforge you need to enable the forge debug.log in its minecraft settings. You should also post your crash report if you have one.

If there is no error in the log file and you don't have a crash report then post the launcher_log.txt from the minecraft folder. Again for curseforge this will be in your curseforge/minecraft/Install

Large files should be posted to a file sharing site like https://gist.github.com  You should also read the support forum sticky post.

Posted

If it just for the block being looked at, you might find subscribing for DrawSelectionEvent.HightlightBlock more useful? 

Boilerplate:

If you don't post your logs/debug.log we can't help you. For curseforge you need to enable the forge debug.log in its minecraft settings. You should also post your crash report if you have one.

If there is no error in the log file and you don't have a crash report then post the launcher_log.txt from the minecraft folder. Again for curseforge this will be in your curseforge/minecraft/Install

Large files should be posted to a file sharing site like https://gist.github.com  You should also read the support forum sticky post.

Posted
  On 8/11/2022 at 8:26 PM, warjort said:

If it just for the block being looked at, you might find subscribing for DrawSelectionEvent.HightlightBlock more useful? 

Expand  

I will look into that.

 

I looked further into the renderNameTag method and also where it is being called from.

I still don't know 100% how everything works, but the renderNameTag method only translates the pose only by adjusting the y value of it. It does not modify the y and z translation.

So I tried doing essentially the same: translating in the y direction and leaving  x and z as is. I also adjusted the text to the camera, similar to the way it is done in renderNameTag.

 

I also looked at another project of mine, where I rendered a block in the world, that isn't actually there, but that project uses getActiveRenderInfo().getProjectedView() in the translation. This other project is sitting in 1.16.5 and there it works, but the ActiveRenderInfo class does not exist anymore and I can't find anything that would be the equivalent to getProjectedView() in 1.18.2.

I still havent been able to get it to work.

My code looks like this now:

                    PoseStack matrixStack = event.getPoseStack();

                    String text = "Collectable XP: ";
                    text += entity.getCollectedXP();

                    LogHelper.info("Render: " + text);

                    matrixStack.pushPose();

                    matrixStack.scale(1, 1, 1);

                    matrixStack.translate(0, 1, 0);

                    matrixStack.mulPose(instance.getEntityRenderDispatcher().cameraOrientation());

                    MultiBufferSource bufferSource = instance.renderBuffers().bufferSource();

                    int packedLight = instance.getEntityRenderDispatcher().getPackedLightCoords(playerIn, 0);

                    //instance.font.draw(matrixStack, text, 7, 80, 0xffffff);
                    instance.font.drawInBatch(text, 7, 10, 0x20ffffff, false, matrixStack.last().pose(), bufferSource, false, 0, packedLight);

                    matrixStack.popPose();

 

Posted
  Quote

So I tried doing essentially the same: translating in the y direction and leaving  x and z as is. I also adjusted the text to the camera, similar to the way it is done in renderNameTag.

Expand  

It moves it up by the height of the entity model + half a block and it also does the mulPose and scale.

You are missing the part where it initially translates to the block position, see my comments above. 

 

This doesn't make sense to me.

  Quote

matrixStack.mulPose(instance.getEntityRenderDispatcher().cameraOrientation());

Expand  

This is just the value of camera.rotation() in the last call to EntityRenderDispatcher().prepare()

I doubt this is intended to be used outside the entity rendering calls themselves.

 

Also, if you use the HighlightBlock event you will be given a buffer source in the event state.

You also get a camera.

 

See this thread for tools/info to help translate old mods to the newer versions.

https://forums.minecraftforge.net/topic/115137-1192-translating-classesmethods-from-1165/

 

Boilerplate:

If you don't post your logs/debug.log we can't help you. For curseforge you need to enable the forge debug.log in its minecraft settings. You should also post your crash report if you have one.

If there is no error in the log file and you don't have a crash report then post the launcher_log.txt from the minecraft folder. Again for curseforge this will be in your curseforge/minecraft/Install

Large files should be posted to a file sharing site like https://gist.github.com  You should also read the support forum sticky post.

Posted
  On 8/11/2022 at 9:43 PM, warjort said:

You are missing the part where it initially translates to the block position, see my comments above.

Expand  

Can you show me where that is actually done in the game code?

If I look at the EntityRenderer class I can only find a single call to translate(), which is the one that moves it to the correct height.

 

  On 8/11/2022 at 9:43 PM, warjort said:

Also, if you use the HighlightBlock event you will be given a buffer source in the event state.

You also get a camera.

Expand  

Yes, I see that. I have now moved my code to the HighlightBlock event and inside the mulPose() call I now have event.getCamera.getRotation(). I also adjusted everything else to use the additional information availbale through that event.

 

I also tried to translate the pose to the block position, but it didn't fix the problem. I also couldn't see that being done anywhere in the vanilla code, so I assumed it was not neccessary....

Posted

Forget the EntityRenderer (it was EntityRendererDispatcher anyway). I was just using that to explain the translation is in 2 steps.

* Step 1 - translate to the relative entity/block position

* Step 2 - do additional block/entity specific changes like moving the name plate upwards (inside the Renderer)

 

It is done this way so people that write BlockEntityRenderers or EntityRenderers don't have to deal with step 1. It is done for them.

You have neither, so you need to do both steps.

 

As I said above, an example of the code you want is in the LevelRenderer for the BlockEntityRenderDispatcher (d0, d1, d2 are the x,y,z of the camera)

If you are going to force me to feed it to you on a spoon...

  Quote


            BlockPos blockpos3 = blockentity.getBlockPos();
            p_109600_.pushPose();

 

            // HERE
            p_109600_.translate((double)blockpos3.getX() - d0, (double)blockpos3.getY() - d1, (double)blockpos3.getZ() - d2);
 

          this.blockEntityRenderDispatcher.render(blockentity, p_109601_, p_109600_, multibuffersource$buffersource);
            p_109600_.popPose();
 

Expand  

 

Boilerplate:

If you don't post your logs/debug.log we can't help you. For curseforge you need to enable the forge debug.log in its minecraft settings. You should also post your crash report if you have one.

If there is no error in the log file and you don't have a crash report then post the launcher_log.txt from the minecraft folder. Again for curseforge this will be in your curseforge/minecraft/Install

Large files should be posted to a file sharing site like https://gist.github.com  You should also read the support forum sticky post.

Posted

As I said above, this is not my area of expertise. There is something of the blind leading the blind here. 🙂

Boilerplate:

If you don't post your logs/debug.log we can't help you. For curseforge you need to enable the forge debug.log in its minecraft settings. You should also post your crash report if you have one.

If there is no error in the log file and you don't have a crash report then post the launcher_log.txt from the minecraft folder. Again for curseforge this will be in your curseforge/minecraft/Install

Large files should be posted to a file sharing site like https://gist.github.com  You should also read the support forum sticky post.

Posted

Ok. I think I understand it now.

The pose is translated first by the difference between camera and block position to move it to where the block is. Then it is translated upwards, so it is above the block/entity and not inside it.

I am doing that now, but it still doesn't fix the problem...

PoseStack matrixStack = event.getPoseStack();

String text = "Collectable XP: ";
text += entity.getCollectedXP();

LogHelper.info("Render: " + text);

matrixStack.pushPose();

Vec3 cameraPosition = event.getCamera().getPosition();

matrixStack.translate((double)hitPos.getX() - cameraPosition.x, (double)hitPos.getY() - cameraPosition.y, (double)hitPos.getZ() - cameraPosition.z);

matrixStack.scale(1, 1, 1);

matrixStack.translate(0, 1.5, 0);

matrixStack.mulPose(event.getCamera().rotation());

MultiBufferSource bufferSource = event.getMultiBufferSource();

int packedLight = instance.getEntityRenderDispatcher().getPackedLightCoords(instance.player, event.getPartialTicks());

//instance.font.draw(matrixStack, text, 7, 80, 0xffffff);
instance.font.drawInBatch(text, 7, 10, 0x20ffffff, false, matrixStack.last().pose(), bufferSource, false, 0, packedLight);

matrixStack.popPose();

It still doesn't draw the text ingame.

 

I think I understand how most of the game works, but all the graphics and rendering stuff is still somewhat beyond my understanding...

 

  On 8/11/2022 at 10:54 PM, warjort said:

As I said above, this is not my area of expertise. There is something of the blind leading the blind here. 🙂

Expand  

Well, we can hope that someone else, who understands this better, picks up this thread and helps us out...

Posted (edited)

I had a go at implementing something like what you are doing, this is what I came up with based on your code:

    public static void highlightBlock(DrawSelectionEvent.HighlightBlock event) {
        Minecraft instance = Minecraft.getInstance();
        BlockHitResult hit = event.getTarget();
        Vec3 pos = hit.getLocation();
        Component text = new TextComponent("test");

        PoseStack matrixStack = event.getPoseStack();
        matrixStack.pushPose();
        Vec3 cameraPosition = event.getCamera().getPosition();
        Quaternion rotation = event.getCamera().rotation();
        matrixStack.translate((double) pos.x - cameraPosition.x, (double) pos.y - cameraPosition.y, (double) pos.z - cameraPosition.z);
        matrixStack.scale(-0.025F, -0.025F, -0.025F);
        matrixStack.mulPose(rotation);

        Font font = instance.font;
        float f2 = (float)(-font.width(text) / 2);
        MultiBufferSource bufferSource = event.getMultiBufferSource();
        int packedLight = instance.getEntityRenderDispatcher().getPackedLightCoords(instance.player, event.getPartialTicks());
        instance.font.drawInBatch(text, f2, 0f, -1, false, matrixStack.last().pose(), bufferSource, false, 0, packedLight);
        matrixStack.popPose();
    }

This is not perfect since it actually draws the text kind of inside the block. Something you can see is especially a problem when you look at solid block from above.

I'm sure you can fix this and other shortcomings. 🙂

Edited by warjort

Boilerplate:

If you don't post your logs/debug.log we can't help you. For curseforge you need to enable the forge debug.log in its minecraft settings. You should also post your crash report if you have one.

If there is no error in the log file and you don't have a crash report then post the launcher_log.txt from the minecraft folder. Again for curseforge this will be in your curseforge/minecraft/Install

Large files should be posted to a file sharing site like https://gist.github.com  You should also read the support forum sticky post.

Posted

I got it to work now!

The problem apperently was the scaling of the matrixStack. For some reason with the matrixStack.scale(1, 1, 1) it does not create any text at all, but as soon as I changed it to -0.025F, it worked!

That was the only change required to make it work in some capacity. I later made some other changes to, but they were not neccersary to make the text show up ingame.

I have no idea why that is the case, as I thought, the text would simply be way to big, if the scale was of...

Seing as it needs a negative scale, maybe scaling it to 1, 1, 1 made the text super small. So small that it wasnt visible....

 

Also: any translation should be done before the scaling, otherwise its way off...

 

Thanks for the help!

Posted (edited)

A negative scaling means a reflection and I guess the reflection in the y direction is because world coords are "updside down" compared to screen coords (which I think is what the font drawing uses?)

 

I tried your 1,1,1 scaling and it is drawing the text, just not where you can see it in first person. You can see the bottom of the backwards large text when you press F5. 🙂

Edited by warjort

Boilerplate:

If you don't post your logs/debug.log we can't help you. For curseforge you need to enable the forge debug.log in its minecraft settings. You should also post your crash report if you have one.

If there is no error in the log file and you don't have a crash report then post the launcher_log.txt from the minecraft folder. Again for curseforge this will be in your curseforge/minecraft/Install

Large files should be posted to a file sharing site like https://gist.github.com  You should also read the support forum sticky post.

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

    • I am using Linux, I did Java --version and it shows I have Java 8 installed
    • Temu Coupon Code $100 Off [acu639380] For The USA This Month  Temu has become a go-to platform for online shopping in recent years, offering a vast selection of trendy items at unbeatable prices. With amazing discounts like the  Temu coupon code (acu639380) offering up to $100 Off for new users and exclusive offers for existing customers,  Temu is quickly cementing itself as a favorite among online shoppers. Whether you're looking for stylish fashion pieces, home essentials, or the latest gadgets, using  Temu 's promotional codes can help you save big on your purchases. In this blog, we’ll dive into all the incredible savings available this month, including details on the  Temu coupon codes (acu639380), which provide discounts like $100 Off for new and existing users, an additional 40% off, and even free gifts for first-time users. No matter where you’re located—whether in the United States, Canada, the UK, or beyond— Temu offers something for everyone. If you're looking to save money on your next shopping spree, keep reading to learn about all the best deals, discounts, and coupon codes you can use in June 2025. What is  Temu ? Before we dive into the details of the amazing  Temu coupon codes (acu639380), let’s first explore what  Temu is all about.  Temu is an online shopping platform that offers a massive range of products, from fashion and beauty items to home goods and electronics. With unbeatable prices, fast delivery, and free shipping to over 67 countries,  Temu is revolutionizing the way we shop online.  Temu is known for offering up to 90% off on certain items, which makes it an attractive option for budget-conscious shoppers. Whether you’re in the mood for trendy apparel, kitchen gadgets, or tech accessories,  Temu has something that fits your style and budget. Plus, with its regular sales events and exclusive coupon codes, there’s always an opportunity to save more. One of the biggest perks is the ability to combine discounts with promo codes like the  Temu coupon code (acu639380), which gives you a $100 discount for new users and additional savings for existing customers. Benefits of Using  Temu Coupon Codes  Temu coupon codes can offer significant discounts, and knowing how to take full advantage of these offers can lead to huge savings. The  Temu coupon code (acu639380) comes with a variety of benefits, such as: $100 Off for new users: This is a great way for new customers to enjoy  Temu ’s products at a fraction of the price. $100 Off for existing users: Loyal customers can still get a fantastic discount. 40% off: This discount code provides a solid extra savings on selected items. $100 coupon bundle: This is an exclusive offer for both new and existing users that lets you save on multiple purchases. Free gifts for new users: A welcome treat for first-time customers.  Temu Coupon Codes for June 2025 Now, let’s look at the  Temu coupon codes for June 2025 and how you can maximize your savings. These codes are designed to provide discounts based on your user status and location. Make sure to apply the  Temu coupon code (acu639380) when you check out to get the best deal possible! Here’s a breakdown of the  Temu coupon codes (acu639380) available:  Temu Coupon Code (acu639380) $100 Off for New Users Enjoy an instant $100 discount when you sign up for  Temu as a new user.  Temu Coupon Code (acu639380) $100 Off for Existing Users Loyal customers can also use this code to score a $100 discount on their next purchase.  Temu Coupon Code (acu639380) 40% Off Get up to 40% off on select items and categories—perfect for budget-savvy shoppers.  Temu $100 Coupon Bundle This bundle lets you apply a $100 discount on your shopping cart for both new and returning users.  Temu First Time User Coupon First-time buyers get an exclusive gift with this coupon code, alongside additional savings.  Temu Promo Code (acu639380) for June 2025 Use this code to unlock all of the June offers, including huge discounts on a wide variety of items. How  Temu Coupon Codes Help You Save More By using the  Temu coupon code (acu639380), you can access not only great discounts but also enjoy perks like free shipping and exclusive offers. The platform’s unbeatable prices, combined with these additional promo codes, create a shopping experience like no other. Let’s take a closer look at how each of these discounts can benefit you. $100 Off for new users: As a new user, you can score $100 Off on your first order with the  Temu coupon code (acu639380) for June 2025. This means you can shop for high-quality products like electronics, fashion, and home goods while spending less. $100 Off for existing users: Existing users also benefit from this promo code, which means even long-time shoppers can save big. The  Temu coupon code (acu639380) ensures that both new and loyal customers get an opportunity to save. 40% extra off: Certain categories are eligible for up to 40% off with this code. Whether you’re eyeing the latest tech gadget or refreshing your wardrobe, this extra discount can make a real difference to your total. Free gifts for new users: If you’re signing up for the first time,  Temu wants to welcome you with extra surprises. Use the  Temu first-time user coupon code to receive free gifts that’ll make your shopping experience even more enjoyable. $100 coupon bundle:  Temu has also created a special bundle that gives users—new and existing—a $100 discount on their orders. This bundle is perfect for those who love shopping in bulk and want to get the most value from their purchases. Where to Use  Temu Coupon Codes (acu639380)  Temu ships to over 67 countries, so no matter where you are, there’s a great deal waiting for you. Here’s a country-specific breakdown of how you can use the  Temu coupon code (acu639380) and enjoy incredible savings:  Temu Coupon Code $100 Off for USA: Residents of the United States can enjoy $100 Off their purchase using the  Temu coupon code (acu639380), which works for both new and existing users.  Temu Coupon Code $100 Off for Canada: Shoppers in Canada can save $100 on their orders when they apply the  Temu coupon code (acu639380), making it an excellent option for our neighbors to the north.  Temu Coupon Code $100 Off for UK: UK shoppers can also benefit from this amazing coupon code, ensuring they get $100 Off their next  Temu order.  Temu Coupon Code 40% Off for Mexico: Mexico-based shoppers can enjoy up to 40% off select items by using the  Temu coupon code (acu639380), which is ideal for those looking for exclusive savings.  Temu Coupon Code 40% Off for Brazil: Brazilian shoppers will be thrilled to know that they can apply the  Temu coupon code (acu639380) for up to 40% off on select items from the website.  Temu Coupon Code $100 Off for Japan: Shoppers in Japan can also take advantage of the  Temu coupon code (acu639380) and get $100 Off their purchases, which works for a wide range of products. Tips to Maximize Your Savings Stack Coupon Codes:  Temu allows users to stack certain discounts, so be sure to combine the  Temu coupon code (acu639380) with other promotional offers to get the best deal possible. Shop During Sales Events: Take advantage of major sales events like Black Friday, Cyber Monday, and holiday sales, when you can use  Temu coupon codes for even bigger discounts. Sign Up for Alerts: By signing up for  Temu ’s newsletter, you’ll be the first to know about new coupon codes, flash sales, and other special offers. Follow  Temu on Social Media:  Temu often shares exclusive discounts and codes on its social media platforms. Follow them to stay updated on the latest deals. Conclusion Whether you’re a first-time shopper or a loyal  Temu customer, using the  Temu coupon code (acu639380) is a smart way to save money on your favorite items. With discounts like $100 Off, up to 40% off, and exclusive coupon bundles,  Temu ensures that you never have to pay full price. With free shipping to over 67 countries, it’s easier than ever to shop for high-quality, affordable products that fit your budget. Don’t miss out on these amazing savings—apply the  Temu coupon code (acu639380) today and enjoy huge discounts on your next purchase.  
    • Make tests with different builds of these mods
    • it worked now. but is therre n outer way to use essential and forggematica?
    • Maybe a conflict with essential - make a test without it
  • Topics

×
×
  • Create New...

Important Information

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