Skip to content

Commit

Permalink
Add /cdebug command (#650)
Browse files Browse the repository at this point in the history
* Add /cdebug command

* Follow Guidelines

* Implement requested changes

* Fix imports

* Change continuation indent to 4

* Use enum instead of string literal

* Use CEnumArgument

* Use Command Source and Enum as parameters

* Make DebugScreenType Enum private

---------

Co-authored-by: Frederik van der Els <[email protected]>
  • Loading branch information
lugosieben and xpple authored Jul 7, 2024
1 parent 23eedd2 commit b5ed915
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ public static void registerCommands(CommandDispatcher<FabricClientCommandSource>
BookCommand.register(dispatcher);
CalcCommand.register(dispatcher);
CalcStackCommand.register(dispatcher, context);
CDebugCommand.register(dispatcher);
CEnchantCommand.register(dispatcher, context);
CFunctionCommand.register(dispatcher);
CGameModeCommand.register(dispatcher);
Expand Down
Original file line number Diff line number Diff line change
@@ -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<FabricClientCommandSource> 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;
}
}
}

0 comments on commit b5ed915

Please sign in to comment.