-
-
Notifications
You must be signed in to change notification settings - Fork 117
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* 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
1 parent
23eedd2
commit b5ed915
Showing
2 changed files
with
50 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
src/main/java/net/earthcomputer/clientcommands/command/CDebugCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} |