feat: added a crude but working way to make opts
This commit is contained in:
parent
4b6bab1e8b
commit
40ef8c34ae
2 changed files with 51 additions and 1 deletions
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue