diff --git a/src/main/java/net/earthcomputer/clientcommands/ClientCommands.java b/src/main/java/net/earthcomputer/clientcommands/ClientCommands.java index fcdf9e61e..07dd5c813 100644 --- a/src/main/java/net/earthcomputer/clientcommands/ClientCommands.java +++ b/src/main/java/net/earthcomputer/clientcommands/ClientCommands.java @@ -120,6 +120,7 @@ public static void registerCommands(CommandDispatcher BookCommand.register(dispatcher); CalcCommand.register(dispatcher); CalcStackCommand.register(dispatcher, context); + CDebugCommand.register(dispatcher); CEnchantCommand.register(dispatcher, context); CFunctionCommand.register(dispatcher); CGameModeCommand.register(dispatcher); diff --git a/src/main/java/net/earthcomputer/clientcommands/command/CDebugCommand.java b/src/main/java/net/earthcomputer/clientcommands/command/CDebugCommand.java new file mode 100644 index 000000000..e1f08926e --- /dev/null +++ b/src/main/java/net/earthcomputer/clientcommands/command/CDebugCommand.java @@ -0,0 +1,49 @@ +package net.earthcomputer.clientcommands.command; + +import com.mojang.brigadier.Command; +import com.mojang.brigadier.CommandDispatcher; +import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource; +import net.minecraft.client.gui.components.DebugScreenOverlay; +import net.minecraft.util.StringRepresentable; +import org.jetbrains.annotations.NotNull; + +import static dev.xpple.clientarguments.arguments.CEnumArgument.*; +import static net.fabricmc.fabric.api.client.command.v2.ClientCommandManager.*; + +public class CDebugCommand { + public static void register(CommandDispatcher dispatcher) { + dispatcher.register(literal("cdebug") + .executes(ctx -> execute(ctx.getSource(), DebugScreenType.OVERLAY)) + .then(argument("type", enumArg(DebugScreenType.class)) + .executes(ctx -> execute(ctx.getSource(), getEnum(ctx, "type")))) + ); + } + + private static int execute(FabricClientCommandSource source, DebugScreenType type) { + DebugScreenOverlay debugScreenOverlay = source.getClient().getDebugOverlay(); + switch (type) { + case OVERLAY -> debugScreenOverlay.toggleOverlay(); + case FPS -> debugScreenOverlay.toggleFpsCharts(); + case NETWORK -> debugScreenOverlay.toggleNetworkCharts(); + case PROFILER -> debugScreenOverlay.toggleProfilerChart(); + } + return Command.SINGLE_SUCCESS; + } + + private enum DebugScreenType implements StringRepresentable { + OVERLAY("overlay"), + FPS("fps"), + NETWORK("network"), + PROFILER("profiler"); + + private final String name; + + DebugScreenType(String name) { + this.name = name; + } + + public @NotNull String getSerializedName() { + return this.name; + } + } +}