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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • I'm using Modrinth as a launcher for a forge modpack on 1.20.1, and can't diagnose the issue on the crash log myself. Have tried repairing the Minecraft instillation as well as removing a few mods that have been problematic for me in the past to no avail. Crash log is below, if any further information is necessary let me know. Thank you! https://paste.ee/p/k6xnS
    • Hey folks. I am working on a custom "Mecha" entity (extended from LivingEntity) that the player builds up from blocks that should get modular stats depending on the used blocks. e.g. depending on what will be used for the legs, the entity will have a different jump strength. However, something unexpected is happening when trying to override a few of LivingEntity's functions and using my new own "Mecha" specific fields: instead of their actual instance-specific value, the default value is used (0f for a float, null for an object...) This is especially strange as when executing with the same entity from a point in the code specific to the mecha entity, the correct value is used. Here are some code snippets to better illustrate what I mean: /* The main Mecha class, cut down for brevity */ public class Mecha extends LivingEntity { protected float jumpMultiplier; //somewhere later during the code when spawning the entity, jumpMultiplier is set to something like 1.5f //changing the access to public didn't help @Override //Overridden from LivingEntity, this function is only used in the jumpFromGround() function, used in the aiStep() function, used in the LivingEntity tick() function protected float getJumpPower() { //something is wrong with this function //for some reason I can't correctly access the fields and methods from the instanciated entity when I am in one of those overridden protected functions. this is very annoying LogUtils.getLogger().info(String.valueOf(this.jumpMultiplier))) //will print 0f return this.jumpMultiplier * super.getJumpPower(); } //The code above does not operate properly. Written as is, the entity will not jump, and adding debug logs shows that when executing the code, the value of this.jumpMultiplier is 0f //in contrast, it will be the correct value when done here: @Override public void tick() { super.tick(); //inherited LivingEntity logic //Custom logic LogUtils.getLogger().info(String.valueOf(this.jumpMultiplier))) //will print 1.5f } } My actual code is slightly different, as the jumpMuliplier is stored in another object (so I am calling "this.legModule.getJumpPower()" instead of the float), but even using a simple float exactly like in the code above didn't help. When running my usual code, the object I try to use is found to be null instead, leading to a crash from a nullPointerException. Here is the stacktrace of said crash: The full code can be viewed here. I have found a workaround in the case of jump strength, but have already found the same problem for another parameter I want to do, and I do not understand why the code is behaving as such, and I would very much like to be able to override those methods as intended - they seemed to work just fine like that for vanilla mobs... Any clues as to what may be happening here?
    • Please delete post. Had not noticed the newest edition for 1.20.6 which resolves the issue.
    • https://paste.ee/p/GTgAV Here's my debug log, I'm on 1.18.2 with forge 40.2.4 and I just want to get it to work!! I cant find any mod names in the error part and I would like some help from the pros!! I have 203 mods at the moment.
  • Topics

×
×
  • Create New...

Important Information

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