diff --git a/fabric-textures-v0/build.gradle b/fabric-textures-v0/build.gradle index 01abe8dd4..7a8e44df3 100644 --- a/fabric-textures-v0/build.gradle +++ b/fabric-textures-v0/build.gradle @@ -1,5 +1,5 @@ archivesBaseName = "fabric-textures-v0" -version = getSubprojectVersion(project, "0.1.2") +version = getSubprojectVersion(project, "0.1.3") dependencies { compile project(path: ':fabric-api-base', configuration: 'dev') diff --git a/fabric-textures-v0/src/main/java/net/fabricmc/fabric/impl/client/texture/SpriteRegistryCallbackHolder.java b/fabric-textures-v0/src/main/java/net/fabricmc/fabric/impl/client/texture/SpriteRegistryCallbackHolder.java index 7feafa6e4..5662938d0 100644 --- a/fabric-textures-v0/src/main/java/net/fabricmc/fabric/impl/client/texture/SpriteRegistryCallbackHolder.java +++ b/fabric-textures-v0/src/main/java/net/fabricmc/fabric/impl/client/texture/SpriteRegistryCallbackHolder.java @@ -23,17 +23,34 @@ import net.minecraft.util.Identifier; import java.util.HashMap; import java.util.Map; +import java.util.concurrent.locks.Lock; +import java.util.concurrent.locks.ReadWriteLock; +import java.util.concurrent.locks.ReentrantReadWriteLock; public final class SpriteRegistryCallbackHolder { public static final Event EVENT_GLOBAL = createEvent(); private static final Map> eventMap = new HashMap<>(); + private static final ReadWriteLock eventMapLock = new ReentrantReadWriteLock(); + private static final Lock eventMapReadLock = eventMapLock.readLock(); + private static final Lock eventMapWriteLock = eventMapLock.writeLock(); private SpriteRegistryCallbackHolder() { } public static Event eventLocal(Identifier key) { - return eventMap.computeIfAbsent(key, (a) -> createEvent()); + eventMapReadLock.lock(); + Event event = eventMap.get(key); + eventMapReadLock.unlock(); + + if (event == null) { + eventMapWriteLock.lock(); + event = createEvent(); + eventMap.put(key, event); + eventMapWriteLock.unlock(); + } + + return event; } private static Event createEvent() {