Skip to content

Commit cf3a90b

Browse files
committed
Fix SoundBlocker not blocking preexisting tickable sounds
1 parent bb2337f commit cf3a90b

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

src/main/java/meteordevelopment/meteorclient/mixin/SoundSystemMixin.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,34 @@
55

66
package meteordevelopment.meteorclient.mixin;
77

8+
import com.llamalad7.mixinextras.sugar.Local;
89
import meteordevelopment.meteorclient.MeteorClient;
910
import meteordevelopment.meteorclient.events.world.PlaySoundEvent;
11+
import meteordevelopment.meteorclient.systems.modules.Modules;
12+
import meteordevelopment.meteorclient.systems.modules.misc.SoundBlocker;
1013
import net.minecraft.client.sound.SoundInstance;
1114
import net.minecraft.client.sound.SoundSystem;
15+
import net.minecraft.client.sound.TickableSoundInstance;
1216
import org.spongepowered.asm.mixin.Mixin;
17+
import org.spongepowered.asm.mixin.Shadow;
1318
import org.spongepowered.asm.mixin.injection.At;
1419
import org.spongepowered.asm.mixin.injection.Inject;
1520
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
1621

1722
@Mixin(SoundSystem.class)
1823
public abstract class SoundSystemMixin {
24+
@Shadow
25+
public abstract void stop(SoundInstance sound);
26+
1927
@Inject(method = "play(Lnet/minecraft/client/sound/SoundInstance;)V", at = @At("HEAD"), cancellable = true)
2028
private void onPlay(SoundInstance soundInstance, CallbackInfo info) {
2129
PlaySoundEvent event = MeteorClient.EVENT_BUS.post(PlaySoundEvent.get(soundInstance));
2230

2331
if (event.isCancelled()) info.cancel();
2432
}
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+
}
2538
}

src/main/java/meteordevelopment/meteorclient/systems/modules/misc/SoundBlocker.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
import meteordevelopment.meteorclient.systems.modules.Categories;
1313
import meteordevelopment.meteorclient.systems.modules.Module;
1414
import meteordevelopment.orbit.EventHandler;
15+
import net.minecraft.client.sound.SoundInstance;
16+
import net.minecraft.registry.Registries;
1517
import net.minecraft.sound.SoundEvent;
1618

1719
import java.util.List;
@@ -38,4 +40,8 @@ private void onPlaySound(PlaySoundEvent event) {
3840
}
3941
}
4042
}
43+
44+
public boolean shouldBlock(SoundInstance soundInstance) {
45+
return isActive() && sounds.get().contains(Setting.parseId(Registries.SOUND_EVENT, soundInstance.getId().getPath()));
46+
}
4147
}

0 commit comments

Comments
 (0)