Posted May 19, 20205 yr I'm making a mod that adds in controls for abilities that can be activated when you're wearing a certain piece of armor (e.g. pressing the chestplate_ability key while wearing the Muteki Chestplate will give you Strength V for 30 seconds). I want 5 controls: One for each piece of armor individually and one for every applicable piece at once. For this reason, I'm trying to instantiate instances of KeyBinding. However, I have no idea what I'm doing and cannot find a tutorial for 1.15.2. Could someone explain to me what I'm supposed to do or link me to a tutorial?
May 19, 20205 yr Create a static final instance (could be just final as well) of your keybinding in a global variable and register it using ClientRegistry#registerKeyBinding during FMLClientSetupEvent. You will need to use packets to apply the potion effects.
May 19, 20205 yr Author I just tried that, but how do I make it appear in the controls menu, and make it possible to set the keybindings?
May 19, 20205 yr It should appear in the controls menu by default. I just verified this using: public static final KeyBinding TEST = new KeyBinding("key.test", KeyConflictContext.UNIVERSAL, InputMappings.Type.KEYSYM, GLFW.GLFW_KEY_J, "key.categories.test"); private void clientSetup(final FMLClientSetupEvent event) { ClientRegistry.registerKeyBinding(TEST); }
May 19, 20205 yr Author Silly me, I was using the run config for my other mod. ...except now the run config for this mod won't work, saying, "The mod file [filepath]/1.15.2/ArmorAbilities/bin/main has mods that were not found." What does this mean? Log posted debug-1.log.gz
May 15, 20214 yr On 5/19/2020 at 7:37 PM, ChampionAsh5357 said: It should appear in the controls menu by default. I just verified this using: public static final KeyBinding TEST = new KeyBinding("key.test", KeyConflictContext.UNIVERSAL, InputMappings.Type.KEYSYM, GLFW.GLFW_KEY_J, "key.categories.test"); private void clientSetup(final FMLClientSetupEvent event) { ClientRegistry.registerKeyBinding(TEST); } How can I do something with it? Like how can I run Code when this key is pressed?
December 22, 20213 yr On 5/15/2021 at 7:04 AM, diesieben07 said: Make your own thread. Sorry if this is necroposting but I have the keybind set up (mind you this is on .1.18 so I'm using the new KeyMapping rather than KeyBinding) But I don't quite understand how to make it be changeable in the Minecraft settings menu? I assumed it would be changeable after registering it but it's not and I don't get how to set it to be there. Code (sorry it's sloppy I'm just testing proof of concept, for now, I plan to clean it up later) @Mod.EventBusSubscriber public class KeyBindHandler { private static final KeyMapping MenuKey = new KeyMapping("key.menu", KeyConflictContext.UNIVERSAL, InputConstants.Type.KEYSYM, GLFW.GLFW_KEY_H, KeyMapping.CATEGORY_GAMEPLAY); @SubscribeEvent public static void registerKeyBinds (FMLClientSetupEvent e) { ClientRegistry.registerKeyBinding(MenuKey); } @SubscribeEvent public static void onKeyPress (InputEvent.KeyInputEvent e) { if (MenuKey.isDown()) { MenuUI.open(); } } } to be clear everything works, I can press h and open my GUI and use it the only thing is it cant be changed in the menu. Edit: lol I'm an idiot ignore me. Turns out i have to use the right event bus weird how that works huh *facepalm* so anyways I used a nested class and changed the event busses so that the ClientSetupEvent was under a MOD event bus and the KeyInputEvent was under a FORGE event bus and problem solved. Edited December 22, 20213 yr by Koolade446
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.