aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/co
diff options
context:
space:
mode:
author alemidev <me@alemi.dev>2023-01-29 05:03:31 +0100
committer alemidev <me@alemi.dev>2023-01-29 05:03:31 +0100
commit40ef8c34ae4987f0825e8f98ddc7375546757226 (patch)
treef3867944757aa734e259f62536e72df4c97de4d1 /src/main/java/co
parent4b6bab1e8b3d50ccb67fa8380c591a5b0c00b16f (diff)
feat: added a crude but working way to make opts
Diffstat (limited to 'src/main/java/co')
-rw-r--r--src/main/java/co/fantabos/bscv/Module.java45
-rw-r--r--src/main/java/co/fantabos/bscv/modules/Fullbright.java7
2 files changed, 51 insertions, 1 deletions
diff --git a/src/main/java/co/fantabos/bscv/Module.java b/src/main/java/co/fantabos/bscv/Module.java
index adb5297..620ece2 100644
--- a/src/main/java/co/fantabos/bscv/Module.java
+++ b/src/main/java/co/fantabos/bscv/Module.java
@@ -1,6 +1,7 @@
package co.fantabos.bscv;
import com.mojang.brigadier.CommandDispatcher;
+import com.mojang.brigadier.arguments.ArgumentType;
import net.minecraft.command.CommandSource;
import net.minecraft.command.Commands;
@@ -39,9 +40,49 @@ public abstract class Module {
return 1;
})
)
+ .executes(ctx -> {
+ log(String.format("=[ %s ]%s", this.name, this.enabled.get() ? "+" : ""));
+ // TODO: print all mod options!
+ return 1;
+ })
);
}
+ public <T> ForgeConfigSpec.ConfigValue<T> option(
+ String name,
+ String comment,
+ T fallback,
+ ArgumentType<T> argument,
+ Class<T> clazz,
+ ForgeConfigSpec.Builder builder,
+ CommandDispatcher<CommandSource> dispatcher
+ ) {
+ ForgeConfigSpec.ConfigValue<T> conf = builder
+ .comment(comment)
+ .define(name, fallback);
+
+ dispatcher.register(
+ Commands.literal(this.name.toLowerCase())
+ .then(
+ Commands.literal(name)
+ .then(
+ Commands.argument(name, argument)
+ .executes( ctx -> {
+ conf.set(ctx.getArgument(name, clazz));
+ conf.save();
+ log(String.format("> %s -> %s", name, conf.get().toString()));
+ return 1;
+ }))
+ .executes(ctx -> {
+ log(String.format("> %s: %s", name, conf.get().toString()));
+ return 1;
+ })
+ )
+ );
+
+ return conf;
+ }
+
protected void onEnabled() {}
protected void onDisabled() {}
@@ -53,14 +94,18 @@ public abstract class Module {
public final void enable() {
MinecraftForge.EVENT_BUS.register(this);
this.enabled.set(true);
+ this.enabled.save();
this.onEnabled();
log(String.format("%s enabled", this.name));
+ BoSCoVicino.LOGGER.info(String.format("%s enabled", this.name));
}
public final void disable() {
MinecraftForge.EVENT_BUS.unregister(this);
this.enabled.set(false);
+ this.enabled.save();
this.onDisabled();
log(String.format("%s disabled", this.name));
+ BoSCoVicino.LOGGER.info(String.format("%s disabled", this.name));
}
}
diff --git a/src/main/java/co/fantabos/bscv/modules/Fullbright.java b/src/main/java/co/fantabos/bscv/modules/Fullbright.java
index d518448..5c2ce5f 100644
--- a/src/main/java/co/fantabos/bscv/modules/Fullbright.java
+++ b/src/main/java/co/fantabos/bscv/modules/Fullbright.java
@@ -1,6 +1,7 @@
package co.fantabos.bscv.modules;
import com.mojang.brigadier.CommandDispatcher;
+import com.mojang.brigadier.arguments.StringArgumentType;
import net.minecraft.command.CommandSource;
import net.minecraft.potion.Effect;
@@ -19,7 +20,11 @@ public class Fullbright extends Module {
public Fullbright(ForgeConfigSpec.Builder builder, CommandDispatcher<CommandSource> dispatcher) {
super("Fullbright", Group.VISION, builder, dispatcher);
- this.mode = builder.comment("either potion or gamma").define("mode", "potion");
+ this.mode = this.option(
+ "mode", "either potion or gamma", "potion",
+ StringArgumentType.string(), String.class,
+ builder, dispatcher
+ );
}
@SubscribeEvent