feat: allow to set specific state via toggle cmd
This commit is contained in:
parent
38d183a775
commit
e992b27d04
1 changed files with 14 additions and 3 deletions
|
@ -1,9 +1,8 @@
|
||||||
package ftbsc.bscv.modules;
|
package ftbsc.bscv.modules;
|
||||||
|
|
||||||
import com.mojang.brigadier.CommandDispatcher;
|
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.CommandSource;
|
||||||
import net.minecraft.command.Commands;
|
import net.minecraft.command.Commands;
|
||||||
import net.minecraftforge.common.ForgeConfigSpec;
|
import net.minecraftforge.common.ForgeConfigSpec;
|
||||||
|
@ -34,17 +33,29 @@ public abstract class Module {
|
||||||
.comment(String.format("Enables %s", this.name))
|
.comment(String.format("Enables %s", this.name))
|
||||||
.define("enabled", false);
|
.define("enabled", false);
|
||||||
|
|
||||||
|
// TODO: can this be made an util or moved somewhere else?
|
||||||
dispatcher.register(
|
dispatcher.register(
|
||||||
Commands.literal(this.name.toLowerCase())
|
Commands.literal(this.name.toLowerCase())
|
||||||
.then(
|
.then(
|
||||||
Commands.literal("toggle")
|
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 -> {
|
.executes(ctx -> {
|
||||||
this.toggle();
|
this.toggle();
|
||||||
return 1;
|
return 1;
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
.executes(ctx -> {
|
.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!
|
// TODO: print all mod options!
|
||||||
return 1;
|
return 1;
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in a new issue