just a copy of petroleum right now
This commit is contained in:
commit
183c81258a
88 changed files with 7405 additions and 0 deletions
229
remappedSrc/pm/j4/petroleum/util/module/ModuleBase.java
Normal file
229
remappedSrc/pm/j4/petroleum/util/module/ModuleBase.java
Normal file
|
|
@ -0,0 +1,229 @@
|
|||
package pm.j4.petroleum.util.module;
|
||||
|
||||
import com.google.gson.JsonElement;
|
||||
import java.util.*;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.text.TranslatableText;
|
||||
import pm.j4.petroleum.gui.PModuleConfigEntry;
|
||||
import pm.j4.petroleum.util.config.ConfigHolder;
|
||||
import pm.j4.petroleum.util.config.ConfigManager;
|
||||
import pm.j4.petroleum.util.module.option.ConfigurationOption;
|
||||
|
||||
/**
|
||||
* The Basis for all mods, used so that modules all have a common activation point and settings.
|
||||
*/
|
||||
public abstract class ModuleBase {
|
||||
|
||||
/**
|
||||
* Instantiates a new Module base.
|
||||
* Parameters should be constant across restarts.
|
||||
*
|
||||
* @param name The name of the module
|
||||
* @param category the category
|
||||
* @param activatable Whether a module can be activated, or if it will remain in the state it was upon startup
|
||||
* @param hidden Whether the module will show up in @link pm.j4.petroleum.modules.menu.ModMenu or the active module list
|
||||
* @param hasConfigMenu whether a button in the configuration menu will show
|
||||
*/
|
||||
public ModuleBase(String name, String category, boolean activatable, boolean hidden, boolean hasConfigMenu) {
|
||||
this.moduleName = name;
|
||||
this.category = category;
|
||||
this.readableName = new TranslatableText(name);
|
||||
this.activatable = activatable;
|
||||
this.hidden = hidden;
|
||||
this.hasConfigMenu = hasConfigMenu;
|
||||
this.moduleOptions = this.getDefaultConfig();
|
||||
}
|
||||
|
||||
/**
|
||||
* Init.
|
||||
*/
|
||||
public void init() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Activate. Should be overridden.
|
||||
*
|
||||
* @param client the client
|
||||
*/
|
||||
public void activate(MinecraftClient client) {
|
||||
this.toggle();
|
||||
}
|
||||
|
||||
/**
|
||||
* Toggle mod.
|
||||
*/
|
||||
public void toggle() {
|
||||
Optional<ConfigHolder> config = ConfigManager.getConfig();
|
||||
config.ifPresent(configHolder -> configHolder.toggleModule(this.moduleName));
|
||||
}
|
||||
|
||||
/**
|
||||
* The Module's name.
|
||||
*/
|
||||
private final String moduleName;
|
||||
|
||||
/**
|
||||
* Gets module name.
|
||||
*
|
||||
* @return the module name
|
||||
*/
|
||||
public String getModuleName() {
|
||||
return this.moduleName;
|
||||
}
|
||||
|
||||
/**
|
||||
* The Category.
|
||||
*/
|
||||
private final String category;
|
||||
|
||||
/**
|
||||
* Gets category.
|
||||
*
|
||||
* @return the category
|
||||
*/
|
||||
public String getCategory() {
|
||||
return this.category;
|
||||
}
|
||||
|
||||
/**
|
||||
* The Readable name.
|
||||
*/
|
||||
private final TranslatableText readableName;
|
||||
|
||||
/**
|
||||
* Gets readable name.
|
||||
*
|
||||
* @return the readable name
|
||||
*/
|
||||
public TranslatableText getReadableName() {
|
||||
return this.readableName;
|
||||
}
|
||||
|
||||
/**
|
||||
* The Activatable.
|
||||
*/
|
||||
private final boolean activatable;
|
||||
|
||||
/**
|
||||
* Is activatable boolean.
|
||||
*
|
||||
* @return the boolean
|
||||
*/
|
||||
public boolean isActivatable() {
|
||||
return activatable;
|
||||
}
|
||||
|
||||
/**
|
||||
* The Hidden.
|
||||
*/
|
||||
private final boolean hidden;
|
||||
|
||||
/**
|
||||
* Is hidden boolean.
|
||||
*
|
||||
* @return the boolean
|
||||
*/
|
||||
public boolean isHidden() {
|
||||
return hidden;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* The Has config menu.
|
||||
*/
|
||||
private final boolean hasConfigMenu;
|
||||
|
||||
/**
|
||||
* Configurable boolean.
|
||||
*
|
||||
* @return the boolean
|
||||
*/
|
||||
public boolean configurable() {
|
||||
return hasConfigMenu;
|
||||
}
|
||||
|
||||
/**
|
||||
* The Module options.
|
||||
*/
|
||||
private final Map<String, ConfigurationOption> moduleOptions;
|
||||
|
||||
/**
|
||||
* Gets module configuration.
|
||||
*
|
||||
* @return the module configuration
|
||||
*/
|
||||
public Map<String, ConfigurationOption> getModuleConfiguration() {
|
||||
return moduleOptions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets config option.
|
||||
* This will fail if the option is not already present in a module.
|
||||
* <p>
|
||||
*
|
||||
* @param key the key
|
||||
* @param value the value
|
||||
* @return whether the operation was successful.
|
||||
*/
|
||||
public boolean setConfigOption(String key, JsonElement value) {
|
||||
if (moduleOptions.containsKey(key)) {
|
||||
moduleOptions.get(key).fromJson(value);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Has option boolean.
|
||||
*
|
||||
* @param key the key
|
||||
* @return the boolean
|
||||
*/
|
||||
public boolean hasOption(String key) {
|
||||
return moduleOptions.containsKey(key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets default config.
|
||||
*
|
||||
* @return the default config
|
||||
*/
|
||||
protected Map<String, ConfigurationOption> getDefaultConfig() {
|
||||
return new HashMap<>();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets config option.
|
||||
*
|
||||
* @param key the key
|
||||
* @return the config option
|
||||
*/
|
||||
public Optional<ConfigurationOption> getConfigOption(String key) {
|
||||
if (moduleOptions.containsKey(key)) {
|
||||
return Optional.of(moduleOptions.get(key));
|
||||
}
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets config entries.
|
||||
*
|
||||
* @return the config entries
|
||||
*/
|
||||
public List<PModuleConfigEntry> getConfigEntries() {
|
||||
List<PModuleConfigEntry> entries = new ArrayList<>();
|
||||
this.getModuleConfiguration().forEach((name, option) -> entries.add(new PModuleConfigEntry(option, new TranslatableText(name))));
|
||||
return entries;
|
||||
}
|
||||
|
||||
/**
|
||||
* Equals boolean.
|
||||
*
|
||||
* @param other the other
|
||||
* @return the boolean
|
||||
*/
|
||||
public boolean equals(ModuleBase other) {
|
||||
return Objects.equals(this.moduleName, other.getModuleName());
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,38 @@
|
|||
package pm.j4.petroleum.util.module.option;
|
||||
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonPrimitive;
|
||||
|
||||
/**
|
||||
* The type Boolean value.
|
||||
*/
|
||||
public class BooleanOption extends ConfigurationOption {
|
||||
/**
|
||||
* The Value.
|
||||
*/
|
||||
private boolean value;
|
||||
|
||||
/**
|
||||
* Instantiates a new Boolean option.
|
||||
*
|
||||
* @param description the description
|
||||
*/
|
||||
public BooleanOption(String description) {
|
||||
super(description);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getStringValue() {
|
||||
return Boolean.toString(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromJson(JsonElement e) {
|
||||
this.value = e.getAsBoolean();
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonElement toJson() {
|
||||
return new JsonPrimitive(value);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,59 @@
|
|||
package pm.j4.petroleum.util.module.option;
|
||||
|
||||
import com.google.gson.JsonElement;
|
||||
|
||||
/**
|
||||
* The type Configuration option.
|
||||
*/
|
||||
public abstract class ConfigurationOption {
|
||||
/**
|
||||
* The Description.
|
||||
*/
|
||||
private final String description;
|
||||
|
||||
/**
|
||||
* Instantiates a new Configuration option.
|
||||
*
|
||||
* @param description the description
|
||||
*/
|
||||
protected ConfigurationOption(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets description.
|
||||
*
|
||||
* @return the description
|
||||
*/
|
||||
public final String getDescription() {
|
||||
return this.description;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets string value.
|
||||
*
|
||||
* @return the string value
|
||||
*/
|
||||
public abstract String getStringValue();
|
||||
|
||||
/**
|
||||
* From json.
|
||||
*
|
||||
* @param e the e
|
||||
*/
|
||||
public abstract void fromJson(JsonElement e);
|
||||
|
||||
/**
|
||||
* To json json element.
|
||||
*
|
||||
* @return the json element
|
||||
*/
|
||||
public abstract JsonElement toJson();
|
||||
|
||||
/**
|
||||
* Update.
|
||||
*/
|
||||
public void update() {
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,38 @@
|
|||
package pm.j4.petroleum.util.module.option;
|
||||
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonPrimitive;
|
||||
|
||||
/**
|
||||
* The type Integer value.
|
||||
*/
|
||||
public class IntegerOption extends ConfigurationOption {
|
||||
/**
|
||||
* The Value.
|
||||
*/
|
||||
private int value;
|
||||
|
||||
/**
|
||||
* Instantiates a new Integer option.
|
||||
*
|
||||
* @param description the description
|
||||
*/
|
||||
protected IntegerOption(String description) {
|
||||
super(description);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getStringValue() {
|
||||
return Integer.toString(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromJson(JsonElement e) {
|
||||
this.value = e.getAsInt();
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonElement toJson() {
|
||||
return new JsonPrimitive(value);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,60 @@
|
|||
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 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);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,32 @@
|
|||
package pm.j4.petroleum.util.module.option;
|
||||
|
||||
import com.google.gson.JsonElement;
|
||||
|
||||
/**
|
||||
* The type List option.
|
||||
*/
|
||||
public class ListOption extends ConfigurationOption {
|
||||
/**
|
||||
* Instantiates a new List option.
|
||||
*
|
||||
* @param description the description
|
||||
*/
|
||||
protected ListOption(String description) {
|
||||
super(description);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getStringValue() {
|
||||
return "ListObject";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromJson(JsonElement e) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonElement toJson() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,38 @@
|
|||
package pm.j4.petroleum.util.module.option;
|
||||
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonPrimitive;
|
||||
|
||||
/**
|
||||
* The type String value.
|
||||
*/
|
||||
public class StringOption extends ConfigurationOption {
|
||||
|
||||
/**
|
||||
* The Value.
|
||||
*/
|
||||
private String value;
|
||||
|
||||
/**
|
||||
* Instantiates a new String option.
|
||||
*
|
||||
* @param description the description
|
||||
*/
|
||||
protected StringOption(String description) {
|
||||
super(description);
|
||||
}
|
||||
|
||||
public String getStringValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromJson(JsonElement e) {
|
||||
this.value = e.getAsString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonElement toJson() {
|
||||
return new JsonPrimitive(value);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue