diff options
-rw-r--r-- | src/main/java/co/fantabos/bscv/BoSCoVicino.java | 28 | ||||
-rw-r--r-- | src/main/java/co/fantabos/bscv/Mod.java | 29 |
2 files changed, 53 insertions, 4 deletions
diff --git a/src/main/java/co/fantabos/bscv/BoSCoVicino.java b/src/main/java/co/fantabos/bscv/BoSCoVicino.java index afb5029..58b8438 100644 --- a/src/main/java/co/fantabos/bscv/BoSCoVicino.java +++ b/src/main/java/co/fantabos/bscv/BoSCoVicino.java @@ -3,7 +3,9 @@ package co.fantabos.bscv; import net.minecraft.block.Block; import net.minecraft.block.Blocks; import net.minecraft.client.Minecraft; +import net.minecraftforge.common.ForgeConfigSpec; import net.minecraftforge.common.MinecraftForge; +import net.minecraftforge.event.RegisterCommandsEvent; import net.minecraftforge.event.RegistryEvent; import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.fml.InterModComms; @@ -19,6 +21,8 @@ import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; +import java.util.ArrayList; +import java.util.List; import java.util.stream.Collectors; // The value here should match an entry in the META-INF/mods.toml file @@ -29,6 +33,8 @@ public class BoSCoVicino { public static Minecraft minecraft; + public static List<Mod> mods; + public BoSCoVicino() { // Register the setup method for modloading FMLJavaModLoadingContext.get().getModEventBus().addListener(this::setup); @@ -39,10 +45,22 @@ public class BoSCoVicino { // Register the doClientStuff method for modloading FMLJavaModLoadingContext.get().getModEventBus().addListener(this::doClientStuff); - ModLoadingContext.get().registerConfig(Type.CLIENT, Configuration.SPEC, "bscv.toml"); + // Store minecraft instance BoSCoVicino.minecraft = Minecraft.getInstance(); + ForgeConfigSpec.Builder builder = new ForgeConfigSpec.Builder(); + + // load and register mods + BoSCoVicino.mods = new ArrayList<Mod>(); + + BoSCoVicino.mods.add((Mod) new Fullbright(builder)); + + ForgeConfigSpec spec = builder.build(); + + // register config handler + ModLoadingContext.get().registerConfig(Type.CLIENT, spec, "bscv.toml"); + // Register ourselves for server and other game events we are interested in MinecraftForge.EVENT_BUS.register(this); } @@ -69,6 +87,14 @@ public class BoSCoVicino { map(m->m.getMessageSupplier().get()). collect(Collectors.toList())); } + + @SubscribeEvent + public void onRegisterCommand(RegisterCommandsEvent event) { + for (Mod mod : BoSCoVicino.mods) { + mod.registerCommands(event.getDispatcher()); + } + } + // You can use SubscribeEvent and let the Event Bus discover methods to call @SubscribeEvent public void onServerStarting(FMLServerStartingEvent event) { diff --git a/src/main/java/co/fantabos/bscv/Mod.java b/src/main/java/co/fantabos/bscv/Mod.java index ddf1f65..6a351b5 100644 --- a/src/main/java/co/fantabos/bscv/Mod.java +++ b/src/main/java/co/fantabos/bscv/Mod.java @@ -1,5 +1,10 @@ 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; import net.minecraftforge.common.ForgeConfigSpec; import net.minecraftforge.common.MinecraftForge; @@ -15,14 +20,32 @@ public abstract class Mod { public final Group group; public final ForgeConfigSpec.ConfigValue<Boolean> enabled; - Mod(String name, Group group, ForgeConfigSpec.Builder builder) { + protected Mod(String name, Group group, ForgeConfigSpec.Builder builder) { this.name = name; this.group = group; builder.push(this.name.toLowerCase()); this.enabled = builder - .comment(String.format("Enable %s", this.name)) - .define(this.name.toLowerCase(), false); + .comment(String.format("Enables %s", this.name)) + .define("enabled", false); + } + + protected void registerCommand(CommandDispatcher<CommandSource> dispatcher) { + dispatcher.register( + Commands.literal(this.name.toLowerCase()) + .then( + Commands.literal("toggle") + .executes(ctx -> { + this.toggle(); + return 1; + }) + ) + ); + } + + public void toggle() { + if (this.enabled.get()) this.disable(); + else this.enable(); } public void enable() { |