diff --git a/src/main/java/com/minelittlepony/unicopia/Config.java b/src/main/java/com/minelittlepony/unicopia/Config.java index cc8d17f9..8ba097dc 100644 --- a/src/main/java/com/minelittlepony/unicopia/Config.java +++ b/src/main/java/com/minelittlepony/unicopia/Config.java @@ -15,6 +15,8 @@ public class Config extends JsonConfig { public final Setting> speciesWhiteList = value("server", "speciesWhiteList", new HashSet<>()); + public final Setting enableCheats = value("server", "enableCheats", false); + /*private final String preferredRaceComment = "The default preferred race. " + "This is the race a client requests when first joining a game. " + diff --git a/src/main/java/com/minelittlepony/unicopia/Debug.java b/src/main/java/com/minelittlepony/unicopia/Debug.java new file mode 100644 index 00000000..8db7ff14 --- /dev/null +++ b/src/main/java/com/minelittlepony/unicopia/Debug.java @@ -0,0 +1,16 @@ +package com.minelittlepony.unicopia; + +import net.fabricmc.loader.api.FabricLoader; +import net.fabricmc.loader.impl.util.Arguments; + +public final class Debug { + public static final boolean DEBUG_SPELLBOOK_CHAPTERS; + public static final boolean DEBUG_COMMANDS; + + static { + Arguments args = new Arguments(); + args.parse(FabricLoader.getInstance().getLaunchArguments(true)); + DEBUG_SPELLBOOK_CHAPTERS = "true".equalsIgnoreCase(args.getOrDefault("unicopia.debug.spellbookChapters", "false")); + DEBUG_COMMANDS = "true".equalsIgnoreCase(args.getOrDefault("unicopia.debug.commands", "false")); + } +} diff --git a/src/main/java/com/minelittlepony/unicopia/Unicopia.java b/src/main/java/com/minelittlepony/unicopia/Unicopia.java index 22e3bc41..e005fde8 100644 --- a/src/main/java/com/minelittlepony/unicopia/Unicopia.java +++ b/src/main/java/com/minelittlepony/unicopia/Unicopia.java @@ -62,7 +62,7 @@ public class Unicopia implements ModInitializer { ServerTickEvents.END_WORLD_TICK.register(w -> { ((BlockDestructionManager.Source)w).getDestructionManager().tick(); ZapAppleStageStore.get(w).tick(); - if (SpellbookChapterLoader.DEBUG) { + if (Debug.DEBUG_SPELLBOOK_CHAPTERS) { SpellbookChapterLoader.INSTANCE.sendUpdate(w.getServer()); } }); diff --git a/src/main/java/com/minelittlepony/unicopia/client/gui/LanSettingsScreen.java b/src/main/java/com/minelittlepony/unicopia/client/gui/LanSettingsScreen.java index ccc36e6e..476a9eaf 100644 --- a/src/main/java/com/minelittlepony/unicopia/client/gui/LanSettingsScreen.java +++ b/src/main/java/com/minelittlepony/unicopia/client/gui/LanSettingsScreen.java @@ -77,6 +77,13 @@ public class LanSettingsScreen extends GameGui { content.addButton(new Label(LEFT, row += 20)).getStyle().setText("unicopia.options.lan"); + content.addButton(new Toggle(LEFT, row += 20, config.enableCheats.get())) + .onChange(v -> { + config.enableCheats.set(v); + return v; + }) + .getStyle().setText("unicopia.options.cheats"); + Set whitelist = config.speciesWhiteList.get(); boolean whitelistEnabled = (forceShowWhitelist || !whitelist.isEmpty()) && !forceHideWhitelist; diff --git a/src/main/java/com/minelittlepony/unicopia/client/gui/spellbook/SpellbookChapterList.java b/src/main/java/com/minelittlepony/unicopia/client/gui/spellbook/SpellbookChapterList.java index b319d108..cc61d777 100644 --- a/src/main/java/com/minelittlepony/unicopia/client/gui/spellbook/SpellbookChapterList.java +++ b/src/main/java/com/minelittlepony/unicopia/client/gui/spellbook/SpellbookChapterList.java @@ -5,8 +5,8 @@ import java.util.function.BiConsumer; import java.util.stream.Stream; import com.minelittlepony.common.client.gui.IViewRoot; +import com.minelittlepony.unicopia.Debug; import com.minelittlepony.unicopia.Unicopia; -import com.minelittlepony.unicopia.container.SpellbookChapterLoader; import net.minecraft.client.util.math.MatrixStack; import net.minecraft.util.Identifier; @@ -39,7 +39,7 @@ public class SpellbookChapterList { } public Chapter getCurrentChapter() { - if (SpellbookChapterLoader.DEBUG) { + if (Debug.DEBUG_SPELLBOOK_CHAPTERS) { ClientChapters.getChapters().forEach(chapter -> { Optional.ofNullable(chapters.get(chapter.id())).flatMap(Chapter::content).ifPresent(old -> { chapter.content().ifPresent(neu -> neu.copyStateFrom(old)); diff --git a/src/main/java/com/minelittlepony/unicopia/client/gui/spellbook/SpellbookScreen.java b/src/main/java/com/minelittlepony/unicopia/client/gui/spellbook/SpellbookScreen.java index 222bb210..c3b4ecb3 100644 --- a/src/main/java/com/minelittlepony/unicopia/client/gui/spellbook/SpellbookScreen.java +++ b/src/main/java/com/minelittlepony/unicopia/client/gui/spellbook/SpellbookScreen.java @@ -8,6 +8,7 @@ import com.minelittlepony.common.client.gui.IViewRoot; import com.minelittlepony.common.client.gui.dimension.Bounds; import com.minelittlepony.common.client.gui.element.Button; import com.minelittlepony.common.client.gui.sprite.TextureSprite; +import com.minelittlepony.unicopia.Debug; import com.minelittlepony.unicopia.Unicopia; import com.minelittlepony.unicopia.client.gui.spellbook.SpellbookChapterList.*; import com.minelittlepony.unicopia.container.*; @@ -139,7 +140,7 @@ public class SpellbookScreen extends HandledScreen imple drawTexture(matrices, x, y, 0, 0, backgroundWidth, backgroundHeight, 512, 256); - if (SpellbookChapterLoader.DEBUG) { + if (Debug.DEBUG_SPELLBOOK_CHAPTERS) { clearAndInit(); } diff --git a/src/main/java/com/minelittlepony/unicopia/command/Commands.java b/src/main/java/com/minelittlepony/unicopia/command/Commands.java index d1310f89..5650c0a1 100644 --- a/src/main/java/com/minelittlepony/unicopia/command/Commands.java +++ b/src/main/java/com/minelittlepony/unicopia/command/Commands.java @@ -2,6 +2,7 @@ package com.minelittlepony.unicopia.command; import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback; +import com.minelittlepony.unicopia.Debug; import com.minelittlepony.unicopia.Unicopia; import net.fabricmc.fabric.api.command.v2.ArgumentTypeRegistry; @@ -17,13 +18,17 @@ public class Commands { new EnumArgumentType.Serializer() ); CommandRegistrationCallback.EVENT.register((dispatcher, access, environment) -> { - SpeciesCommand.register(dispatcher); RacelistCommand.register(dispatcher); - GravityCommand.register(dispatcher); - DisguiseCommand.register(dispatcher); - TraitCommand.register(dispatcher); EmoteCommand.register(dispatcher); - ManaCommand.register(dispatcher); + if (Unicopia.getConfig().enableCheats.get()) { + SpeciesCommand.register(dispatcher); + GravityCommand.register(dispatcher); + DisguiseCommand.register(dispatcher); + if (Debug.DEBUG_COMMANDS) { + TraitCommand.register(dispatcher); + ManaCommand.register(dispatcher); + } + } }); Object game = FabricLoader.getInstance().getGameInstance(); if (game instanceof MinecraftServer) { diff --git a/src/main/java/com/minelittlepony/unicopia/container/SpellbookChapterLoader.java b/src/main/java/com/minelittlepony/unicopia/container/SpellbookChapterLoader.java index b6181928..fce8d434 100644 --- a/src/main/java/com/minelittlepony/unicopia/container/SpellbookChapterLoader.java +++ b/src/main/java/com/minelittlepony/unicopia/container/SpellbookChapterLoader.java @@ -9,6 +9,7 @@ import org.slf4j.Logger; import com.google.gson.*; import com.minelittlepony.common.client.gui.dimension.Bounds; +import com.minelittlepony.unicopia.Debug; import com.minelittlepony.unicopia.Unicopia; import com.minelittlepony.unicopia.ability.magic.spell.crafting.IngredientWithSpell; import com.minelittlepony.unicopia.client.gui.spellbook.SpellbookChapterList.*; @@ -30,7 +31,6 @@ public class SpellbookChapterLoader extends JsonDataLoader implements Identifiab private static final Logger LOGGER = LogUtils.getLogger(); private static final Identifier ID = Unicopia.id("spellbook/chapters"); private static final Executor EXECUTOR = CompletableFuture.delayedExecutor(5, TimeUnit.SECONDS); - public static boolean DEBUG = false; public static final SpellbookChapterLoader INSTANCE = new SpellbookChapterLoader(); @@ -73,7 +73,7 @@ public class SpellbookChapterLoader extends JsonDataLoader implements Identifiab LOGGER.error("Could not load spellbook chapters due to exception", e); } - if (DEBUG) { + if (Debug.DEBUG_SPELLBOOK_CHAPTERS) { CompletableFuture.runAsync(() -> { try { Util.waitAndApply(executor -> reload(CompletableFuture::completedFuture, manager, profiler, profiler, Util.getMainWorkerExecutor(), executor)).get(); diff --git a/src/main/resources/assets/unicopia/lang/en_us.json b/src/main/resources/assets/unicopia/lang/en_us.json index 19f24da1..04e7cfae 100644 --- a/src/main/resources/assets/unicopia/lang/en_us.json +++ b/src/main/resources/assets/unicopia/lang/en_us.json @@ -466,6 +466,7 @@ "unicopia.options.whitelist": "Enable Whitelist", "unicopia.options.whitelist.race": "Allow %ss", "unicopia.options.whitelist.details": "* Select the races you wish to allow", + "unicopia.options.cheats": "Enable Cheats", "unicopia.options.client": "Client Settings", "unicopia.options.world": "World Settings", "unicopia.options.world.default_race": "Default Race: %s",