[[Template core/global/global/includeCSS is throwing an error. This theme may be out of date. Run the support tool in the AdminCP to restore the default theme.]] Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

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?

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.

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

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.