kerosene/remappedSrc/pm/j4/petroleum/util/module/option/KeybindOption.java

61 lines
1.3 KiB
Java
Raw Permalink Normal View History

2020-12-20 04:19:55 +00:00
package pm.j4.kerosene.util.module.option;
2020-12-19 23:30:50 +00:00
import com.google.gson.JsonElement;
import net.minecraft.client.options.KeyBinding;
2020-12-20 04:19:55 +00:00
import pm.j4.kerosene.modules.bindings.BindingInfo;
import pm.j4.kerosene.util.config.ConfigManager;
import pm.j4.kerosene.util.config.GlobalConfig;
import pm.j4.kerosene.util.module.ModuleBase;
2020-12-19 23:30:50 +00:00
/**
* The type Keybind value.
*/
public class KeybindOption extends ConfigurationOption {
/**
* The Value.
*/
private KeyBinding value;
/**
* The Converted value.
*/
private BindingInfo convertedValue;
/**
* Instantiates a new Keybind option.
*
* @param description the description
*/
public KeybindOption(String description) {
super(description);
}
@Override
public String getStringValue() {
return value.getDefaultKey().getLocalizedText().getString();
}
@Override
public void fromJson(JsonElement e) {
BindingInfo bindingInfo = ConfigManager.deserializeElement(e, BindingInfo.class);
this.convertedValue = bindingInfo;
this.value = GlobalConfig.reconstructBinding(bindingInfo);
}
@Override
public JsonElement toJson() {
return null;
}
/**
* From keybind.
*
* @param bind the bind
* @param base the base
*/
public void fromKeybind(KeyBinding bind, ModuleBase base) {
this.value = bind;
this.convertedValue = GlobalConfig.extractBinding(bind, base);
}
}