diff --git a/build.gradle b/build.gradle index 06cab9b5..19bd5952 100644 --- a/build.gradle +++ b/build.gradle @@ -22,6 +22,10 @@ dependencies { modImplementation libs.fabric.api modImplementation libs.fabric.loader + // Why do I need this on 0.15.x ..? + modImplementation libs.mixinextras + annotationProcessor libs.mixinextras + modApi libs.modmenu modApi libs.cloth.config } diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 0fc1bd35..0522f9cc 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -1,5 +1,7 @@ [versions] minecraft = "1.20" + +mixinextras = "0.3.2" fabric_loader = "0.15.3" modmenu = "7.0.1" @@ -9,6 +11,8 @@ cloth_config = "11.0.99" [libraries] minecraft = { module = "com.mojang:minecraft", version.ref = "minecraft" } + +mixinextras = { module = "io.github.llamalad7:mixinextras-fabric", version.ref = "mixinextras" } fabric_loader = { module = "net.fabricmc:fabric-loader", version.ref = "fabric_loader" } modmenu = { module = "com.terraformersmc:modmenu", version.ref = "modmenu" } diff --git a/src/main/java/dynamic_fps/impl/mixin/DebugScreenOverlayMixin.java b/src/main/java/dynamic_fps/impl/mixin/DebugScreenOverlayMixin.java index 1565ad04..3052064c 100644 --- a/src/main/java/dynamic_fps/impl/mixin/DebugScreenOverlayMixin.java +++ b/src/main/java/dynamic_fps/impl/mixin/DebugScreenOverlayMixin.java @@ -5,8 +5,8 @@ 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 com.llamalad7.mixinextras.injector.ModifyReturnValue; import dynamic_fps.impl.DynamicFPSMod; import dynamic_fps.impl.PowerState; @@ -14,18 +14,20 @@ @Mixin(DebugScreenOverlay.class) public class DebugScreenOverlayMixin { - /* - * Insert information about effective frame rate below misleading FPS counter. + /** + * Show the current power state and effective frame rate below the FPS counter, unless focused. + * + * As we only slow the client loop to a minimum of 15 TPS the vanilla frame rate counter is inaccurate and confusing. */ - @Inject(method = "getGameInformation", at = @At("RETURN")) - private void onGetGameInformation(CallbackInfoReturnable> callbackInfo) { + @ModifyReturnValue(method = "getGameInformation", at = @At("RETURN")) + private List getGameInformation(List result) { 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())); } + + return result; } } diff --git a/src/main/java/dynamic_fps/impl/mixin/SoundEngineMixin.java b/src/main/java/dynamic_fps/impl/mixin/SoundEngineMixin.java index 9f2cdfcc..091c373e 100644 --- a/src/main/java/dynamic_fps/impl/mixin/SoundEngineMixin.java +++ b/src/main/java/dynamic_fps/impl/mixin/SoundEngineMixin.java @@ -9,8 +9,9 @@ import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; +import com.llamalad7.mixinextras.injector.ModifyReturnValue; +import com.llamalad7.mixinextras.sugar.Local; import com.mojang.blaze3d.audio.Listener; import dynamic_fps.impl.DynamicFPSMod; @@ -102,16 +103,14 @@ private void play(SoundInstance instance, CallbackInfo callbackInfo) { /** * Applies the user's requested volume multiplier to any newly played sounds. */ - @Inject(method = "getVolume", at = @At("HEAD"), cancellable = true) - private void getVolume(@Nullable SoundSource source, CallbackInfoReturnable callbackInfo) { - float base = 1.0f; - + @ModifyReturnValue(method = "getVolume", at = @At("RETURN")) + private float getVolume(float original, @Local @Nullable SoundSource source) { // Note: The original doesn't consider the user's setting when the source is MASTER // In vanilla this doesn't matter because it's never called, but we use it when setting the gain - if (source != null) { - base = this.options.getSoundSourceVolume(source); + if (SoundSource.MASTER.equals(source)) { + original = this.options.getSoundSourceVolume(source); } - callbackInfo.setReturnValue(base * DynamicFPSMod.volumeMultiplier(source)); + return original * DynamicFPSMod.volumeMultiplier(source); } }