mirror of
https://github.com/PaperMC/Paper.git
synced 2025-08-02 05:02:10 -07:00
Co-authored-by: Bjarne Koll <git@lynxplay.dev> Co-authored-by: Jake Potrebic <jake.m.potrebic@gmail.com> Co-authored-by: Jason Penilla <11360596+jpenilla@users.noreply.github.com> Co-authored-by: Lulu13022002 <41980282+Lulu13022002@users.noreply.github.com> Co-authored-by: Noah van der Aa <ndvdaa@gmail.com> Co-authored-by: Owen1212055 <23108066+Owen1212055@users.noreply.github.com> Co-authored-by: Spottedleaf <Spottedleaf@users.noreply.github.com>
95 lines
6.2 KiB
Diff
95 lines
6.2 KiB
Diff
--- a/net/minecraft/resources/RegistryDataLoader.java
|
|
+++ b/net/minecraft/resources/RegistryDataLoader.java
|
|
@@ -206,11 +_,21 @@
|
|
final Map<ResourceKey<? extends Registry<?>>, RegistryOps.RegistryInfo<?>> map = new HashMap<>();
|
|
registryLookups.forEach(registryLookup -> map.put(registryLookup.key(), createInfoForContextRegistry((HolderLookup.RegistryLookup<?>)registryLookup)));
|
|
loaders.forEach(loader -> map.put(loader.registry.key(), createInfoForNewRegistry(loader.registry)));
|
|
+ // this creates a HolderLookup.Provider to be used exclusively to obtain real instances of values to pre-populate builders
|
|
+ // for the Registry Modification API. This concatenates the context registry lookups and the empty registries about to be filled.
|
|
+ final HolderLookup.Provider providerForBuilders = HolderLookup.Provider.create(java.util.stream.Stream.concat(registryLookups.stream(), loaders.stream().map(Loader::registry))); // Paper - add method to get the value for pre-filling builders in the reg mod API
|
|
return new RegistryOps.RegistryInfoLookup() {
|
|
@Override
|
|
public <T> Optional<RegistryOps.RegistryInfo<T>> lookup(ResourceKey<? extends Registry<? extends T>> registryKey) {
|
|
return Optional.ofNullable((RegistryOps.RegistryInfo<T>)map.get(registryKey));
|
|
}
|
|
+
|
|
+ // Paper start - add method to get the value for pre-filling builders in the reg mod API
|
|
+ @Override
|
|
+ public HolderLookup.Provider lookupForValueCopyViaBuilders() {
|
|
+ return providerForBuilders;
|
|
+ }
|
|
+ // Paper end - add method to get the value for pre-filling builders in the reg mod API
|
|
};
|
|
}
|
|
|
|
@@ -274,13 +_,14 @@
|
|
RegistryOps<JsonElement> ops,
|
|
ResourceKey<E> resourceKey,
|
|
Resource resource,
|
|
- RegistrationInfo registrationInfo
|
|
+ RegistrationInfo registrationInfo,
|
|
+ io.papermc.paper.registry.data.util.Conversions conversions // Paper - pass conversions
|
|
) throws IOException {
|
|
try (Reader reader = resource.openAsReader()) {
|
|
JsonElement jsonElement = StrictJsonParser.parse(reader);
|
|
DataResult<E> dataResult = codec.parse(ops, jsonElement);
|
|
E orThrow = dataResult.getOrThrow();
|
|
- registry.register(resourceKey, orThrow, registrationInfo);
|
|
+ io.papermc.paper.registry.PaperRegistryListenerManager.INSTANCE.registerWithListeners(registry, resourceKey, orThrow, registrationInfo, conversions); // Paper - register with listeners
|
|
}
|
|
}
|
|
|
|
@@ -294,6 +_,7 @@
|
|
FileToIdConverter fileToIdConverter = FileToIdConverter.registry(registry.key());
|
|
RegistryOps<JsonElement> registryOps = RegistryOps.create(JsonOps.INSTANCE, registryInfoLookup);
|
|
|
|
+ final io.papermc.paper.registry.data.util.Conversions conversions = new io.papermc.paper.registry.data.util.Conversions(registryInfoLookup); // Paper - create conversions
|
|
for (Entry<ResourceLocation, Resource> entry : fileToIdConverter.listMatchingResources(resourceManager).entrySet()) {
|
|
ResourceLocation resourceLocation = entry.getKey();
|
|
ResourceKey<E> resourceKey = ResourceKey.create(registry.key(), fileToIdConverter.fileToId(resourceLocation));
|
|
@@ -301,7 +_,7 @@
|
|
RegistrationInfo registrationInfo = REGISTRATION_INFO_CACHE.apply(resource.knownPackInfo());
|
|
|
|
try {
|
|
- loadElementFromResource(registry, codec, registryOps, resourceKey, resource, registrationInfo);
|
|
+ loadElementFromResource(registry, codec, registryOps, resourceKey, resource, registrationInfo, conversions); // Paper - pass conversions
|
|
} catch (Exception var14) {
|
|
loadingErrors.put(
|
|
resourceKey,
|
|
@@ -310,7 +_,9 @@
|
|
}
|
|
}
|
|
|
|
- TagLoader.loadTagsForRegistry(resourceManager, registry);
|
|
+ io.papermc.paper.registry.PaperRegistryAccess.instance().lockReferenceHolders(registry.key()); // Paper - lock reference holders
|
|
+ io.papermc.paper.registry.PaperRegistryListenerManager.INSTANCE.runFreezeListeners(registry.key(), conversions); // Paper - run pre-freeze listeners
|
|
+ TagLoader.loadTagsForRegistry(resourceManager, registry, io.papermc.paper.plugin.lifecycle.event.registrar.ReloadableRegistrarEvent.Cause.INITIAL); // Paper - tag lifecycle - add cause
|
|
}
|
|
|
|
static <E> void loadContentsFromNetwork(
|
|
@@ -327,6 +_,7 @@
|
|
RegistryOps<JsonElement> registryOps1 = RegistryOps.create(JsonOps.INSTANCE, registryInfoLookup);
|
|
FileToIdConverter fileToIdConverter = FileToIdConverter.registry(registry.key());
|
|
|
|
+ final io.papermc.paper.registry.data.util.Conversions conversions = new io.papermc.paper.registry.data.util.Conversions(registryInfoLookup); // Paper - create conversions
|
|
for (RegistrySynchronization.PackedRegistryEntry packedRegistryEntry : networkedRegistryData.elements) {
|
|
ResourceKey<E> resourceKey = ResourceKey.create(registry.key(), packedRegistryEntry.id());
|
|
Optional<Tag> optional = packedRegistryEntry.data();
|
|
@@ -345,7 +_,7 @@
|
|
|
|
try {
|
|
Resource resourceOrThrow = resourceProvider.getResourceOrThrow(resourceLocation);
|
|
- loadElementFromResource(registry, codec, registryOps1, resourceKey, resourceOrThrow, NETWORK_REGISTRATION_INFO);
|
|
+ loadElementFromResource(registry, codec, registryOps1, resourceKey, resourceOrThrow, NETWORK_REGISTRATION_INFO, conversions); // Paper - pass conversions
|
|
} catch (Exception var17) {
|
|
loadingErrors.put(resourceKey, new IllegalStateException("Failed to parse local data", var17));
|
|
}
|
|
@@ -387,6 +_,7 @@
|
|
|
|
RegistryDataLoader.Loader<T> create(Lifecycle registryLifecycle, Map<ResourceKey<?>, Exception> loadingErrors) {
|
|
WritableRegistry<T> writableRegistry = new MappedRegistry<>(this.key, registryLifecycle);
|
|
+ io.papermc.paper.registry.PaperRegistryAccess.instance().registerRegistry(writableRegistry); // Paper - initialize API registry
|
|
return new RegistryDataLoader.Loader<>(this, writableRegistry, loadingErrors);
|
|
}
|
|
|