Tutorial 12. GUI

Before you read, make sure you have seen the previous tutorial

Code is on github

So, to add a GUI, we Need an GUIHandler, which implements IGuiHandler

Now, we need to override 2 methods.

This is where you open your gui.
Depending on the ID you get, you can open different GUI’s.
GUI’s are client side elements, becuase it is a visual thing.
Therefor, we add our openGUI in getClientGuiElement.
So, when an GUI has to be opened, with ID = 0, we open TestGUI.
Lets create our GUI.

Now, get your background texture. I use this one:

mygui

 

Note: The entire png needs to be 256×256. The ACTUAL GUI can have any size. Mine is 176×214. Remember these numbers. The Texture goes in /src/main/resources/assets/[MODID]/textures/gui

Now, in the TestGUI, add a link to this file, and define the texture size.

Now, to actually draw something, we need to Override drawScreen.
We bind the texture, then we calculate where we need to place it, and finally draw it.

Finally, we prevent the game from pausing when opening the gui.

Now, lets make sure we can open the gui.
I wanna do that, by right clicking on our newest TileEntity. Therefor, in TestTileBlock, i add

Last thing to do, is register our GUIHandler.
Firstly, we need an instance of our @Mod

And in the Init (not preInit), we register our handler

 


Back to List


Next tutorial


Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">