Posted June 6, 20178 yr Hey there, so I'm trying to figure out how to use GuiScreens for a mod 'guidebook.' (something similar to the Thaumonomicon, if you're familiar with Thaumcraft). However, I can't get the closeScreen() or openGui() methods to work correctly. In my main gui class, I have the actionPerformed method with a switch case in it switching between the ID of the buttons; you can see this here. I've commented the openGui() line because it doesn't work. When I click on the 'update news' button, the screen becomes twice as dark and nothing renders. I know it's opening the new gui because the screen becomes darker, but the old one doesn't go away. What I don't get about this is that when I remove the openGui() line, like I have in my gui class, it closes the gui just fine. I have no idea why this happens this way. My guihandler class and other gui classes are also present within this package.
June 7, 20178 yr Author 8 hours ago, draganz said: Look at minecraft's GuiInGameMenu class. Your not handling your gui correctly. What exactly would I have to do to handle it correctly? I don't know what I'm doing wrong.
June 7, 20178 yr you need to us mc.displayGuiScreen(yourGui) to display the GUI, because this method handles for null variables, aswell as handing the closing of previously opened gui. When you did the mc.thePlayer.openGui you did just that, open a GUI, on top of another GUI that wasn't closed. The displayGuiScreen method handles for that. Look at the class I said, and then at the method I said, if you want to know how. Edited June 7, 20178 yr by draganz
June 8, 20178 yr Author On 6/7/2017 at 3:38 AM, draganz said: you need to us mc.displayGuiScreen(yourGui) to display the GUI, because this method handles for null variables, aswell as handing the closing of previously opened gui. When you did the mc.thePlayer.openGui you did just that, open a GUI, on top of another GUI that wasn't closed. The displayGuiScreen method handles for that. Look at the class I said, and then at the method I said, if you want to know how. Okay, so I got that working. But I have another issue now. My textured rectangle is placed on the screen with 'hard' coordinates; set numbers. Now I need to get it to always be in the center of the screen, regardless of monitor size. I've gotten the screen size using Dimension Toolkit, but I don't know how to make the rectangle always in the center, because changing the coordinates at which it renders seems to be rather random.
June 9, 20178 yr You want to know what I did to find this answer, spend a minute looking at the minecraft source code, tends to have most of the answers... Just do something along the lines of : mc.getTextureManager().bindTexture(yourTexture); //This is a VERY standard way of getting the center of the screen, like you cant miss this, if you google it, it will be the first result, I'm sure; its common code. final int x = (width - x_length_of_texture_you_want_to_draw) / 2; final int y = (height - y_length_of_texture_you_want_to_draw) / 2; /* As a note, the width and height variables are provided via the gui which are the screens width and height (they respond to screen rescaling), you can also use xSize and ySize to get 176 and 166 (respectivly), those being the values for Minecraft's default gui sizes. Also, I make the ints x and y final, this isn't neccessary, just preference; stick to your own code style. */ drawTexturedModelRect(x, y, 0, 0, x_length_of_texture_you_want_to_draw, y_length_of_texture_you_want_to_draw); // this method is also provided via the Gui class, look at it, if you want to understand the parameters
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.