Posted October 28, 20186 yr Hello! I’m fairy new to modding and I need some help with a custom gui. I want to make a gui that pops up when you press the “U” Key but I do not know where to start. Could someone help me? Edited November 1, 20186 yr by Creleb
October 28, 20186 yr Start off by making your custom GUI obviously, then make and register a KeyBinding, listen for the KeyInputEvent, check if your keybinding is pressed and display your GUI with Minecraft#displayGuiScreen.
October 29, 20186 yr Author 2 hours ago, V0idWa1k3r said: Start off by making your custom GUI obviously, then make and register a KeyBinding, listen for the KeyInputEvent, check if your keybinding is pressed and display your GUI with Minecraft#displayGuiScreen. I started to try this out but I did not make it far. I tried to get the keybind to appear in the controls but they haven't appeared. I do not know what I did wrong ? package com.Creleb.Mod.keys; import org.lwjgl.input.Keyboard; import com.Creleb.Mod.util.handlers.KeyInputHandler; import net.minecraft.client.settings.KeyBinding; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.fml.common.event.FMLPreInitializationEvent; public class Keybinds { public static KeyBinding gui; public static void register() { gui = new KeyBinding("key.gui", Keyboard.KEY_U, "key.categories.mhq"); } public static void preInit(FMLPreInitializationEvent event) { Keybinds.register(); MinecraftForge.EVENT_BUS.register(new KeyInputHandler()); } } I don't know if I am missing anything, but if I am let me know.
October 29, 20186 yr 1 minute ago, Creleb said: KeyInputHandler What is in here? VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect. Forge and vanilla BlockState generator.
October 29, 20186 yr 4 minutes ago, Creleb said: public static void preInit(FMLPreInitializationEvent event) Are you calling this from your main mod file? And even if you are - why are you passing the FML event as a parameter? You have exactly zero use for it. Just creating a KeyBinding isn't enough, you also need to register it in order for it to appear in the options menu with ClientRegistry.registerKeyBinding
October 29, 20186 yr Author 9 minutes ago, V0idWa1k3r said: Are you calling this from your main mod file? And even if you are - why are you passing the FML event as a parameter? You have exactly zero use for it. Just creating a KeyBinding isn't enough, you also need to register it in order for it to appear in the options menu with ClientRegistry.registerKeyBinding Well I edited it and I guess I still don't get it. public class Keybinds { public static KeyBinding gui; public static void register() { gui = new KeyBinding("key.gui", Keyboard.KEY_U, "key.categories.mhq"); ClientRegistry.registerKeyBinding(gui); Keybinds.register(); MinecraftForge.EVENT_BUS.register(new KeyInputHandler()); } } Like I said I'm fairly new. I have been trying to lookup tutorials but I haven't found much. I'm sorry if my lack of knowledge is annoying you, but I am learning and I thank you for your help!
October 29, 20186 yr public static void register() { gui = new KeyBinding("key.gui", Keyboard.KEY_U, "key.categories.mhq"); ClientRegistry.registerKeyBinding(gui); Keybinds.register(); MinecraftForge.EVENT_BUS.register(new KeyInputHandler()); } Are you... calling the register method from inside of the register method? The fact that you do not have a StackOverflow on your hands means that you are not calling register from anywhere in the first place.
October 29, 20186 yr Author 3 minutes ago, V0idWa1k3r said: public static void register() { gui = new KeyBinding("key.gui", Keyboard.KEY_U, "key.categories.mhq"); ClientRegistry.registerKeyBinding(gui); Keybinds.register(); MinecraftForge.EVENT_BUS.register(new KeyInputHandler()); } Are you... calling the register method from inside of the register method? The fact that you do not have a StackOverflow on your hands means that you are not calling register from anywhere in the first place. okay...so how can I edit it to insert a StackOverflow to get it to work? ?
October 29, 20186 yr Just now, Creleb said: okay...so how can I edit it to insert a StackOverflow to get it to work? ? He meant a StackOverFlow Exception. You shouldn't be calling a method inside of itself unless you know what you are doing. You need to call your register method from your @Mod class. VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect. Forge and vanilla BlockState generator.
October 29, 20186 yr Author 40 minutes ago, Animefan8888 said: What is in here? It's suppose to detect if the "U" key is pressed and display a custom gui screen. I'm 100% positive that its wrong considering that i have done everything else without knowing. package com.Creleb.Mod.util.handlers; import com.Creleb.Mod.client.gui.CustomGui; import com.Creleb.Mod.keys.Keybinds; import net.minecraft.client.Minecraft; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; import net.minecraftforge.fml.common.gameevent.InputEvent.KeyInputEvent; public class KeyInputHandler { @SubscribeEvent public void onKeyInput (KeyInputEvent event) { if (Keybinds.gui.isPressed()) { Minecraft.getMinecraft().displayGuiScreen(new CustomGui()); } } } Thanks for your help! I know my inexperience is frustrating...if there is a tutorial out there that you know of feel free to let me know because I obviously need it.
October 29, 20186 yr 2 minutes ago, Creleb said: Thanks for your help! I know my inexperience is frustrating...if there is a tutorial out there that you know of feel free to let me know because I obviously need it. Any Java tutorial really. Stanford has a really good YouTube playlist of their Java course. 4 minutes ago, Creleb said: It's suppose to detect if the "U" key is pressed and display a custom gui screen. I'm 100% positive that its wrong considering that i have done everything else without knowing. That code looks good. VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect. Forge and vanilla BlockState generator.
October 29, 20186 yr Author Just now, Animefan8888 said: Any Java tutorial really. Stanford has a really good YouTube playlist of their Java course. That code looks good. wow really? Awesome! anyways you said something about a StackOverflow Exception and that 25 minutes ago, Animefan8888 said: You need to call your register method from your @Mod class stupid question: wheres the @Mod class and how to I call my register method from it? Could my @Mod class named something different or no?
October 29, 20186 yr 1 minute ago, Creleb said: stupid question: wheres the @Mod class Its a class you have to make. 2 minutes ago, Creleb said: Could my @Mod class named something different or no? It can be named anything you want, but it needs to have the @Mod annotation. VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect. Forge and vanilla BlockState generator.
October 29, 20186 yr Author 11 minutes ago, Animefan8888 said: Its a class you have to make. It can be named anything you want, but it needs to have the @Mod annotation. It works now! Thank you so much! My only problem now is actually getting the GUI to display lol. I press the key and it pauses but nothing shows up. I'll work on it and let you know if I have any issues!
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.