Skip to content

Commit 171a3cb

Browse files
committed
fixed EVENT_VOLUME and EVENT_PITCH client values
i might have trauma after dealing with mixins bruh
1 parent f5add03 commit 171a3cb

File tree

2 files changed

+28
-10
lines changed

2 files changed

+28
-10
lines changed

src/main/java/io/github/techstreet/dfscript/event/RecieveSoundEvent.java

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,24 @@
1111
public class RecieveSoundEvent implements CancellableEvent {
1212
private boolean cancelled = false;
1313

14-
private final SoundInstance sound;
14+
private final Identifier soundId;
15+
private final float volume, pitch;
1516

16-
public RecieveSoundEvent(SoundInstance sound) {
17-
this.sound = sound;
17+
public RecieveSoundEvent(Identifier soundId, float volume, float pitch) {
18+
this.soundId = soundId;
19+
this.volume = volume;
20+
this.pitch = pitch;
1821
}
1922

2023
public Identifier getSoundId() {
21-
return sound.getId();
24+
return soundId;
2225
}
2326
public float getVolume() {
24-
return sound.getVolume();
27+
return volume;
2528
}
2629

2730
public float getPitch() {
28-
return sound.getPitch();
31+
return pitch;
2932
}
3033

3134
@Override

src/main/java/io/github/techstreet/dfscript/mixin/sound/MSoundSystem.java

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,34 @@
33
import io.github.techstreet.dfscript.event.RecieveSoundEvent;
44
import io.github.techstreet.dfscript.event.system.EventManager;
55
import io.github.techstreet.dfscript.util.chat.ChatUtil;
6+
import net.minecraft.client.sound.Sound;
67
import net.minecraft.client.sound.SoundInstance;
78
import net.minecraft.client.sound.SoundSystem;
9+
import net.minecraft.client.sound.WeightedSoundSet;
810
import net.minecraft.network.packet.s2c.play.PlaySoundIdS2CPacket;
11+
import net.minecraft.sound.SoundCategory;
12+
import net.minecraft.util.Identifier;
13+
import net.minecraft.util.math.MathHelper;
914
import org.spongepowered.asm.mixin.Mixin;
15+
import org.spongepowered.asm.mixin.Shadow;
16+
import org.spongepowered.asm.mixin.gen.Invoker;
1017
import org.spongepowered.asm.mixin.injection.At;
1118
import org.spongepowered.asm.mixin.injection.Inject;
1219
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
20+
import org.spongepowered.asm.mixin.injection.callback.LocalCapture;
1321

1422
@Mixin(SoundSystem.class)
15-
public class MSoundSystem {
16-
@Inject(method = "play", at = @At("HEAD"), cancellable = true)
17-
public void play(SoundInstance sound, CallbackInfo ci) {
18-
RecieveSoundEvent event = new RecieveSoundEvent(sound);
23+
public abstract class MSoundSystem {
24+
25+
@Shadow
26+
public abstract float getAdjustedVolume(SoundInstance sound);
27+
@Shadow
28+
public abstract float getAdjustedPitch(SoundInstance sound);
29+
@Shadow
30+
public abstract float getSoundVolume(SoundCategory category);
31+
@Inject(method = "play", at = @At(value="INVOKE_ASSIGN", target="Lnet/minecraft/client/sound/SoundSystem;getAdjustedPitch(Lnet/minecraft/client/sound/SoundInstance;)F"), cancellable = true, locals = LocalCapture.CAPTURE_FAILHARD)
32+
public void play(SoundInstance sound, CallbackInfo ci, WeightedSoundSet weightedSoundSet, Identifier identifier, Sound sound2, float f, float g, SoundCategory soundCategory, float h, float i) {
33+
RecieveSoundEvent event = new RecieveSoundEvent(sound.getId(), h, i);
1934
EventManager.getInstance().dispatch(event);
2035

2136
if (event.isCancelled()) {

0 commit comments

Comments
 (0)