SevenDeadly Posted September 14, 2013 Posted September 14, 2013 Is it possible to add buttons to the MainMenu without editing Base Classes? I read something a while back about using a tickhandler to check for when the MainMenu GUI is open, and to replace it with a custom GUI. However, I feel like this is excessive if there is a way to add a button. I tried something somewhere along the lines of: called in the load method of the base-mod class import net.minecraft.client.gui.GuiButton; import net.minecraft.client.gui.GuiMainMenu; import net.minecraft.client.resources.I18n; public class GuiNewButton extends GuiMainMenu { private GuiButton newButton = null; public GuiNewButton() { newButton = new GuiButton(15, this.width / 2 - 100, 108 + 24 * 2, "New Button"); buttonList.add(newButton); } } out of curiosity, as it seemed pretty simple. Unfortunately it did not work, though. Any ideas? (Very new to modding, so sorry if what I tried is obvious that it would fail. I am completely oblivious to a lot of the classes, FML methods, etc.) Quote
sep87x Posted September 15, 2013 Posted September 15, 2013 The way to go here is a coremod that modifies the bytecode of the GuiMainMenu class (or GuiScreen to be more generic). Not necessarily. When I was a coding noob, I tried the same and found another method without editing base classes. At first create a new GuiScreen (I'll call it FakeGuiMainMenu) which is similar to the GuiMainMenu (so simply copy & paste). After that, add a client side tick handler to your mod. In the tickEnd() method, check if the current screen being is an instance of the GuiMainMenu. If so, then make Minecraft display your "fake" gui screen. package my.dummy.package; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiMainMenu; import net.minecraft.client.gui.GuiScreen; import cpw.mods.fml.common.ITickHandler; import cpw.mods.fml.common.TickType; public class OpenGuiListener implements ITickHandler { @Override public void tickStart(EnumSet<TickType> type, Object... tickData) { } @Override public void tickEnd(EnumSet<TickType> type, Object... tickData) { if (Minecraft.getMinecraft().currentScreen instanceof GuiMainMenu) { Minecraft.getMinecraft().displayGuiScreen(new FakeGuiMainMenu()); } } @Override public EnumSet<TickType> ticks() { return EnumSet.of(TickType.CLIENT); } @Override public String getLabel() { return "dummyMainMenuListener"; } } I made it earlier and it works sweet. Greets from Germany ~sep87x Quote
sep87x Posted September 15, 2013 Posted September 15, 2013 The way to go here is a coremod that modifies the bytecode of the GuiMainMenu class (or GuiScreen to be more generic). Not necessarily. When I was a coding noob, I tried the same and found another method without editing base classes. At first create a new GuiScreen (I'll call it FakeGuiMainMenu) which is similar to the GuiMainMenu (so simply copy & paste). After that, add a client side tick handler to your mod. In the tickEnd() method, check if the current screen being is an instance of the GuiMainMenu. If so, then make Minecraft display your "fake" gui screen. package my.dummy.package; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiMainMenu; import net.minecraft.client.gui.GuiScreen; import cpw.mods.fml.common.ITickHandler; import cpw.mods.fml.common.TickType; public class OpenGuiListener implements ITickHandler { @Override public void tickStart(EnumSet<TickType> type, Object... tickData) { } @Override public void tickEnd(EnumSet<TickType> type, Object... tickData) { if (Minecraft.getMinecraft().currentScreen instanceof GuiMainMenu) { Minecraft.getMinecraft().displayGuiScreen(new FakeGuiMainMenu()); } } @Override public EnumSet<TickType> ticks() { return EnumSet.of(TickType.CLIENT); } @Override public String getLabel() { return "dummyMainMenuListener"; } } If it works, you may now edit the FakeGuiScreen as you like. I made it earlier and it works sweet. Greets from Germany ~sep87x Quote
SevenDeadly Posted September 15, 2013 Author Posted September 15, 2013 The way to go here is a coremod that modifies the bytecode of the GuiMainMenu class (or GuiScreen to be more generic). Not necessarily. When I was a coding noob, I tried the same and found another method without editing base classes. At first create a new GuiScreen (I'll call it FakeGuiMainMenu) which is similar to the GuiMainMenu (so simply copy & paste). After that, add a client side tick handler to your mod. In the tickEnd() method, check if the current screen being is an instance of the GuiMainMenu. If so, then make Minecraft display your "fake" gui screen. package my.dummy.package; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiMainMenu; import net.minecraft.client.gui.GuiScreen; import cpw.mods.fml.common.ITickHandler; import cpw.mods.fml.common.TickType; public class OpenGuiListener implements ITickHandler { @Override public void tickStart(EnumSet<TickType> type, Object... tickData) { } @Override public void tickEnd(EnumSet<TickType> type, Object... tickData) { if (Minecraft.getMinecraft().currentScreen instanceof GuiMainMenu) { Minecraft.getMinecraft().displayGuiScreen(new FakeGuiMainMenu()); } } @Override public EnumSet<TickType> ticks() { return EnumSet.of(TickType.CLIENT); } @Override public String getLabel() { return "dummyMainMenuListener"; } } I made it earlier and it works sweet. Greets from Germany ~sep87x I tried doing this, but it doesn't seem to work. I get two errors: The first being that RunnableTitleScreen cannot be resolved to a type. When importing this, I get the error stating that RunnableTitleScreen is not a public class. The second being that GuiButton.width is not visible. I tried making custom classes (copying and pasting with little editing other than the names of a few methods such as constructors) of the classes causing the errors, which got rid of the errors being shown in my IDE. However, when running the game with this about one second after the MainMenu is shown the game crashes. Any ideas? First, let me explain why your method won't work. Minecraft itself doesn't care about your extending class. Minecraft uses GuiMainMenu, not GuiNewButton, so your class probably doesn't even get loaded. The way to go here is a coremod that modifies the bytecode of the GuiMainMenu class (or GuiScreen to be more generic). If you say you are very new to modding you probably are not in a position to try that yet, though. if you still want to, have a look at https://github.com/diesieben07/SevenCommons/ where I do exactly that to create a GuiInit event. Of course my class was loaded somewhere, I even stated where above the code when I posted the topic. As for making a CoreMod, I would rather just try and use "messy" code. Not only does it work fine, but it saves work on the user's side and makes installing less complex. Quote
SevenDeadly Posted September 15, 2013 Author Posted September 15, 2013 Why are people so against core-mods then? Also, maybe I am thinking too far back, but I remember core-mods being the ones where you have to go out of your way to put them in the minecraft.jar (now minecraft-Version.jar). Did that change? Quote
SevenDeadly Posted September 15, 2013 Author Posted September 15, 2013 Do you know of any tutorials on making CoreMods? Never made one before, and I wouldn't have the slightest clue as to where I should start. Quote
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.