Skip to content

Commit

Permalink
Make SoundPlayedEvent work as intended
Browse files Browse the repository at this point in the history
  • Loading branch information
Deftu committed Dec 24, 2024
1 parent 688ac5e commit a4dc116
Showing 1 changed file with 8 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,30 +10,25 @@
import org.polyfrost.oneconfig.api.event.v1.EventManager;
import org.polyfrost.oneconfig.api.event.v1.events.SoundPlayedEvent;
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.ModifyVariable;

@Mixin(SoundManager.class)
public class SoundManagerMixin {

@Shadow private boolean loaded;

@ModifyVariable(
method = "playSound",
at = @At(
value = "INVOKE",
//#if MC >= 1.12.2
//#if MC == 1.12.2 && FABRIC
//$$ target = "Lnet/minecraft/client/sound/SoundInstance;method_12532(Lnet/minecraft/client/sound/SoundManager;)Lnet/minecraft/client/sound/SoundContainerImpl;",
//#else
//$$ target = "Lnet/minecraft/client/audio/ISound;createAccessor(Lnet/minecraft/client/audio/SoundHandler;)Lnet/minecraft/client/audio/SoundEventAccessor;",
//#endif
//#else
target = "Lnet/minecraft/client/audio/SoundHandler;getSound(Lnet/minecraft/util/ResourceLocation;)Lnet/minecraft/client/audio/SoundEventAccessorComposite;",
//#endif
shift = At.Shift.BEFORE
),
at = @At("HEAD"),
argsOnly = true
)
private ISound onPlaySoundCallback(ISound value) {
if (!this.loaded) {
return value;
}

//#if MC <= 1.8.9
SoundEventAccessorComposite accessor = ((SoundManagerAccessorMixin) this).getSndHandler().getSound(value.getSoundLocation());
SoundCategory category = (accessor == null ? null : accessor.getSoundCategory());
Expand Down

0 comments on commit a4dc116

Please sign in to comment.