mirror of
https://github.com/FabricMC/fabric.git
synced 2024-11-22 23:58:02 -05:00
fix #222
This commit is contained in:
parent
620b4d6141
commit
5b6551ce12
2 changed files with 19 additions and 2 deletions
|
@ -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')
|
||||
|
|
|
@ -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<ClientSpriteRegistryCallback> EVENT_GLOBAL = createEvent();
|
||||
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() {
|
||||
|
||||
}
|
||||
|
||||
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() {
|
||||
|
|
Loading…
Reference in a new issue