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 f80ca42 commit 2004005
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 51 deletions.
8 changes: 0 additions & 8 deletions common/src/main/java/gg/meza/SoundsBeGone.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,8 @@
package gg.meza;

import gg.meza.analytics.Analytics;
import net.minecraft.client.option.KeyBinding;
import net.minecraft.client.util.InputUtil;
import org.lwjgl.glfw.GLFW;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

public class SoundsBeGone {

// This logger is used to write text to the console and the log file.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package gg.meza.client.mixin;

import gg.meza.SoundsBeGone;
import gg.meza.client.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());
}

}
}

This file was deleted.

18 changes: 8 additions & 10 deletions common/src/main/resources/soundsbegone.client.mixins.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
{
"required": true,
"package": "gg.meza.client.mixin",
"compatibilityLevel": "JAVA_17",
"minVersion": "0.8.4",
"client": [
"SoundInterceptorMixin"
],
"injectors": {
"defaultRequire": 1
}
"required": true,
"package": "gg.meza.client.mixin",
"compatibilityLevel": "JAVA_17",
"minVersion": "0.8.4",
"client": ["AbstractSoundInstanceMixin"],
"injectors": {
"defaultRequire": 1
}
}

0 comments on commit 2004005

Please sign in to comment.