MSpace-Dev Posted November 21, 2017 Share Posted November 21, 2017 So, I am trying to get the width and height of my current screen size, by extending GuiScreen. Though, for some reason, it's returning 0 for this.width and this.height. Yet when I made an Openable GUI extend GuiScreen, it returns the correct values. I need the screen width and height to put my custom health bar in the bottom right of the screen. I've tried to call initGui() and setWorldAndResolution() to see if they'd get the width and height, but with no avail. public class GuiOverlay extends GuiScreen { private final ResourceLocation bar = new ResourceLocation(Reference.MODID, "textures/blocks/hp_bar.png"); private final int bar_width = 102, bar_height = 8, hp_height = 6; private int hp_width = 100; @SubscribeEvent public void renderOverlay(RenderGameOverlayEvent event){ Minecraft mc = Minecraft.getMinecraft(); mc.renderEngine.bindTexture(bar); Utils.getLogger().info("Width: " + this.width); // returns 0 Utils.getLogger().info("Height: " + this.height); // returns 0 drawTexturedModalRect(width - bar_width, height - bar_height, 0, 0, bar_width, bar_height); // Off the screen due to width/height = 0 drawTexturedModalRect(width - bar_width, height - bar_height, 1, bar_height + 1, hp_width, hp_height); // Off the screen due to width/height = 0 mc.renderEngine.bindTexture(ICONS); } } Any ideas? Quote Link to comment Share on other sites More sharing options...
MSpace-Dev Posted November 21, 2017 Author Share Posted November 21, 2017 Still having trouble with this. Can't find a solution. Quote Link to comment Share on other sites More sharing options...
jabelar Posted November 22, 2017 Share Posted November 22, 2017 If you follow the call hierarchy for the width and height fields you'll see that the main way they are set is with the Minecraft#updateDisplay() method which calls the Minecraft#checkWindowResize() method which calls the Minecraft#resize() method which calls the GuiScreen#onGuiResize() method which calls the GuiScreen#setWorldAndResolution(). I think your GUI should get the benefit of that automatically if you register it and open it properly. But if you wanted to force it then the setWorldAndResolution() method should do it assuming you pass the right size (scaled display size) to it. Quote Check out my tutorials here: http://jabelarminecraft.blogspot.com/ Link to comment Share on other sites More sharing options...
Recommended Posts
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.