diff options
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/utils')
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/utils/DelayedRun.kt | 12 | ||||
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/utils/SoundUtils.kt | 6 |
2 files changed, 15 insertions, 3 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/DelayedRun.kt b/src/main/java/at/hannibal2/skyhanni/utils/DelayedRun.kt index eb83bce3a..4642124b7 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/DelayedRun.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/DelayedRun.kt @@ -2,7 +2,9 @@ package at.hannibal2.skyhanni.utils import at.hannibal2.skyhanni.test.command.ErrorManager import at.hannibal2.skyhanni.utils.CollectionUtils.drainTo +import net.minecraft.client.Minecraft import java.util.concurrent.ConcurrentLinkedQueue +import java.util.concurrent.Executor import kotlin.time.Duration object DelayedRun { @@ -35,4 +37,14 @@ object DelayedRun { } futureTasks.drainTo(tasks) } + + @JvmField + val onThread = Executor { + val mc = Minecraft.getMinecraft() + if (mc.isCallingFromMinecraftThread) { + it.run() + } else { + Minecraft.getMinecraft().addScheduledTask(it) + } + } } diff --git a/src/main/java/at/hannibal2/skyhanni/utils/SoundUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/SoundUtils.kt index 79e320949..f001cfadb 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/SoundUtils.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/SoundUtils.kt @@ -19,8 +19,8 @@ object SoundUtils { val centuryActiveTimerAlert by lazy { createSound("skyhanni:centurytimer.active", 1f) } fun ISound.playSound() { - Minecraft.getMinecraft().addScheduledTask { - if (Minecraft.getMinecraft().soundHandler.isSoundPlaying(this)) return@addScheduledTask + DelayedRun.onThread.execute { + if (Minecraft.getMinecraft().soundHandler.isSoundPlaying(this)) return@execute val gameSettings = Minecraft.getMinecraft().gameSettings val oldLevel = gameSettings.getSoundLevel(SoundCategory.PLAYERS) if (!SkyHanniMod.feature.misc.maintainGameVolume) { @@ -33,7 +33,7 @@ object SoundUtils { e.message?.let { if (it.startsWith("value already present:")) { println("SkyHanni Sound error: $it") - return@addScheduledTask + return@execute } } } |