feature/d01-component-system #5

Merged
NotEvil merged 20 commits from feature/d01-component-system into develop 2026-04-14 00:54:17 +00:00
Showing only changes of commit 90bc890b95 - Show all commits

View File

@@ -48,6 +48,9 @@ public final class DataDrivenItemRegistry {
*/
private static volatile RegistrySnapshot SNAPSHOT = RegistrySnapshot.EMPTY;
/** Guards read-then-write sequences in {@link #reload} and {@link #mergeAll}. */
private static final Object RELOAD_LOCK = new Object();
private DataDrivenItemRegistry() {}
/**
@@ -59,9 +62,11 @@ public final class DataDrivenItemRegistry {
public static void reload(
Map<ResourceLocation, DataDrivenItemDefinition> newDefs
) {
Map<ResourceLocation, DataDrivenItemDefinition> defs =
Collections.unmodifiableMap(new HashMap<>(newDefs));
SNAPSHOT = new RegistrySnapshot(defs, buildComponentHolders(defs));
synchronized (RELOAD_LOCK) {
Map<ResourceLocation, DataDrivenItemDefinition> defs =
Collections.unmodifiableMap(new HashMap<>(newDefs));
SNAPSHOT = new RegistrySnapshot(defs, buildComponentHolders(defs));
}
}
/**
@@ -78,13 +83,15 @@ public final class DataDrivenItemRegistry {
public static void mergeAll(
Map<ResourceLocation, DataDrivenItemDefinition> newDefs
) {
Map<ResourceLocation, DataDrivenItemDefinition> merged = new HashMap<>(
SNAPSHOT.definitions
);
merged.putAll(newDefs);
Map<ResourceLocation, DataDrivenItemDefinition> defs =
Collections.unmodifiableMap(merged);
SNAPSHOT = new RegistrySnapshot(defs, buildComponentHolders(defs));
synchronized (RELOAD_LOCK) {
Map<ResourceLocation, DataDrivenItemDefinition> merged = new HashMap<>(
SNAPSHOT.definitions
);
merged.putAll(newDefs);
Map<ResourceLocation, DataDrivenItemDefinition> defs =
Collections.unmodifiableMap(merged);
SNAPSHOT = new RegistrySnapshot(defs, buildComponentHolders(defs));
}
}
/**
@@ -95,7 +102,8 @@ public final class DataDrivenItemRegistry {
*/
@Nullable
public static DataDrivenItemDefinition get(ResourceLocation id) {
return SNAPSHOT.definitions.get(id);
RegistrySnapshot snap = SNAPSHOT;
return snap.definitions.get(id);
}
/**
@@ -113,7 +121,8 @@ public final class DataDrivenItemRegistry {
tag.getString(NBT_ITEM_ID)
);
if (id == null) return null;
return SNAPSHOT.definitions.get(id);
RegistrySnapshot snap = SNAPSHOT;
return snap.definitions.get(id);
}
/**
@@ -122,7 +131,8 @@ public final class DataDrivenItemRegistry {
* @return unmodifiable collection of all definitions
*/
public static Collection<DataDrivenItemDefinition> getAll() {
return SNAPSHOT.definitions.values();
RegistrySnapshot snap = SNAPSHOT;
return snap.definitions.values();
}
/**
@@ -168,7 +178,8 @@ public final class DataDrivenItemRegistry {
*/
@Nullable
public static ComponentHolder getComponents(ResourceLocation id) {
return SNAPSHOT.holders.get(id);
RegistrySnapshot snap = SNAPSHOT;
return snap.holders.get(id);
}
/**