Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add /cdebug command #650

Merged
merged 9 commits into from
Jul 7, 2024
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();
xpple marked this conversation as resolved.
Show resolved Hide resolved
}
return Command.SINGLE_SUCCESS;
}

public enum DebugScreenType implements StringRepresentable {
lugosieben marked this conversation as resolved.
Show resolved Hide resolved
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;
}
}
}