From 78048b70b92e7eadb4d8f8641f8c57e41c0d1cba Mon Sep 17 00:00:00 2001 From: LostLuma Date: Sat, 2 Sep 2023 15:37:18 +0200 Subject: [PATCH] Add information about reduced frame rate to debug screen --- .../impl/mixin/DebugScreenOverlayMixin.java | 31 +++++++++++++++++++ src/main/resources/dynamic_fps.mixins.json | 1 + 2 files changed, 32 insertions(+) create mode 100644 src/main/java/dynamic_fps/impl/mixin/DebugScreenOverlayMixin.java diff --git a/src/main/java/dynamic_fps/impl/mixin/DebugScreenOverlayMixin.java b/src/main/java/dynamic_fps/impl/mixin/DebugScreenOverlayMixin.java new file mode 100644 index 00000000..1565ad04 --- /dev/null +++ b/src/main/java/dynamic_fps/impl/mixin/DebugScreenOverlayMixin.java @@ -0,0 +1,31 @@ +package dynamic_fps.impl.mixin; + +import java.util.List; +import java.util.Locale; + +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; + +import dynamic_fps.impl.DynamicFPSMod; +import dynamic_fps.impl.PowerState; +import net.minecraft.client.gui.components.DebugScreenOverlay; + +@Mixin(DebugScreenOverlay.class) +public class DebugScreenOverlayMixin { + /* + * Insert information about effective frame rate below misleading FPS counter. + */ + @Inject(method = "getGameInformation", at = @At("RETURN")) + private void onGetGameInformation(CallbackInfoReturnable> callbackInfo) { + var status = DynamicFPSMod.powerState(); + + if (status != PowerState.FOCUSED) { + var result = callbackInfo.getReturnValue(); + int target = DynamicFPSMod.targetFrameRate(); + + result.add(2, String.format(Locale.ROOT, "§c[Dynamic FPS] FPS: %s P: %s§r", target, status.toString().toLowerCase())); + } + } +} diff --git a/src/main/resources/dynamic_fps.mixins.json b/src/main/resources/dynamic_fps.mixins.json index ca49df0a..3c29163e 100644 --- a/src/main/resources/dynamic_fps.mixins.json +++ b/src/main/resources/dynamic_fps.mixins.json @@ -4,6 +4,7 @@ "compatibilityLevel": "JAVA_17", "mixins": [], "client": [ + "DebugScreenOverlayMixin", "GameRendererMixin", "GuiMixin", "LoadingOverlayMixin",