|
5 | 5 |
|
6 | 6 | package meteordevelopment.meteorclient.mixin; |
7 | 7 |
|
| 8 | +import com.llamalad7.mixinextras.sugar.Local; |
8 | 9 | import meteordevelopment.meteorclient.MeteorClient; |
9 | 10 | import meteordevelopment.meteorclient.events.world.PlaySoundEvent; |
| 11 | +import meteordevelopment.meteorclient.systems.modules.Modules; |
| 12 | +import meteordevelopment.meteorclient.systems.modules.misc.SoundBlocker; |
10 | 13 | import net.minecraft.client.sound.SoundInstance; |
11 | 14 | import net.minecraft.client.sound.SoundSystem; |
| 15 | +import net.minecraft.client.sound.TickableSoundInstance; |
12 | 16 | import org.spongepowered.asm.mixin.Mixin; |
| 17 | +import org.spongepowered.asm.mixin.Shadow; |
13 | 18 | import org.spongepowered.asm.mixin.injection.At; |
14 | 19 | import org.spongepowered.asm.mixin.injection.Inject; |
15 | 20 | import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; |
16 | 21 |
|
17 | 22 | @Mixin(SoundSystem.class) |
18 | 23 | public abstract class SoundSystemMixin { |
| 24 | + @Shadow |
| 25 | + public abstract void stop(SoundInstance sound); |
| 26 | + |
19 | 27 | @Inject(method = "play(Lnet/minecraft/client/sound/SoundInstance;)V", at = @At("HEAD"), cancellable = true) |
20 | 28 | private void onPlay(SoundInstance soundInstance, CallbackInfo info) { |
21 | 29 | PlaySoundEvent event = MeteorClient.EVENT_BUS.post(PlaySoundEvent.get(soundInstance)); |
22 | 30 |
|
23 | 31 | if (event.isCancelled()) info.cancel(); |
24 | 32 | } |
| 33 | + |
| 34 | + @Inject(method = "tick()V", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/sound/TickableSoundInstance;tick()V", ordinal = 0)) |
| 35 | + private void onTick(CallbackInfo ci, @Local TickableSoundInstance tickableSoundInstance) { |
| 36 | + if (Modules.get().get(SoundBlocker.class).shouldBlock(tickableSoundInstance)) stop(tickableSoundInstance); |
| 37 | + } |
25 | 38 | } |
0 commit comments