Jump to content

Recommended Posts

Posted

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?

Posted

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.

  • Like 1
Posted

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);
}

 

  • 11 months later...
Posted
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?

  • 7 months later...
Posted (edited)
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 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.

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.