generated from kappa-maintainer/1.12.2-FG6-Template
-
Notifications
You must be signed in to change notification settings - Fork 9
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
038c986
commit 5e3c7ce
Showing
6 changed files
with
82 additions
and
0 deletions.
There are no files selected for viewing
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
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
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
38 changes: 38 additions & 0 deletions
38
src/main/java/com/cleanroommc/fugue/helper/SoundThread.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,38 @@ | ||
package com.cleanroommc.fugue.helper; | ||
|
||
import net.minecraft.util.math.BlockPos; | ||
import tech.feldman.betterrecords.api.sound.Sound; | ||
import tech.feldman.betterrecords.client.sound.SoundPlayer; | ||
|
||
import java.util.List; | ||
import java.util.concurrent.atomic.AtomicBoolean; | ||
|
||
public class SoundThread extends Thread { | ||
private final AtomicBoolean interrupted; | ||
private final List<Sound> sounds; | ||
private final BlockPos pos; | ||
private final int dim; | ||
private final boolean repeat; | ||
|
||
public SoundThread(AtomicBoolean interrupted, List<Sound> sounds, BlockPos pos, int dim, boolean repeat) { | ||
super("Better Records Sound Thread"); | ||
this.interrupted = interrupted; | ||
this.sounds = sounds; | ||
this.pos = pos; | ||
this.dim = dim; | ||
this.repeat = repeat; | ||
} | ||
|
||
@Override | ||
public void interrupt() { | ||
interrupted.set(true); | ||
} | ||
|
||
@Override | ||
public void run() { | ||
while (!interrupted.get()) { | ||
sounds.forEach(sound -> SoundPlayer.INSTANCE.playSound(pos, dim, sound)); | ||
if (!repeat) return; | ||
} | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
src/main/java/com/cleanroommc/fugue/mixin/betterrecords/SoundManagerMixin.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,38 @@ | ||
package com.cleanroommc.fugue.mixin.betterrecords; | ||
|
||
import com.cleanroommc.fugue.helper.SoundThread; | ||
import com.llamalad7.mixinextras.sugar.Local; | ||
import com.llamalad7.mixinextras.sugar.ref.LocalRef; | ||
import net.minecraft.util.math.BlockPos; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
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.Redirect; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; | ||
import tech.feldman.betterrecords.api.sound.Sound; | ||
import tech.feldman.betterrecords.client.sound.SoundManager; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.concurrent.ConcurrentHashMap; | ||
import java.util.concurrent.atomic.AtomicBoolean; | ||
|
||
@Mixin(value = SoundManager.class, remap = false) | ||
public class SoundManagerMixin { | ||
@Unique | ||
private static final Map<Thread, AtomicBoolean> threads = new ConcurrentHashMap<>(); | ||
@Redirect(method = "stopQueueAt", at = @At(value = "INVOKE", target = "Ljava/lang/Thread;stop()V")) | ||
private void stopQueueAt(Thread thread) { | ||
threads.get(thread).set(Boolean.FALSE); | ||
thread.interrupt(); | ||
} | ||
|
||
@Inject(method = "queueSongsAt", at = @At(value = "INVOKE", target = "Ljava/util/Map;put(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;")) | ||
private void hackThread(BlockPos pos, int dimension, List<Sound> sounds, boolean shuffle, boolean repeat, CallbackInfo ci, @Local LocalRef<Thread> job) { | ||
AtomicBoolean interrupted = new AtomicBoolean(false); | ||
job.set(new SoundThread(interrupted, sounds, pos, dimension, repeat)); | ||
threads.put(Thread.currentThread(), interrupted); | ||
} | ||
|
||
} |
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