From 16db344e23c97b946f894341765307ecb482f12a Mon Sep 17 00:00:00 2001 From: LostLuma Date: Sat, 16 Dec 2023 12:51:45 +0100 Subject: [PATCH] Simplify SoundEngine access --- .../java/dynamic_fps/impl/DynamicFPSMod.java | 2 +- .../impl/mixin/SoundEngineMixin.java | 4 ++-- .../impl/mixin/SoundManagerMixin.java | 21 ------------------- ...SoundManager.java => DuckSoundEngine.java} | 2 +- src/main/resources/dynamic_fps.accesswidener | 1 + src/main/resources/dynamic_fps.mixins.json | 1 - src/main/resources/fabric.mod.json | 3 +-- 7 files changed, 6 insertions(+), 28 deletions(-) delete mode 100644 src/main/java/dynamic_fps/impl/mixin/SoundManagerMixin.java rename src/main/java/dynamic_fps/impl/util/duck/{DuckSoundManager.java => DuckSoundEngine.java} (87%) diff --git a/src/main/java/dynamic_fps/impl/DynamicFPSMod.java b/src/main/java/dynamic_fps/impl/DynamicFPSMod.java index 899e7f80..f0469799 100644 --- a/src/main/java/dynamic_fps/impl/DynamicFPSMod.java +++ b/src/main/java/dynamic_fps/impl/DynamicFPSMod.java @@ -196,7 +196,7 @@ public static void handleStateChange(PowerState previous, PowerState current) { for (var source : SoundSource.values()) { if (before.volumeMultiplier(source) != config.volumeMultiplier(source)) { - minecraft.getSoundManager().dynamic_fps$updateVolume(source); + minecraft.getSoundManager().soundEngine.dynamic_fps$updateVolume(source); } } diff --git a/src/main/java/dynamic_fps/impl/mixin/SoundEngineMixin.java b/src/main/java/dynamic_fps/impl/mixin/SoundEngineMixin.java index ce1e3880..6eb53dd7 100644 --- a/src/main/java/dynamic_fps/impl/mixin/SoundEngineMixin.java +++ b/src/main/java/dynamic_fps/impl/mixin/SoundEngineMixin.java @@ -14,14 +14,14 @@ import com.mojang.blaze3d.audio.Listener; import dynamic_fps.impl.DynamicFPSMod; -import dynamic_fps.impl.util.duck.DuckSoundManager; +import dynamic_fps.impl.util.duck.DuckSoundEngine; import net.minecraft.client.resources.sounds.SoundInstance; import net.minecraft.client.sounds.ChannelAccess; import net.minecraft.client.sounds.SoundEngine; import net.minecraft.sounds.SoundSource; @Mixin(SoundEngine.class) -public class SoundEngineMixin implements DuckSoundManager { +public class SoundEngineMixin implements DuckSoundEngine { @Shadow private boolean loaded; diff --git a/src/main/java/dynamic_fps/impl/mixin/SoundManagerMixin.java b/src/main/java/dynamic_fps/impl/mixin/SoundManagerMixin.java deleted file mode 100644 index f087c307..00000000 --- a/src/main/java/dynamic_fps/impl/mixin/SoundManagerMixin.java +++ /dev/null @@ -1,21 +0,0 @@ -package dynamic_fps.impl.mixin; - -import org.spongepowered.asm.mixin.Final; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; - -import dynamic_fps.impl.util.duck.DuckSoundManager; -import net.minecraft.client.sounds.SoundEngine; -import net.minecraft.client.sounds.SoundManager; -import net.minecraft.sounds.SoundSource; - -@Mixin(SoundManager.class) -public class SoundManagerMixin implements DuckSoundManager { - @Shadow - @Final - private SoundEngine soundEngine; - - public void dynamic_fps$updateVolume(SoundSource source) { - this.soundEngine.dynamic_fps$updateVolume(source); - } -} diff --git a/src/main/java/dynamic_fps/impl/util/duck/DuckSoundManager.java b/src/main/java/dynamic_fps/impl/util/duck/DuckSoundEngine.java similarity index 87% rename from src/main/java/dynamic_fps/impl/util/duck/DuckSoundManager.java rename to src/main/java/dynamic_fps/impl/util/duck/DuckSoundEngine.java index 41c8f00a..3b305d41 100644 --- a/src/main/java/dynamic_fps/impl/util/duck/DuckSoundManager.java +++ b/src/main/java/dynamic_fps/impl/util/duck/DuckSoundEngine.java @@ -2,7 +2,7 @@ import net.minecraft.sounds.SoundSource; -public interface DuckSoundManager { +public interface DuckSoundEngine { public default void dynamic_fps$updateVolume(SoundSource source) { throw new RuntimeException("No implementation for dynamic_fps$updateVolume was found."); } diff --git a/src/main/resources/dynamic_fps.accesswidener b/src/main/resources/dynamic_fps.accesswidener index aa31532c..0298cddf 100644 --- a/src/main/resources/dynamic_fps.accesswidener +++ b/src/main/resources/dynamic_fps.accesswidener @@ -1,3 +1,4 @@ accessWidener v2 named accessible field com/mojang/blaze3d/platform/Window window J +accessible field net/minecraft/client/sounds/SoundManager soundEngine Lnet/minecraft/client/sounds/SoundEngine; diff --git a/src/main/resources/dynamic_fps.mixins.json b/src/main/resources/dynamic_fps.mixins.json index 6b661ccc..da9d1887 100644 --- a/src/main/resources/dynamic_fps.mixins.json +++ b/src/main/resources/dynamic_fps.mixins.json @@ -11,7 +11,6 @@ "MinecraftMixin", "ScreenMixin", "SoundEngineMixin", - "SoundManagerMixin", "StatsScreenMixin", "ToastComponentMixin", "WindowMixin", diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index 58c9eca4..1021b674 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -46,8 +46,7 @@ "loom:injected_interfaces": { "net/minecraft/class_437": ["dynamic_fps/impl/util/duck/DuckScreen"], "net/minecraft/class_425": ["dynamic_fps/impl/util/duck/DuckSplashOverlay"], - "net/minecraft/class_1140": ["dynamic_fps/impl/util/duck/DuckSoundManager"], - "net/minecraft/class_1144": ["dynamic_fps/impl/util/duck/DuckSoundManager"] + "net/minecraft/class_1140": ["dynamic_fps/impl/util/duck/DuckSoundEngine"] }, "dynamic_fps": { "optimized_screens": {