Skip to content

Commit

Permalink
fix: minecart, guardian and other sounds are now silenced properly
Browse files Browse the repository at this point in the history
  • Loading branch information
meza committed Mar 2, 2024
1 parent 757966f commit 1de30df
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 44 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package gg.meza.mixin.client;

import gg.meza.SoundsBeGone;
import gg.meza.SoundsBeGoneClient;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.sound.AbstractSoundInstance;
import net.minecraft.text.Text;
import net.minecraft.util.Identifier;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

@Mixin(AbstractSoundInstance.class)
public class AbstractSoundInstanceMixin {

@Final
@Shadow
protected Identifier id;

@Inject(
method = "getVolume()F",
at = @At("HEAD"),
cancellable = true)
private void getVolume(CallbackInfoReturnable<Float> cir) {

if (SoundsBeGoneClient.config.isSoundDisabled(id.toString())) {
SoundsBeGone.LOGGER.debug("Disabling the sound: {}", id);
SoundsBeGoneClient.analytics.blockedSound(id.toString());
cir.setReturnValue(0.0F);
cir.cancel();
}

if(MinecraftClient.getInstance().world != null) {
SoundsBeGone.LOGGER.debug("Intercepting the sound: {}", Text.translatable(id.toTranslationKey()));
SoundsBeGoneClient.SoundMap.put(id.toString(), new java.util.Date());
}

}
}
35 changes: 0 additions & 35 deletions src/client/java/gg/meza/mixin/client/SoundInterceptorMixin.java

This file was deleted.

16 changes: 7 additions & 9 deletions src/client/resources/soundsbegone.client.mixins.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
{
"required": true,
"package": "gg.meza.mixin.client",
"compatibilityLevel": "JAVA_17",
"client": [
"SoundInterceptorMixin"
],
"injectors": {
"defaultRequire": 1
}
"required": true,
"package": "gg.meza.mixin.client",
"compatibilityLevel": "JAVA_17",
"client": ["AbstractSoundInstanceMixin"],
"injectors": {
"defaultRequire": 1
}
}

0 comments on commit 1de30df

Please sign in to comment.