From d497c1d976a75eef67fb508a1c40ce7016589295 Mon Sep 17 00:00:00 2001 From: alemi Date: Tue, 28 Feb 2023 17:00:05 +0100 Subject: feat: some initial work on Abstract Module --- src/main/java/ftbsc/bscv/modules/Module.java | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/src/main/java/ftbsc/bscv/modules/Module.java b/src/main/java/ftbsc/bscv/modules/Module.java index 6ac71b3..0f73a7a 100644 --- a/src/main/java/ftbsc/bscv/modules/Module.java +++ b/src/main/java/ftbsc/bscv/modules/Module.java @@ -22,12 +22,10 @@ public abstract class Module { public final String name; public final Group group; - public final ForgeConfigSpec.ConfigValue enabled; - protected Module(String name, Group group, ForgeConfigSpec.Builder builder, CommandDispatcher dispatcher) { - this.name = name; - this.group = group; + protected ForgeConfigSpec.ConfigValue enabled; + public void initialize(ForgeConfigSpec.Builder builder, CommandDispatcher dispatcher) { builder.push(this.name.toLowerCase()); this.enabled = builder .comment(String.format("Enables %s", this.name)) @@ -60,6 +58,21 @@ public abstract class Module { return 1; }) ); + + this.register(builder, dispatcher); + + builder.pop(); + } + + public abstract void register(ForgeConfigSpec.Builder builder, CommandDispatcher dispatcher); + + protected Module(ForgeConfigSpec.Builder builder, CommandDispatcher dispatcher) { + // TODO can this be done in a less magic way? + String[] pkg = this.getClass().getPackage().getName().split("."); + this.group = Group.valueOf(pkg[pkg.length-1].toUpperCase()); + this.name = this.getClass().getName(); + + this.initialize(builder, dispatcher); } public Module done(ForgeConfigSpec.Builder builder) { -- cgit v1.2.3-56-ga3b1