Search in sources :

Example 1 with ClientProxy

use of me.desht.pneumaticcraft.proxy.ClientProxy in project pnc-repressurized by TeamPneumatic.

the class GuiKeybindCheckBox method setOrAddKeybind.

/**
 * @param keybindName
 * @param keyCode     when a value of <0 is parsed, this will function as a getter, with a chance of returning null.
 * @return
 */
public static KeyBinding setOrAddKeybind(String keybindName, int keyCode) {
    GameSettings gameSettings = FMLClientHandler.instance().getClient().gameSettings;
    for (KeyBinding keyBinding : gameSettings.keyBindings) {
        if (keyBinding != null && keyBinding.getKeyDescription().equals(keybindName)) {
            if (keybindName.equals(keyBinding.getKeyDescription())) {
                if (keyCode >= 0) {
                    keyBinding.setKeyCode(keyCode);
                    KeyBinding.resetKeyBindingArrayAndHash();
                    gameSettings.saveOptions();
                }
                return keyBinding;
            }
        }
    }
    // in ClientProxy#getAllKeybindsFromOptionsFile() during pre-init)
    if (keyCode < 0) {
        if (((ClientProxy) PneumaticCraftRepressurized.proxy).keybindToKeyCodes.containsKey(keybindName)) {
            keyCode = ((ClientProxy) PneumaticCraftRepressurized.proxy).keybindToKeyCodes.get(keybindName);
        } else {
            return null;
        }
    }
    KeyBinding keyBinding = new KeyBinding(keybindName, keyCode, Names.PNEUMATIC_KEYBINDING_CATEGORY);
    ClientRegistry.registerKeyBinding(keyBinding);
    KeyBinding.resetKeyBindingArrayAndHash();
    gameSettings.saveOptions();
    return keyBinding;
}
Also used : KeyBinding(net.minecraft.client.settings.KeyBinding) ClientProxy(me.desht.pneumaticcraft.proxy.ClientProxy) GameSettings(net.minecraft.client.settings.GameSettings)

Aggregations

ClientProxy (me.desht.pneumaticcraft.proxy.ClientProxy)1 GameSettings (net.minecraft.client.settings.GameSettings)1 KeyBinding (net.minecraft.client.settings.KeyBinding)1