|
| 1 | +package dynamic_fps.impl.mixin.debug; |
| 2 | + |
| 3 | +import dynamic_fps.impl.util.Logging; |
| 4 | +import net.minecraft.client.Minecraft; |
| 5 | +import net.minecraft.client.sounds.SoundEngine; |
| 6 | +import org.spongepowered.asm.mixin.Mixin; |
| 7 | +import org.spongepowered.asm.mixin.Unique; |
| 8 | +import org.spongepowered.asm.mixin.injection.At; |
| 9 | +import org.spongepowered.asm.mixin.injection.Inject; |
| 10 | +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; |
| 11 | +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; |
| 12 | + |
| 13 | +@Mixin(SoundEngine.class) |
| 14 | +public class SoundEngineMixin { |
| 15 | + @Inject(method = "updateCategoryVolume", at = @At("HEAD")) |
| 16 | + private void updateCategoryVolume(CallbackInfo callbackInfo) { |
| 17 | + dynamic_fps$logOffThreadUsage("updateCategoryVolume"); |
| 18 | + } |
| 19 | + |
| 20 | + @Inject(method = "stop", at = @At("HEAD")) |
| 21 | + private void stop(CallbackInfo callbackInfo) { |
| 22 | + dynamic_fps$logOffThreadUsage("stop"); |
| 23 | + } |
| 24 | + |
| 25 | + @Inject(method = "stopAll", at = @At("HEAD")) |
| 26 | + private void stopAll(CallbackInfo callbackInfo) { |
| 27 | + dynamic_fps$logOffThreadUsage("stopAll"); |
| 28 | + } |
| 29 | + |
| 30 | + @Inject(method = "tickNonPaused", at = @At("HEAD")) |
| 31 | + private void tickNonPaused(CallbackInfo callbackInfo) { |
| 32 | + dynamic_fps$logOffThreadUsage("tickNonPaused"); |
| 33 | + } |
| 34 | + |
| 35 | + @Inject(method = "isActive", at = @At("HEAD")) |
| 36 | + private void isActive(CallbackInfoReturnable<Boolean> cir) { |
| 37 | + dynamic_fps$logOffThreadUsage("isActive"); |
| 38 | + } |
| 39 | + |
| 40 | + @Inject(method = "play", at = @At("HEAD")) |
| 41 | + private void play(CallbackInfo callbackInfo) { |
| 42 | + dynamic_fps$logOffThreadUsage("play"); |
| 43 | + } |
| 44 | + |
| 45 | + @Inject(method = "playDelayed", at = @At("HEAD")) |
| 46 | + private void playDelayed(CallbackInfo callbackInfo) { |
| 47 | + dynamic_fps$logOffThreadUsage("playDelayed"); |
| 48 | + } |
| 49 | + |
| 50 | + @Unique |
| 51 | + private void dynamic_fps$logOffThreadUsage(String method) { |
| 52 | + if (!Minecraft.getInstance().isSameThread()) { |
| 53 | + Logging.getLogger().warn("Potentially dangerous call to SoundEngine.{} from non-main thread!", method, new Throwable()); |
| 54 | + } |
| 55 | + } |
| 56 | +} |
0 commit comments