Posted July 11, 201312 yr I am trying to add a button to the options GUI, but I can't find any forge way to make it work! I tried to make a normal ModLoader mod to use the onTickInGUI funstion, but it never triggered. I know how to do this using ASM, but I would like to avoid that if possible. Is there a way to do this? EDIT: To clarify, I am not trying to make a modloader mod. I have a modloader mod that works, but I would like to port it to a forge mod.
July 11, 201312 yr ModLoader? This isn't the place for ModLoader mods! Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support. 1.12 -> 1.13 primer by williewillus. 1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support. http://www.howoldisminecraft1710.today/
July 11, 201312 yr Why do you ask this in a forum for Minecraft FORGE? Forge contains classes like BaseMod to allow compability with mods designed for ModLoader, not for making ModLoader mods. If you really want to use ModLoader (i recommend switching to forge), this is the wrong forum. But now back to your question: With Forge yes (pretty easily), with Modloader i dont know.
July 11, 201312 yr Author I know this is for forge, and that's why I was asking! I am trying to update an old ModLoader mod to forge, and I could not find a forge way to add the button to the GUI. If you know a way (without using ModLoader and preferably without ASM), then please tell me!
July 11, 201312 yr I know this is for forge, and that's why I was asking! I am trying to update an old ModLoader mod to forge, and I could not find a forge way to add the button to the GUI. If you know a way (without using ModLoader and preferably without ASM), then please tell me! You need to be a little more informative in your posts, but about your question, I have only one thing to say: search trough the javadoc if you can find any forge hooks. Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support. 1.12 -> 1.13 primer by williewillus. 1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support. http://www.howoldisminecraft1710.today/
July 11, 201312 yr Author I looked a bit through the javadocs, but I don't know what classes the hooks are stored in besides ForgeHooks and ForgeHooksClient, and neither has what I want. I am mostly new to forge but I have used it before. I have never had to change a vanilla GUI before...
July 11, 201312 yr Author Would it work if I made a BaseMod class and used the old modloader onTickInGUI method? Or would having a basemod and an @Mod for the same mod clash?
July 11, 201312 yr Even with forge this is not cleanly possible without using ASM. I dont know what you consider as cleanly but its possible with reflection. Here is how to do it: First create a new TickHandler (similar to onTick in ModLoader): import java.lang.reflect.Field; import java.util.EnumSet; import java.util.List; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiButton; import net.minecraft.client.gui.GuiScreen; import net.minecraft.client.gui.inventory.GuiChest; import cpw.mods.fml.common.ITickHandler; import cpw.mods.fml.common.TickType; public class TickHandler implements ITickHandler { @Override public void tickStart(EnumSet<TickType> type, Object... tickData) { try { GuiScreen activeGUI = Minecraft.getMinecraft().currentScreen; if(activeGUI != null && activeGUI instanceof GuiChest) //whatever GUI you want to add a/multiple button/s to { Field field = GuiScreen.class.getDeclaredField("buttonList"); field.setAccessible(true); List buttonList = (List) field.get(activeGUI); if(buttonList.size() < 1) //this has to be one smaller than the number of buttons it usually has, else you will keep adding your button over and oever again { buttonList.add(new GuiButton(1, 2, 5, "Test")); //you have to make a class extending GuiButton to add function to your button } } } catch(Exception e) { e.printStackTrace(); } } @Override public void tickEnd(EnumSet<TickType> type, Object... tickData) { } @Override public EnumSet<TickType> ticks() { return EnumSet.of(TickType.RENDER); } @Override public String getLabel() { return "GUI TickHandler"; //Or however you want to name it } } Then you have to register it in your load/init method TickRegistry.registerTickHandler(new TickHandler(), Side.CLIENT); Thats basically it, you will now have an additional button in the GUI(I used the chest as an example):
July 11, 201312 yr Author Thank you! That is exactly what I was looking for! I didn't realize that TickHandler fired in GUIs!
July 11, 201312 yr Author Thank you for pointing that out. I was pretty sure ASM would be smoother, but when I did try it it kept refusing to load my class, even though I did it just like my other ASM classes that work just fine.
July 11, 201312 yr speaking of ASM, I keep getting this error to do with something like com.google.event.EventBus or something and how it does not exist. This error gets thrown on my CoreMod's dmmycontainer. But it only gets that error when I extend DummyModContainer... Any ideas why? I am Mew. The Legendary Psychic. I behave oddly and am always playing practical jokes. I have also found that I really love making extremely long and extremely but sometimes not so descriptive variables. Sort of like what I just did there
July 11, 201312 yr Author I don't use DummyModContainer, so I don't know how much I can help. But I think your IDE may be trying to import the wrong class. I'm pretty sure there is an event bus class somewhere in FML that has the same name. If you'r IDE has an autocomplete function (eclipse, Intell-j, probably more), try referencing "EventBus" and see what import options it gives.
July 11, 201312 yr I already tried that It still gave the error. And the error was underneath the p in "package mew.core;" I am Mew. The Legendary Psychic. I behave oddly and am always playing practical jokes. I have also found that I really love making extremely long and extremely but sometimes not so descriptive variables. Sort of like what I just did there
July 11, 201312 yr Author What IDE are you using? If its intelli-j try doing a full rebuild or restarting it. Mine will glitch up like that sometimes.
July 11, 201312 yr What IDE are you using? If its intelli-j try doing a full rebuild or restarting it. Mine will glitch up like that sometimes. I am using eclipse. I will try it again with my rebuilt workspace. Thanks for the Idea I am Mew. The Legendary Psychic. I behave oddly and am always playing practical jokes. I have also found that I really love making extremely long and extremely but sometimes not so descriptive variables. Sort of like what I just did there
July 11, 201312 yr Author Your welcome! It's what I do with everything: "If it stops working for no apparent reason: turn it off and on again." It works for nearly everything.
July 11, 201312 yr Ill agree to that Unless it is out of battery and that's why it stops working I am Mew. The Legendary Psychic. I behave oddly and am always playing practical jokes. I have also found that I really love making extremely long and extremely but sometimes not so descriptive variables. Sort of like what I just did there
July 11, 201312 yr And what do you know it worked Now I just have to figure out why it is disabled I am Mew. The Legendary Psychic. I behave oddly and am always playing practical jokes. I have also found that I really love making extremely long and extremely but sometimes not so descriptive variables. Sort of like what I just did there
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.