Jump to content

Recommended Posts

Posted

So, for a mod I am creating, I was going to create a separate options GUI where I'm going to put settings that I want to make sure are looked over and configured. I'm trying to do two things:

1. On the first time you start up Minecraft, display a GUI that prominently displays a message, with buttons that will take you to the main menu. I'm trying to make something similar to the same thing that Biomes O' Plenty for MC 1.7.2 does the first time you start it up.

2. Add a button to the primary main menu (the one with singleplayer, multiplayer, realms, settings, etc) that will lead to another GUI.

 

I've included most of my code below, but here's a synopsis of what I'm trying to do, and what's the problem.

 

I've created a working event handler which has a function that uses the GuiOpen event. The function makes sure the GUI opened is the vanilla GuiMainMenu (and judging by the debug messages I placed, this part mostly works), and then checks some settings to see if the "MainMenuWarning" GUI hasn't been opened yet. I then use the Minecraft.getMinecraft() method to get the instance of Minecraft (not sure if this is a reliable method)  and then run displayGuiScreen(new WhateverGui()) on the Minecraft instance to open the preferred GUI (this seems to be the method a lot of vanilla code uses; I still have my doubts of the usability of this method). If all works as planned, my special GUI should then open instead of the default GuiMainMenu.

 

Problem: It doesn't.

There's no crash or anything, it just doesn't open. By the little debug messages I placed in my event handler, I can confirm that the displayGuiScreen method is running, which is why I have doubts about the method. There's something in the source code involving instances of GuiMainMenu, so that might interfere with my new main menu which subclasses that. So, I made a few changes to the code to make sure it only displays the MainMenuWarning (which directly subclasses GuiScreen; shouldn't be any problem). Unfortunately, there still is no change; it just displays the GuiMainMenu.

 

Potential solutions?

Mainly, I just want to know what method I should be using to change the GUI. I'm not sure if there's something else that I need to do, or if I should use a different method for opening guis (like player.openGui(), but I usually thought this was mainly used for opening GUIs ingame).

 

Now for my custom code:

 

Main Mod Class:

https://gist.github.com/anonymous/62acdc5df16c40aa0b8d

 

EventHandler:

https://gist.github.com/anonymous/4907577c331aba9e4e4a

 

GuiHandler: (idk if i have to register these GUIs)

https://gist.github.com/anonymous/d6bf684523d389dd50aa

 

MainMenu:

https://gist.github.com/anonymous/9175ae5bdcb27ed7a29c

 

MainMenuWarning:

https://gist.github.com/anonymous/86d0630bbc32a6d6ae94

 

I think that's all that's necessary, tell me if you need any more. Sorry if anything if a but sloppy.

 

Also, on a side note, I can't seem to use spoilers or emoticons. Is it a site error, or because I'm using Chrome or something?

 

Thanks for any help in advance, especially if you've stuck around to read all of that ;)

Posted

Use event.gui = new WhateverGui()

It also states in the event's javadoc:

If you want to override this Gui, simply set the gui variable to your own Gui.

Don't ask for support per PM! They'll get ignored! | If a post helped you, click the "Thank You" button at the top right corner of said post! |

mah twitter

This thread makes me sad because people just post copy-paste-ready code when it's obvious that the OP has little to no programming experience. This is not how learning works.

Posted

So overriding the GUI just changes the displayed GUI outright? Let me try this real quick...

 

EDIT: Ok, it displays the MainMenuWarning GUI perfectly. The only problem is now when I open the new MainMenu from MainMenuWarning.actionPerformed using mc.currentscreen=new DNATGuiMainMenu(), it crashed because of a NullPointerException. Here's the stacktrace if it helps:

 

https://gist.github.com/anonymous/1407cf49ad0a59adfbba

 

I have an idea of what might be causing the problem, so I'm going to look into that. Thanks for the help with the other GUI though!

 

EDIT 2: It appears to be a problem within the GuiMainMenu.renderSkybox(int,int,float) method, on the line this.mc.getFramebuffer().unbindFramebutter(). This probably means that the Framebuffer in the main Minecraft instance is still not initialized; so the new question is, how can I initialize this safely?

Posted

DO NOT set

mc.currentscreen

directly!

 

Use mc.displayGuiScreen for that, since it initializes the GUI (and not just sets a variable)

Don't ask for support per PM! They'll get ignored! | If a post helped you, click the "Thank You" button at the top right corner of said post! |

mah twitter

This thread makes me sad because people just post copy-paste-ready code when it's obvious that the OP has little to no programming experience. This is not how learning works.

Guest
This topic is now closed to further replies.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.