Skip to content

Commit

Permalink
Test better record patch
Browse files Browse the repository at this point in the history
  • Loading branch information
kappa-maintainer committed Oct 1, 2024
1 parent 038c986 commit 5e3c7ce
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 0 deletions.
2 changes: 2 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,8 @@ dependencies {
//Carry on
compileOnly(fg.deobf("curse.maven:carry-274259:4507139"))

//Better Records
compileOnly(fg.deobf("curse.maven:br-222722:2930159"))

implementation("com.cleanroommc:groovyscript:1.1.1") {
transitive = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ public boolean shouldApplyMixin(String targetClassName, String mixinClassName) {
case "infinitylib" -> Loader.isModLoaded("infinitylib") && FugueConfig.modPatchConfig.enableInfLib;
case "carryon" -> Loader.isModLoaded("carryon") && FugueConfig.modPatchConfig.enableCarryon;
case "litematica" -> Loader.isModLoaded("litematica") && FugueConfig.modPatchConfig.enableLitematica;
case "betterrecords" -> Loader.isModLoaded("betterrecords") && FugueConfig.modPatchConfig.enableBetterRecords;
default -> true;
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,4 +124,6 @@ public class ModPatchConfig {
public boolean enableCarryon = true;
@Config.Name("Enable Litematica Patch")
public boolean enableLitematica = true;
@Config.Name("Enable Better Records Patch")
public boolean enableBetterRecords = true;
}
38 changes: 38 additions & 0 deletions src/main/java/com/cleanroommc/fugue/helper/SoundThread.java
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;
}
}
}
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);
}

}
1 change: 1 addition & 0 deletions src/main/resources/fugue.mixin.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"armourers_workshop.GlobalTaskMixin",
"armourers_workshop.SkinTextureMixin",
"astralsorcery.PerkAttributeTypeMixin",
"betterrecords.SoundManagerMixin",
"carryon.ItemTileMixin",
"charset.ColorspacesMixin",
"codechickenlib.ReflectionManagerMixin",
Expand Down

0 comments on commit 5e3c7ce

Please sign in to comment.