This commit is contained in:
asie 2019-05-29 23:10:56 +02:00
parent 620b4d6141
commit 5b6551ce12
2 changed files with 19 additions and 2 deletions

View file

@ -1,5 +1,5 @@
archivesBaseName = "fabric-textures-v0" archivesBaseName = "fabric-textures-v0"
version = getSubprojectVersion(project, "0.1.2") version = getSubprojectVersion(project, "0.1.3")
dependencies { dependencies {
compile project(path: ':fabric-api-base', configuration: 'dev') compile project(path: ':fabric-api-base', configuration: 'dev')

View file

@ -23,17 +23,34 @@ import net.minecraft.util.Identifier;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; 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 final class SpriteRegistryCallbackHolder {
public static final Event<ClientSpriteRegistryCallback> EVENT_GLOBAL = createEvent(); public static final Event<ClientSpriteRegistryCallback> EVENT_GLOBAL = createEvent();
private static final Map<Identifier, Event<ClientSpriteRegistryCallback>> eventMap = new HashMap<>(); private static final Map<Identifier, Event<ClientSpriteRegistryCallback>> 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() { private SpriteRegistryCallbackHolder() {
} }
public static Event<ClientSpriteRegistryCallback> eventLocal(Identifier key) { public static Event<ClientSpriteRegistryCallback> eventLocal(Identifier key) {
return eventMap.computeIfAbsent(key, (a) -> createEvent()); eventMapReadLock.lock();
Event<ClientSpriteRegistryCallback> event = eventMap.get(key);
eventMapReadLock.unlock();
if (event == null) {
eventMapWriteLock.lock();
event = createEvent();
eventMap.put(key, event);
eventMapWriteLock.unlock();
}
return event;
} }
private static Event<ClientSpriteRegistryCallback> createEvent() { private static Event<ClientSpriteRegistryCallback> createEvent() {