-
-
Notifications
You must be signed in to change notification settings - Fork 126
Add cfps command #726
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
Merged
Merged
Add cfps command #726
Changes from 14 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
af0f389
Add cfps command
xpple 9d6d204
what I'm thinking
wagyourtail c5b592c
dont actually need to change this part
wagyourtail 482ff8f
unlimited first
wagyourtail d0c481f
simplify mixins
wagyourtail ffccaf9
reverse order
wagyourtail c511859
cut off values
wagyourtail 4e6c6c3
add getter, fix common refresh rate list
wagyourtail fdf9ff3
mojang sorts them anyway -_-
wagyourtail 161998e
make translation keys same as xpple
wagyourtail 2bf401a
Update src/main/java/net/earthcomputer/clientcommands/mixin/commands/…
wagyourtail c05edc5
fix import
wagyourtail 1930cf5
Update src/main/java/net/earthcomputer/clientcommands/command/Framera…
wagyourtail b5c7719
2 values of monitors I actually have
wagyourtail f596256
don't chop common refreshrates
wagyourtail c4b359d
fix translation keys
wagyourtail 3478e8b
Update src/main/resources/assets/clientcommands/lang/en_us.json
wagyourtail File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
80 changes: 80 additions & 0 deletions
80
src/main/java/net/earthcomputer/clientcommands/command/FramerateCommand.java
This file contains hidden or 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,80 @@ | ||
package net.earthcomputer.clientcommands.command; | ||
|
||
import com.mojang.brigadier.CommandDispatcher; | ||
import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource; | ||
import net.minecraft.client.Minecraft; | ||
import net.minecraft.network.chat.Component; | ||
|
||
import static com.mojang.brigadier.arguments.IntegerArgumentType.*; | ||
import static net.fabricmc.fabric.api.client.command.v2.ClientCommandManager.*; | ||
|
||
public class FramerateCommand { | ||
private static final int[] COMMON_REFRESH_RATES = new int[] { | ||
30, | ||
45, | ||
60, | ||
75, | ||
90, | ||
100, | ||
120, | ||
144, | ||
165, | ||
180, | ||
240, | ||
300, | ||
360, | ||
420, | ||
480, | ||
540, | ||
600 | ||
}; | ||
|
||
public static void register(CommandDispatcher<FabricClientCommandSource> dispatcher) { | ||
dispatcher.register(literal("cfps") | ||
.executes(ctx -> getMaxFps(ctx.getSource())) | ||
.then(literal("unlimited") | ||
.executes(ctx -> maxFps(ctx.getSource(), Integer.MAX_VALUE))) | ||
.then(argument("maxfps", integer()) | ||
.suggests((context, builder) -> { | ||
int maxFps = getDisplayMaxFramerate(); | ||
for (int refreshRate : COMMON_REFRESH_RATES) { | ||
if (refreshRate > maxFps) { | ||
break; | ||
} | ||
builder.suggest(refreshRate); | ||
} | ||
return builder.buildFuture(); | ||
}) | ||
.executes(ctx -> maxFps(ctx.getSource(), getInteger(ctx, "maxfps"))) | ||
) | ||
); | ||
|
||
} | ||
|
||
private static int getMaxFps(FabricClientCommandSource source) { | ||
int framerateLimit = source.getClient().getFramerateLimitTracker().getFramerateLimit(); | ||
if (framerateLimit < Integer.MAX_VALUE) { | ||
source.sendFeedback(Component.translatable("commands.cfps.success.get", framerateLimit)); | ||
} else { | ||
source.sendFeedback(Component.translatable("commands.cfps.success.get.unlimited")); | ||
} | ||
return framerateLimit; | ||
} | ||
|
||
private static int maxFps(FabricClientCommandSource source, int maxFps) { | ||
source.getClient().getFramerateLimitTracker().setFramerateLimit(maxFps); | ||
if (maxFps == Integer.MAX_VALUE) { | ||
source.sendFeedback(Component.translatable("commands.cfps.success.set.unlimited")); | ||
} else { | ||
source.sendFeedback(Component.translatable("commands.cfps.success.set", maxFps)); | ||
} | ||
return maxFps; | ||
} | ||
|
||
private static int getDisplayMaxFramerate() { | ||
return Minecraft.getInstance().virtualScreen.screenManager.monitors.values().stream() | ||
.mapToInt(monitor -> monitor.getCurrentMode().getRefreshRate()) | ||
.max().orElseThrow(); | ||
} | ||
|
||
} |
17 changes: 17 additions & 0 deletions
17
src/main/java/net/earthcomputer/clientcommands/mixin/commands/fps/MinecraftMixin.java
This file contains hidden or 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,17 @@ | ||
package net.earthcomputer.clientcommands.mixin.commands.fps; | ||
|
||
import com.llamalad7.mixinextras.injector.ModifyExpressionValue; | ||
import net.minecraft.client.Minecraft; | ||
import net.minecraft.client.Options; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
|
||
@Mixin(Minecraft.class) | ||
public class MinecraftMixin { | ||
|
||
@ModifyExpressionValue(method = "runTick", at = @At(value = "CONSTANT", args = "intValue=" + Options.UNLIMITED_FRAMERATE_CUTOFF)) | ||
wagyourtail marked this conversation as resolved.
Show resolved
Hide resolved
|
||
private int fixMaxFps(int fps) { | ||
return Integer.MAX_VALUE; | ||
} | ||
|
||
} |
20 changes: 20 additions & 0 deletions
20
src/main/java/net/earthcomputer/clientcommands/mixin/commands/fps/OptionsMixin.java
This file contains hidden or 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,20 @@ | ||
package net.earthcomputer.clientcommands.mixin.commands.fps; | ||
|
||
import net.minecraft.client.Options; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.ModifyArg; | ||
|
||
@Mixin(Options.class) | ||
public class OptionsMixin { | ||
|
||
@ModifyArg(method = "lambda$new$8", at = @At(value = "INVOKE", target = "Lcom/mojang/blaze3d/platform/FramerateLimitTracker;setFramerateLimit(I)V")) | ||
private static int fixMaxFpsSet(int maxFps) { | ||
if (maxFps == Options.UNLIMITED_FRAMERATE_CUTOFF) { | ||
return Integer.MAX_VALUE; | ||
} | ||
return maxFps; | ||
} | ||
|
||
|
||
} |
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.