Jump to content

Recommended Posts

Posted (edited)

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 by Creleb
Posted

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.

Posted
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.

Posted
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

Posted
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 

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

Posted
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.

Posted
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.

Posted
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.

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

Posted
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.

Posted
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 

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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Reach Out To Rapid Digital: What sapp Info: +1 41 4 80 7 14 85 Email INFO: rap iddi gita lrecov ery @ exe cs. com Hello, my name is Jayson, and I’m 35 years old from the United Kingdom. My family and I recently endured an incredibly challenging experience that I wouldn’t wish on anyone. We became victims of a cryptocurrency investment fraud scheme that saw us lose a staggering $807,000 in USDT and Bitcoins. The fraudsters had created a convincing facade, and we were lured into investing, only to discover later that the platform was a complete scam. We were left devastated, not just financially, but emotionally, as we had trusted these people and believed in the legitimacy of the investment. After the initial shock wore off, we desperately searched for ways to recover the lost funds. It seemed like an impossible task, and we felt as though there was no hope. That’s when, by sheer luck, we stumbled across a post about Rapid Digital Recovery, a cryptocurrency and funds recovery organization with a proven track record in cybersecurity and fraud recovery. We decided to reach out to them, and from the first interaction, we were impressed with their professionalism and transparency. They explained the recovery process in detail and reassured us that they had the skills and expertise to track down the perpetrators and recover our funds. This gave us a renewed sense of hope, something we hadn’t felt in months. What truly stood out during our experience with Rapid Digital Recovery was their dedication to the recovery process. The team went above and beyond, using sophisticated tracking tools and cyber forensics to gather critical information. Within a matter of weeks, they had successfully located the funds and traced the scam back to the fraudsters responsible. They worked with the authorities to ensure the criminals were held accountable for their actions. To our relief, the team at Rapid Digital Recovery was able to recover every single penny we had lost. The funds were returned in full, and the sense of closure we felt was invaluable. We couldn’t have imagined such a positive outcome in the early stages of our recovery journey, and we are deeply grateful for the work they did. If you ever find yourself in a similar situation, I highly recommend contacting Rapid Digital Recovery. Their expertise, transparency, and dedication to their clients make them the go-to choice for anyone seeking to recover lost cryptocurrency or funds. They truly gave us back our financial future.  
    • This is my first time modding anything, so maybe just skill issue. I'm using Forge 54.0.12 and Temurin 21.0.5+11-LTS I wanted to create a custom keybind and to check whether it works I'd like to send a chat message. I tried using Minecraft.getInstance().player.sendSystemMessage(Component.literal("test")); but IntelliJ couldnt resolve sendSystemMessage(...). Since I saw people using it in earlier versions, I tried the same thing with 1.20.6(- 50.1.0), where it works fine, now I can't figure out if this is intentional and whether there are other options for sending chat messages. On that note, is there more documentation than https://docs.minecraftforge.net/en/1.21.x/? It seems very incomplete compared to something like the Oracle Java docs
    • Hi, i'm having this error and I wanna fix it. we try: -Reload drivers -Eliminate .minecraft -Eliminate Java -Restart launcher -Verify if minecraft is using gpu -Mods  in .minecraft is empty -Install the latest and recomended version of forge idk what i have to do, help me pls. the lastest log is: https://mclo.gs/WAMao8x  
    • Read the FAQ, Rule #2. (https://forums.minecraftforge.net/topic/125488-rules-and-frequently-asked-questions-faq/)  
  • Topics

×
×
  • Create New...

Important Information

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