From ded55a671f8f97bdcfe5c677ddc7ed4bd0bc5e7f Mon Sep 17 00:00:00 2001 From: Zoobooo <245741181+Zoobooo@users.noreply.github.com> Date: Wed, 4 Nov 2026 23:02:25 +0100 Subject: [PATCH 1/3] fix(sound): stop the untracked ambience copy before restarting it On 1.8.9 sounds start asynchronously, so a stream that was just started can still report inactive for up to 20 ticks. When the ambience watch loop hit that window it started a new copy and dropped the reference to the old one, which kept playing. stopAmbience only fades the tracked copy, so turning UI Ambience off or closing the menu left the music playing (forever for the looping Polyglass pad). --- .../polyfrost/oneconfig/internal/ui/sound/McUiSoundService.kt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/minecraft/src/main/kotlin/org/polyfrost/oneconfig/internal/ui/sound/McUiSoundService.kt b/minecraft/src/main/kotlin/org/polyfrost/oneconfig/internal/ui/sound/McUiSoundService.kt index e0e1660f4..665895e84 100644 --- a/minecraft/src/main/kotlin/org/polyfrost/oneconfig/internal/ui/sound/McUiSoundService.kt +++ b/minecraft/src/main/kotlin/org/polyfrost/oneconfig/internal/ui/sound/McUiSoundService.kt @@ -198,6 +198,10 @@ class McUiSoundService : UiSoundService { val current = ambience ?: return@execute if (current.isStopped || current.isFadingOut || current !== ambience) return@execute if (!mc.soundManager.isActive(current)) { + // 1.8.9 starts sounds asynchronously, so a stream that was just started can still + // report inactive. Stop it before replacing it, otherwise it keeps playing untracked + // and stopAmbience can no longer fade it out + mc.soundManager.stop(current) playAmbienceInstance(current.theme, current.targetVolume, fadeIn = !mc.isPaused) } else if (current.isStalledFadeIn) { mc.soundManager.stop(current) From 83d2dfbae86bf4715db5a0ddefc8f820c15fd8c7 Mon Sep 17 00:00:00 2001 From: Julian Chang Date: Tue, 10 Nov 2026 00:52:34 -0500 Subject: [PATCH 2/3] fix(sound): don't replace ambience stream while it is starting --- .../internal/ui/sound/McUiSoundService.kt | 23 +++++++++++++++---- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/minecraft/src/main/kotlin/org/polyfrost/oneconfig/internal/ui/sound/McUiSoundService.kt b/minecraft/src/main/kotlin/org/polyfrost/oneconfig/internal/ui/sound/McUiSoundService.kt index 665895e84..1b9f0bc9f 100644 --- a/minecraft/src/main/kotlin/org/polyfrost/oneconfig/internal/ui/sound/McUiSoundService.kt +++ b/minecraft/src/main/kotlin/org/polyfrost/oneconfig/internal/ui/sound/McUiSoundService.kt @@ -95,7 +95,7 @@ class McUiSoundService : UiSoundService { override fun startAmbience(theme: UiSoundTheme, volume: Float) { try { val current = ambience - if (current != null && !current.isStopped && current.theme == theme && mc.soundManager.isActive(current)) { + if (current != null && !current.isStopped && current.theme == theme && isAlive(current)) { current.updateTargetVolume(ambienceVolumeFor(theme, volume)) current.cancelFadeOut() UiSoundDucking.setActive(true) @@ -197,10 +197,7 @@ class McUiSoundService : UiSoundService { try { val current = ambience ?: return@execute if (current.isStopped || current.isFadingOut || current !== ambience) return@execute - if (!mc.soundManager.isActive(current)) { - // 1.8.9 starts sounds asynchronously, so a stream that was just started can still - // report inactive. Stop it before replacing it, otherwise it keeps playing untracked - // and stopAmbience can no longer fade it out + if (!isAlive(current)) { mc.soundManager.stop(current) playAmbienceInstance(current.theme, current.targetVolume, fadeIn = !mc.isPaused) } else if (current.isStalledFadeIn) { @@ -221,6 +218,16 @@ class McUiSoundService : UiSoundService { thread.start() } + // 1.8.9 starts streams on Paulscode's threads, so a fresh stream reports inactive until its preload ends. + // Stopping it then is lost: preload finishes afterwards and starts the channel untracked. + private fun isAlive(instance: FadingLoopSoundInstance): Boolean { + if (mc.soundManager.isActive(instance)) { + instance.seenActive = true + return true + } + return !instance.seenActive && System.currentTimeMillis() - instance.startedAt < START_GRACE_MS + } + private val musicRefreshUntil = AtomicLong(0) @Volatile @@ -284,6 +291,11 @@ class McUiSoundService : UiSoundService { @Volatile private var fadeOutStep = 0f + val startedAt = System.currentTimeMillis() + + @Volatile + var seenActive = false + val isFadingOut: Boolean get() = fadingOut @@ -368,5 +380,6 @@ class McUiSoundService : UiSoundService { const val FADE_IN_TICKS = 30f const val FADE_IN_FLOOR = 0.0001f const val STALL_NANOS = 400_000_000L + const val START_GRACE_MS = 5000L } } From d85f56902781c5b4fefeb7bbca65ed71f8f9abc0 Mon Sep 17 00:00:00 2001 From: Julian Chang Date: Tue, 10 Nov 2026 01:02:27 -0500 Subject: [PATCH 3/3] fix(sound): restart ambience started at zero volume --- .../oneconfig/internal/ui/sound/McUiSoundService.kt | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/minecraft/src/main/kotlin/org/polyfrost/oneconfig/internal/ui/sound/McUiSoundService.kt b/minecraft/src/main/kotlin/org/polyfrost/oneconfig/internal/ui/sound/McUiSoundService.kt index 1b9f0bc9f..4d7502de9 100644 --- a/minecraft/src/main/kotlin/org/polyfrost/oneconfig/internal/ui/sound/McUiSoundService.kt +++ b/minecraft/src/main/kotlin/org/polyfrost/oneconfig/internal/ui/sound/McUiSoundService.kt @@ -220,12 +220,14 @@ class McUiSoundService : UiSoundService { // 1.8.9 starts streams on Paulscode's threads, so a fresh stream reports inactive until its preload ends. // Stopping it then is lost: preload finishes afterwards and starts the channel untracked. + // A zero-volume play is skipped by the engine, so it never starts and gets no grace. private fun isAlive(instance: FadingLoopSoundInstance): Boolean { if (mc.soundManager.isActive(instance)) { instance.seenActive = true return true } - return !instance.seenActive && System.currentTimeMillis() - instance.startedAt < START_GRACE_MS + return !instance.startedSilent && !instance.seenActive && + System.currentTimeMillis() - instance.startedAt < START_GRACE_MS } private val musicRefreshUntil = AtomicLong(0) @@ -293,6 +295,8 @@ class McUiSoundService : UiSoundService { val startedAt = System.currentTimeMillis() + val startedSilent = targetVolume <= 0f + @Volatile var seenActive = false