diff --git a/paper-server/patches/sources/net/minecraft/core/RegistrySetBuilder.java.patch b/paper-server/patches/sources/net/minecraft/core/RegistrySetBuilder.java.patch index 210f802c5265..b6488fedabbf 100644 --- a/paper-server/patches/sources/net/minecraft/core/RegistrySetBuilder.java.patch +++ b/paper-server/patches/sources/net/minecraft/core/RegistrySetBuilder.java.patch @@ -12,3 +12,17 @@ public ResourceKey> key() { return registryKey; } +@@ -121,6 +_,13 @@ + public Optional> lookup(ResourceKey> registryKey) { + return getEntry(registryKey).map(Entry::opsInfo); + } ++ ++ // Paper start - add method to get the value for pre-filling builders in the reg mod API ++ @Override ++ public HolderLookup.Provider lookupForValueCopyViaBuilders() { ++ throw new UnsupportedOperationException("Not implemented"); ++ } ++ // Paper end - add method to get the value for pre-filling builders in the reg mod API + }); + } + }; diff --git a/paper-server/patches/sources/net/minecraft/resources/RegistryDataLoader.java.patch b/paper-server/patches/sources/net/minecraft/resources/RegistryDataLoader.java.patch index 97a14239e606..9e6ac9823ffb 100644 --- a/paper-server/patches/sources/net/minecraft/resources/RegistryDataLoader.java.patch +++ b/paper-server/patches/sources/net/minecraft/resources/RegistryDataLoader.java.patch @@ -1,5 +1,27 @@ --- a/net/minecraft/resources/RegistryDataLoader.java +++ b/net/minecraft/resources/RegistryDataLoader.java +@@ -179,11 +_,21 @@ + final Map>, 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 Optional> lookup(ResourceKey> registryKey) { + return Optional.ofNullable((RegistryOps.RegistryInfo)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 + }; + } + @@ -247,13 +_,14 @@ RegistryOps ops, ResourceKey resourceKey, diff --git a/paper-server/patches/sources/net/minecraft/resources/RegistryOps.java.patch b/paper-server/patches/sources/net/minecraft/resources/RegistryOps.java.patch new file mode 100644 index 000000000000..93b5b31807ba --- /dev/null +++ b/paper-server/patches/sources/net/minecraft/resources/RegistryOps.java.patch @@ -0,0 +1,24 @@ +--- a/net/minecraft/resources/RegistryOps.java ++++ b/net/minecraft/resources/RegistryOps.java +@@ -117,6 +_,13 @@ + public int hashCode() { + return this.lookupProvider.hashCode(); + } ++ ++ // Paper start - add method to get the value for pre-filling builders in the reg mod API ++ @Override ++ public HolderLookup.Provider lookupForValueCopyViaBuilders() { ++ return this.lookupProvider; ++ } ++ // Paper end - add method to get the value for pre-filling builders in the reg mod API + } + + public record RegistryInfo(HolderOwner owner, HolderGetter getter, Lifecycle elementsLifecycle) { +@@ -127,5 +_,7 @@ + + public interface RegistryInfoLookup { + Optional> lookup(ResourceKey> registryKey); ++ ++ HolderLookup.Provider lookupForValueCopyViaBuilders(); // Paper - add method to get the value for pre-filling builders in the reg mod API + } + } diff --git a/paper-server/src/main/java/io/papermc/paper/registry/data/util/Conversions.java b/paper-server/src/main/java/io/papermc/paper/registry/data/util/Conversions.java index 08b87b9cadfe..6737573209a1 100644 --- a/paper-server/src/main/java/io/papermc/paper/registry/data/util/Conversions.java +++ b/paper-server/src/main/java/io/papermc/paper/registry/data/util/Conversions.java @@ -7,13 +7,10 @@ import io.papermc.paper.registry.PaperRegistryBuilder; import io.papermc.paper.registry.PaperRegistryBuilderFactory; import io.papermc.paper.registry.entry.RegistryEntryMeta; -import java.util.Optional; import java.util.function.Consumer; -import java.util.function.Function; import net.kyori.adventure.text.Component; import net.minecraft.core.Holder; import net.minecraft.core.HolderLookup; -import net.minecraft.core.MappedRegistry; import net.minecraft.core.Registry; import net.minecraft.core.RegistryAccess; import net.minecraft.resources.RegistryOps; @@ -87,14 +84,8 @@ public > Holder crea final ResourceKey> registryKey, final RegistryEntryMeta.Buildable buildableMeta ) { - final RegistryOps.RegistryInfo info = this.lookup.lookup(registryKey).orElseThrow(); - final Function, Optional> existingValueGetter; - if (info.getter() instanceof final HolderLookup.RegistryLookup registryLookup) { - existingValueGetter = registryLookup::getValueForCopying; - } else { - existingValueGetter = ((MappedRegistry) info.owner())::getValueForCopying; - } - return new PaperRegistryBuilderFactory<>(registryKey, this, buildableMeta.builderFiller(), existingValueGetter); + final HolderLookup.RegistryLookup lookupForBuilders = this.lookup.lookupForValueCopyViaBuilders().lookupOrThrow(registryKey); + return new PaperRegistryBuilderFactory<>(registryKey, this, buildableMeta.builderFiller(), lookupForBuilders::getValueForCopying); } }