Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

[1.8] Text on screen changing place

Recommended Posts

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?



Link to post
Share on other sites

Few things 1st:


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

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



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.



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.

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

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.

  • Create New...

Important Information

By using this site, you agree to our Privacy Policy.