From e7277b89d5cfc6dac9dfb61c17af66a87c1c9960 Mon Sep 17 00:00:00 2001 From: Phoenix-Starlight <64714532+Phoenix-Starlight@users.noreply.github.com> Date: Thu, 12 Oct 2023 19:19:46 -0700 Subject: [PATCH] Fix dynamic_sounds breaking on 1.16 (#259) An issue in Guava (https://github.com/google/guava/issues/3081) causes the removal listener to fire even when entries haven't actually been removed. We filter them to get around this. --- .../mixin/perf/dynamic_sounds/SoundBufferLibraryMixin.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/common/src/main/java/org/embeddedt/modernfix/common/mixin/perf/dynamic_sounds/SoundBufferLibraryMixin.java b/common/src/main/java/org/embeddedt/modernfix/common/mixin/perf/dynamic_sounds/SoundBufferLibraryMixin.java index 607657d5..921da3ef 100644 --- a/common/src/main/java/org/embeddedt/modernfix/common/mixin/perf/dynamic_sounds/SoundBufferLibraryMixin.java +++ b/common/src/main/java/org/embeddedt/modernfix/common/mixin/perf/dynamic_sounds/SoundBufferLibraryMixin.java @@ -1,6 +1,7 @@ package org.embeddedt.modernfix.common.mixin.perf.dynamic_sounds; import com.google.common.cache.CacheBuilder; +import com.google.common.cache.RemovalCause; import com.google.common.cache.RemovalNotification; import com.mojang.blaze3d.audio.SoundBuffer; import net.minecraft.client.sounds.SoundBufferLibrary; @@ -26,12 +27,15 @@ public abstract class SoundBufferLibraryMixin { @Shadow @Final @Mutable private Map> cache = CacheBuilder.newBuilder() .expireAfterAccess(DynamicSoundHelpers.MAX_SOUND_LIFETIME_SECS, TimeUnit.SECONDS) + .concurrencyLevel(1) // Excessive use of type hinting due to it assuming Object as the broadest correct type .>removalListener(this::onSoundRemoval) .build() .asMap(); private > void onSoundRemoval(RemovalNotification notification) { + if(notification.getCause() == RemovalCause.REPLACED && notification.getValue() == cache.get(notification.getKey())) + return; notification.getValue().thenAccept(SoundBuffer::discardAlBuffer); if(debugDynamicSoundLoading) { K k = notification.getKey();