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

I have a class called ArrowCount which creates a string of text to render on the screen. It renders fine, but when I try to reposition it, the text moves when changing the gui size in the Minecraft settings.

 

Here's my class:

public class ArrowCount {
    private static Minecraft mc = Minecraft.getMinecraft();
    public static int arrowCount = 20;

    public static void renderToHud() {
        if((mc.inGameHasFocus) || (mc.currentScreen != null) && (mc.currentScreen instanceof GuiChat) && !mc.gameSettings.showDebugInfo) {
            ScaledResolution res = new ScaledResolution(mc, mc.displayWidth, mc.displayHeight);
            FontRenderer fontRender = mc.fontRendererObj;
            int width = res.getScaledWidth();
            int height = res.getScaledHeight();
            int arrows = arrowCount;

            String arrowCount = "Arrows: " + arrows;
            int x = width / 2;
            int y = (height / 2) + 82;
            int color = 0xffffff;
            mc.fontRendererObj.drawStringWithShadow(arrowCount, x, y, color);
        }
    }
}

 

I thought about this, and I'm pretty sure that because in the integer y, when I added 82, it always displays it in the same spot because 82 is static and will not change.

 

Does anyone know how I can have the text in the same spot no matter what size the gui is?

 

Thanks

Few things 1st:

 

1. Event gives you resolution, use that, m8.

@SubscribeEvent
public void onRenderOvelay(RenderGameOverlayEvent.Pre event)
{
	int w = event.resolution.getScaledWidth();
	int h = event.resolution.getScaledHeight();

 

2.

private static Minecraft mc = Minecraft.getMinecraft();

I don't think it can be static, Minecraft.class needs to be initialized (it's null on startup), so does your object (ArrowCount), after Minecraft.

But I might be wrong.

 

3.

int x = width / 2;
int y = (height / 2) + 82;

 

This will cause your arrow count to ALWAYS render with 82 offset from exact center - the 82 value is dependent to gui size - thus with different gui size it will be different offset.

 

Use e.g:

int x = width / 2;
int y = height - 50;

 

1.7.10 is no longer supported by forge, you are on your own.

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.