67 lines
1.5 KiB
Java
67 lines
1.5 KiB
Java
|
package pm.j4.petroleum.util.module.option;
|
||
|
|
||
|
import com.google.gson.JsonElement;
|
||
|
import net.minecraft.client.options.KeyBinding;
|
||
|
import pm.j4.petroleum.modules.bindings.BindingInfo;
|
||
|
import pm.j4.petroleum.util.config.ConfigManager;
|
||
|
import pm.j4.petroleum.util.config.GlobalConfig;
|
||
|
import pm.j4.petroleum.util.module.ModuleBase;
|
||
|
|
||
|
/**
|
||
|
* The type Keybind value.
|
||
|
*/
|
||
|
public class KeybindOption extends ConfigurationOption {
|
||
|
|
||
|
/**
|
||
|
* The Value.
|
||
|
*/
|
||
|
private KeyBinding value;
|
||
|
/**
|
||
|
* The Converted value.
|
||
|
*/
|
||
|
private BindingInfo convertedValue;
|
||
|
|
||
|
/**
|
||
|
* Instantiates a new Configuration option.
|
||
|
*
|
||
|
* @param key
|
||
|
* @param description the description
|
||
|
* @param parent
|
||
|
*/
|
||
|
public KeybindOption(String key, String description, ModuleBase parent) {
|
||
|
super(key, description, parent);
|
||
|
}
|
||
|
|
||
|
public String getTranslationKey() {
|
||
|
return value.getTranslationKey();
|
||
|
}
|
||
|
|
||
|
@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);
|
||
|
}
|
||
|
}
|