Skip to content

Commit 1cfb0e6

Browse files
committed
Add query subcommand
1 parent 60eaff1 commit 1cfb0e6

File tree

2 files changed

+20
-7
lines changed

2 files changed

+20
-7
lines changed

src/main/java/net/earthcomputer/clientcommands/command/FramerateCommand.java

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,25 @@ public class FramerateCommand {
1919

2020
public static void register(CommandDispatcher<FabricClientCommandSource> dispatcher) {
2121
dispatcher.register(literal("cfps")
22+
.executes(ctx -> getMaxFps(ctx.getSource()))
2223
.then(argument("maxfps", integer(1))
2324
.suggests((context, builder) -> builder.suggest(MAX_REFRESH_RATE.getAsInt()).buildFuture())
24-
.executes(ctx -> maxFps(ctx.getSource(), getInteger(ctx, "maxfps"))))
25+
.executes(ctx -> setMaxFps(ctx.getSource(), getInteger(ctx, "maxfps"))))
2526
.then(literal("unlimited")
26-
.executes(ctx -> maxFps(ctx.getSource(), MAX_REFRESH_RATE.getAsInt() + 1))));
27+
.executes(ctx -> setMaxFps(ctx.getSource(), MAX_REFRESH_RATE.getAsInt() + 1))));
2728
}
2829

29-
private static int maxFps(FabricClientCommandSource source, int maxFps) {
30+
private static int getMaxFps(FabricClientCommandSource source) {
31+
int framerateLimit = source.getClient().getFramerateLimitTracker().getFramerateLimit();
32+
if (framerateLimit > MAX_REFRESH_RATE.getAsInt()) {
33+
source.sendFeedback(Component.translatable("commands.cfps.getMaxFps.unlimited"));
34+
} else {
35+
source.sendFeedback(Component.translatable("commands.cfps.getMaxFps", framerateLimit));
36+
}
37+
return framerateLimit;
38+
}
39+
40+
private static int setMaxFps(FabricClientCommandSource source, int maxFps) {
3041
int maxRefreshRate = MAX_REFRESH_RATE.getAsInt();
3142
boolean unlimited;
3243
if (maxFps > maxRefreshRate) {
@@ -37,9 +48,9 @@ private static int maxFps(FabricClientCommandSource source, int maxFps) {
3748
}
3849
source.getClient().getFramerateLimitTracker().setFramerateLimit(maxFps);
3950
if (unlimited) {
40-
source.sendFeedback(Component.translatable("commands.cfps.unlimited"));
51+
source.sendFeedback(Component.translatable("commands.cfps.setMaxFps.unlimited"));
4152
} else {
42-
source.sendFeedback(Component.translatable("commands.cfps.success", maxFps));
53+
source.sendFeedback(Component.translatable("commands.cfps.setMaxFps.success", maxFps));
4354
}
4455
return maxFps;
4556
}

src/main/resources/assets/clientcommands/lang/en_us.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,10 @@
129129

130130
"commands.cfov.success": "Set FOV to %s",
131131

132-
"commands.cfps.success": "Set max FPS to %s",
133-
"commands.cfps.unlimited": "Set max FPS to unlimited",
132+
"commands.cfps.getMaxFps": "FPS is capped at %s",
133+
"commands.cfps.getMaxFps.unlimited": "FPS is unlimited",
134+
"commands.cfps.setMaxFps.success": "Set max FPS to %s",
135+
"commands.cfps.setMaxFps.unlimited": "Set max FPS to unlimited",
134136

135137
"commands.cfunction.limitReached": "Command limit (%s) reached",
136138
"commands.cfunction.success": "Ran %s commands from function %s",

0 commit comments

Comments
 (0)