Jump to content

[SOLVED] [1.12.2] GUI Help


Creleb

Recommended Posts

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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! :D 

Link to comment
Share on other sites

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.

  • Haha 2
Link to comment
Share on other sites

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? ?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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! :D 

Link to comment
Share on other sites

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

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