Jump to content

Recommended Posts

Posted

It's very easy!

Some geometry:

image.png.c83a24557940adb033e55e1c3fc15b5b.png

 

In general it will be similar:

String text = "something";
int objectWidth=fontRenderer.getStringWidth(text);
int screenWidth=Minecraft.getInstance().mainWindow.getWidth();
fontRenderer.drawString(text, screenWidth/2-objectWidth/2, 10);
//we can optimize division:
fontRenderer.drawString(text, (screenWidth-objectWidth)/2, 10);

 

Posted
3 hours ago, Nitoxym said:

Hello!

I wanted to know how can I center text in 1.15.2, I searched ScaledResolution, but it doesn't seem to exist.

Thanks!

First off where are you rendering at? Also what do you mean "center text"? In the exact middle of the screen? In the middle of the width, middle of the height. or even any other point on the screen?

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Posted (edited)
9 hours ago, Animefan8888 said:

First off where are you rendering at? Also what do you mean "center text"? In the exact middle of the screen? In the middle of the width, middle of the height. or even any other point on the screen?

At the middle of the width and height, and I'm rendering in game

And screenWidth is the width of the real screen, or the scaled one?

Edited by Nitoxym
Posted
6 minutes ago, Nitoxym said:

What do you mean? An event, class? If so, it's in RenderGameOverlayEvent

That's exactly what I meant. Inside the RenderGameOverlayEvent there is a getWIndow() function and that has a bunch of getters inside of it. There is one for getScaledWidth/Height and the normal getWidth/Height not sure which one you want to use though.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

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.