* @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.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;
}