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

Hi Guys,

 

i'm trying to change the input key of a keybinding if the keybinding is contained by a HashMap (which also contains the new input key).

 

Here is what i'm calling at the FMLClientSetupEvent. 

KeyBinding[] keyBindings = Minecraft.getInstance().gameSettings.keyBindings.clone();
        for (KeyBinding keyBinding : keyBindings) {
            if (SyncedKeyBindings.containsKey(keyBinding.getKeyDescription())) {
                KeyData data = SyncedKeyBindings.get(keyBinding.getKeyDescription());
                keyBinding.setKeyModifierAndCode(data.getModifier(), data.getValue());
                final GameSettings gameSettings = Minecraft.getInstance().gameSettings;

                if (data.getValue().toString().contains("mouse")) {
                    gameSettings.setKeyBindingCode(keyBinding, InputMappings.Type.MOUSE.getOrMakeInput(data.getValue().getKeyCode()));
                } else {
                    gameSettings.setKeyBindingCode(keyBinding, InputMappings.getInputByName(data.getValue().toString()));
                }

                LOGGER.debug("Changed " + data.getIdentidier() + " to " + data.getModifier().toString() + " + " + data.getValue().toString());
            }
        }

        KeyBinding.resetKeyBindingArrayAndHash();

 

For some reason the new input won't be appled to the keybinding.

Is the FMLClientSetupEvent to early to change the input key? Or am i missing something?

  • Author

I'm trying to load already changed keybindings from other Profiles to the current instance so the keybindings are already set if you start playing.

This only applies to keybindings which where marked in the original Profile and should sync to other Profiles.

  • Author

The GameSettings.setKeyBindingCode() Method should call the saveOptions() Method which should save the Keybindings to the options.txt file.

But the Keybindings only apply if there is no options.txt before startup.

If the options.txt has been generated, the loaded Keybindings don't apply to the started instance anymore.

 

Even if i load the options.txt again using the loadOptions() Method, the Keybinds won't be there.

 

Edit:

i guess the

if (net.minecraftforge.fml.client.ClientModLoader.isLoading()) return;

part inside of the saveOptions() chould be the issue since i'm calling it at the FMLClientSetupEvent.

 

Is there a better Event i chould use to apply the Keybindings?

 

Edited by Skyriis

  • Author

The loaded Keybindings only should be applied to the running instance at startup (or exactly after startup).

The Goal is to make a Mod which sets your favorite keybinds on the first load and sync changed (favorite) keybinds to other instances so you don't have to set them manually anymore.

 

  • Author

I could also start a new Thread at FMLClientSetupEvent which could wait for the loadup and instandly apply the Keybindings but i'm not sure if that would be a good way since the new Thread would have to check ClientModLoader.isLoading until it's false...

  • Author

I tried

new Thread(() -> {
                while (ClientModLoader.isLoading()) {
                    try {
                        TimeUnit.SECONDS.sleep(1);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
                Minecraft.getInstance().enqueue(() -> SyncHandler.applyKeybindings());
            }).start();

 and it would "work" but since GameSettings is not threadsafe it would be a bad idea to use this correct? :S

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.