Search in sources :

Example 1 with ClientProxy

use of pneumaticCraft.proxy.ClientProxy in project PneumaticCraft by MineMaarten.

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;
            }
        }
    }
    //When the keybind wasn't added yet
    if (keyCode < 0) {
        if (((ClientProxy) PneumaticCraft.proxy).keybindToKeyCodes.containsKey(keybindName)) {
            //If the keybind can be found in the options file
            keyCode = ((ClientProxy) PneumaticCraft.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(pneumaticCraft.proxy.ClientProxy) GameSettings(net.minecraft.client.settings.GameSettings)

Aggregations

GameSettings (net.minecraft.client.settings.GameSettings)1 KeyBinding (net.minecraft.client.settings.KeyBinding)1 ClientProxy (pneumaticCraft.proxy.ClientProxy)1