-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ef65215
commit 17bdb1d
Showing
2 changed files
with
45 additions
and
0 deletions.
There are no files selected for viewing
44 changes: 44 additions & 0 deletions
44
src/main/java/com/mmodding/mmodding_lib/mixin/injectors/client/SoundSystemMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package com.mmodding.mmodding_lib.mixin.injectors.client; | ||
|
||
import com.mmodding.mmodding_lib.library.sounds.client.SoundQueue; | ||
import net.minecraft.client.sound.SoundInstance; | ||
import net.minecraft.client.sound.SoundSystem; | ||
import net.minecraft.client.sound.TickableSoundInstance; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Shadow; | ||
import org.spongepowered.asm.mixin.Unique; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
@Mixin(SoundSystem.class) | ||
public abstract class SoundSystemMixin { | ||
|
||
@Unique | ||
private final List<TickableSoundInstance> soundQueues = new ArrayList<>(); | ||
|
||
@Shadow | ||
public abstract boolean isPlaying(SoundInstance sound); | ||
|
||
@Inject(method = "play(Lnet/minecraft/client/sound/SoundInstance;)V", at = @At("HEAD"), cancellable = true) | ||
private void injectSoundQueueToTickingSounds(SoundInstance sound, CallbackInfo ci) { | ||
if (sound instanceof SoundQueue queue) { | ||
this.soundQueues.add(queue); | ||
ci.cancel(); | ||
} | ||
} | ||
|
||
@Inject(method = "tick()V", at = @At("HEAD")) | ||
private void tickSoundQueues(CallbackInfo ci) { | ||
for (TickableSoundInstance queue : this.soundQueues) { | ||
queue.tick(); | ||
if (queue.isDone()) { | ||
this.soundQueues.remove(queue); | ||
} | ||
} | ||
this.soundQueues.forEach(TickableSoundInstance::tick); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters