Craftit7 Posted July 8, 2021 Share Posted July 8, 2021 @SubscribeEvent public void clientTickEvent(ClientTickEvent event) { if (openGuiMenuKey.isPressed()) { System.out.println("Helllllllooooooooooooooooooooooooooooooooooooooooooooooooooooo"); } } Just crashes with:- `AL lib: (EE) alc_cleanup: 1 device not closed` // Daisy, daisy... Time: 06/07/21 12:15 Description: Unexpected error java.lang.NullPointerException: Unexpected error at com.craftit7.fpsbooster.FpsBooster.clientTickEvent(FpsBooster.java:47) ~[main/:?] {re:classloading} Quote Link to comment Share on other sites More sharing options...
Saksham4106 Posted July 8, 2021 Share Posted July 8, 2021 event method should be static Quote Link to comment Share on other sites More sharing options...
Craftit7 Posted July 8, 2021 Author Share Posted July 8, 2021 1 minute ago, diesieben07 said: I assume that is the line with the if statement in it? How do you initialize openGuiMenuKey? Also note that ClientTickEvent fires twice every tick, check TickEvent#phase. public void init(FMLClientSetupEvent event) { this.openGuiMenuKey = new KeyBinding("key.openfpsboostermenu", 72, "key.categories.menu"); Quote Link to comment Share on other sites More sharing options...
Craftit7 Posted July 8, 2021 Author Share Posted July 8, 2021 1 minute ago, Saksham4106 said: event method should be static Error: openGuiKeyMenu is not static, and i cant make it static because i need it not to be static Quote Link to comment Share on other sites More sharing options...
Craftit7 Posted July 8, 2021 Author Share Posted July 8, 2021 // Here it is package com.craftit7.fpsbooster; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import net.minecraft.client.settings.KeyBinding; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.event.TickEvent; import net.minecraftforge.event.TickEvent.ClientTickEvent; import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.fml.common.Mod; import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent; @Mod("fpsbooster") public class FpsBooster { public static final Logger LOGGER = LogManager.getLogger(); public static final String MOD_ID = "fpsbooster"; public KeyBinding openGuiMenuKey; private boolean isMenuOpen = false; private final ClientTickEvent tickEvent = new ClientTickEvent(TickEvent.Phase.START); public void init(FMLClientSetupEvent event) { this.openGuiMenuKey = new KeyBinding("key.openfpsboostermenu", 72, "key.categories.menu"); /** TODO * Run "H" key listener. */ //looper /*if (openGuiMenuKey.isPressed()) { if (isMenuOpen) { saveSettings(); closeMenu(); within it: isMenuOpen = false; } else { loadSettings(); openMenu(); within it: isMenuOpen = true; } }*/ } @SubscribeEvent public void clientTickEvent(ClientTickEvent event) { if (openGuiMenuKey.isPressed()) { System.out.println("Test, works ig"); } } public FpsBooster() { //IEventBus Bus = FMLJavaModLoadingContext.get().getModEventBus(); MinecraftForge.EVENT_BUS.register(this); } } 1 minute ago, diesieben07 said: Show more of your code. Quote Link to comment Share on other sites More sharing options...
Craftit7 Posted July 8, 2021 Author Share Posted July 8, 2021 The mod is client-sid only and im registering the event bus at the very bottom.... public FpsBooster() { //IEventBus Bus = FMLJavaModLoadingContext.get().getModEventBus(); MinecraftForge.EVENT_BUS.register(this); } Quote Link to comment Share on other sites More sharing options...
Saksham4106 Posted July 8, 2021 Share Posted July 8, 2021 (edited) 'init' method still needs a @SubscribeEvent Edited July 8, 2021 by Saksham4106 1 Quote Link to comment Share on other sites More sharing options...
Craftit7 Posted July 8, 2021 Author Share Posted July 8, 2021 Init works, i tested it. Quote Link to comment Share on other sites More sharing options...
Craftit7 Posted July 8, 2021 Author Share Posted July 8, 2021 Oh wait a minute, My code didnt save @SubscribeEvent.... Added it lemme test it now Quote Link to comment Share on other sites More sharing options...
Saksham4106 Posted July 8, 2021 Share Posted July 8, 2021 (edited) ClientRegistry.registerKeyBinding(myKey); also you need to register your key bindings like this in FMLClientSetupEvent i believe Edited July 8, 2021 by Saksham4106 Quote Link to comment Share on other sites More sharing options...
Craftit7 Posted July 8, 2021 Author Share Posted July 8, 2021 Works, init was the problem, moved it to the public KyeBinding openGuiMenuKey Quote Link to comment Share on other sites More sharing options...
Craftit7 Posted July 8, 2021 Author Share Posted July 8, 2021 Uh sure package com.craftit7.fpsbooster; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import net.minecraft.client.settings.KeyBinding; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.event.TickEvent; import net.minecraftforge.event.TickEvent.ClientTickEvent; import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.fml.client.registry.ClientRegistry; import net.minecraftforge.fml.common.Mod; import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent; @Mod("fpsbooster") public class FpsBooster { public static final Logger LOGGER = LogManager.getLogger(); public static final String MOD_ID = "fpsbooster"; public KeyBinding openGuiMenuKey = new KeyBinding("key.openfpsboostermenu", 72, "key.categories.menu");; private boolean isMenuOpen = false; @SubscribeEvent public void clientTickEvent(ClientTickEvent event) { if (openGuiMenuKey.isPressed()) { /** TODO * Run "H" key listener. */ //looper /*if (openGuiMenuKey.isPressed()) { if (isMenuOpen) { saveSettings(); closeMenu(); within it: isMenuOpen = false; } else { loadSettings(); openMenu(); within it: isMenuOpen = true; } }*/ System.out.println("Ayo man asdjhsakjf hdsahh fsadhf hhkdshk jksdrhfhsdajkhg jkhdfkjghsdfhgjk"); } } public FpsBooster() { //IEventBus Bus = FMLJavaModLoadingContext.get().getModEventBus(); MinecraftForge.EVENT_BUS.register(this); } } Quote Link to comment Share on other sites More sharing options...
Craftit7 Posted July 8, 2021 Author Share Posted July 8, 2021 Um i dont understand, it works fine on singleplayer, im gonna try it in mp rn Quote Link to comment Share on other sites More sharing options...
Craftit7 Posted July 8, 2021 Author Share Posted July 8, 2021 Uhhhh its works perfect on multiplayer Quote Link to comment Share on other sites More sharing options...
Craftit7 Posted July 8, 2021 Author Share Posted July 8, 2021 One more thing, if i keep holding the H key, it prints multiple times, i want to use it to open a gui so no matter how much u hold it for, the second u release it, the gui opens Quote Link to comment Share on other sites More sharing options...
Craftit7 Posted July 8, 2021 Author Share Posted July 8, 2021 How can i check if it is? 16 minutes ago, diesieben07 said: Did you install it on the server? Then check if it was released. Quote Link to comment Share on other sites More sharing options...
Craftit7 Posted July 8, 2021 Author Share Posted July 8, 2021 Also as i said before ITS CLIENT SIDE ONLYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY ONLY CLIENT WILL RUN IT Quote Link to comment Share on other sites More sharing options...
Craftit7 Posted July 8, 2021 Author Share Posted July 8, 2021 Uhm, Its a private mod Quote Link to comment Share on other sites More sharing options...
Craftit7 Posted July 8, 2021 Author Share Posted July 8, 2021 How can i make a dist-only event sub on a sep class?? Quote Link to comment Share on other sites More sharing options...
Luis_ST Posted July 8, 2021 Share Posted July 8, 2021 1 minute ago, Craftit7 said: How can i make a dist-only event sub on a sep class?? you need to set the "value" in the EventBusSubscriber annotation take a look at the forge doc -> there is a practical example https://mcforge.readthedocs.io/en/latest/events/intro/ Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.