Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

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!

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);

 

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.

  • Author
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

5 minutes ago, Nitoxym said:

and I'm rendering in game

Not that kind of where, where is your code going to be located for this rendering operation?

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.

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.

  • Author
1 minute ago, Animefan8888 said:

There is one for getScaledWidth/Height

That's exactly what I needed, thanks! ?

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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.