aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author alemi <me@alemi.dev>2023-02-27 03:46:28 +0100
committer alemi <me@alemi.dev>2023-02-27 03:50:32 +0100
commite992b27d0414955bee634f7b6cef4ba32a264db9 (patch)
tree87657975dfc079de1fe658c56a18ee3413c0c8a2
parent38d183a775d1eb9b5fc60b8658e7de37a6f3d44e (diff)
feat: allow to set specific state via toggle cmd0.3.2
-rw-r--r--src/main/java/ftbsc/bscv/modules/Module.java17
1 files changed, 14 insertions, 3 deletions
diff --git a/src/main/java/ftbsc/bscv/modules/Module.java b/src/main/java/ftbsc/bscv/modules/Module.java
index 57a5a00..6ac71b3 100644
--- a/src/main/java/ftbsc/bscv/modules/Module.java
+++ b/src/main/java/ftbsc/bscv/modules/Module.java
@@ -1,9 +1,8 @@
package ftbsc.bscv.modules;
import com.mojang.brigadier.CommandDispatcher;
-import com.mojang.brigadier.arguments.ArgumentType;
+import com.mojang.brigadier.arguments.BoolArgumentType;
-import ftbsc.bscv.BoSCoVicino;
import net.minecraft.command.CommandSource;
import net.minecraft.command.Commands;
import net.minecraftforge.common.ForgeConfigSpec;
@@ -34,17 +33,29 @@ public abstract class Module {
.comment(String.format("Enables %s", this.name))
.define("enabled", false);
+ // TODO: can this be made an util or moved somewhere else?
dispatcher.register(
Commands.literal(this.name.toLowerCase())
.then(
Commands.literal("toggle")
+ .then(
+ Commands.argument("state", BoolArgumentType.bool())
+ .executes( ctx -> {
+ boolean value = ctx.getArgument("state", Boolean.class);
+ if (this.enabled.get() ^ value) { // must change
+ if (value) { this.enable(); }
+ else { this.disable(); }
+ }
+ return 1;
+ })
+ )
.executes(ctx -> {
this.toggle();
return 1;
})
)
.executes(ctx -> {
- log(String.format("=[ %s ]%s", this.name, this.enabled.get() ? "+" : ""));
+ log(String.format("%s [%s]", this.name, this.enabled.get() ? "ON" : "OFF"));
// TODO: print all mod options!
return 1;
})