getOrCreateRegistry

This commit is contained in:
dfsek
2021-07-05 21:56:14 -07:00
parent 04725698e8
commit 4acfeab948
2 changed files with 11 additions and 1 deletions

View File

@@ -15,6 +15,8 @@ import java.util.Set;
public interface ConfigPack extends LoaderRegistrar, LoaderHolder, RegistryHolder {
BiomeProviderBuilder getBiomeProviderBuilder();
<T> CheckedRegistry<T> getOrCreateRegistry(Class<T> clazz);
WorldConfig toWorldConfig(TerraWorld world);
void registerConfigType(ConfigType<?, ?> type, String id, int priority);

View File

@@ -194,7 +194,6 @@ public class ConfigPackImpl implements ConfigPack {
}
};
putPair(map, NoiseProvider.class, new NoiseRegistry());
putPair(map, LootTable.class, new OpenRegistryImpl<>());
putPair(map, Structure.class, new OpenRegistryImpl<>());
@@ -302,6 +301,15 @@ public class ConfigPackImpl implements ConfigPack {
return biomeProviderBuilder;
}
@SuppressWarnings("unchecked")
@Override
public <T> CheckedRegistry<T> getOrCreateRegistry(Class<T> clazz) {
return (CheckedRegistry<T>) registryMap.computeIfAbsent(clazz, c -> {
OpenRegistry<T> registry = new OpenRegistryImpl<>();
return ImmutablePair.of(registry, new CheckedRegistryImpl<>(registry));
}).getRight();
}
@Override
public WorldConfigImpl toWorldConfig(TerraWorld world) {