From d027a2c341019daae289136392712a06a62181a7 Mon Sep 17 00:00:00 2001 From: Noah van der Aa Date: Sat, 14 Dec 2024 18:17:02 +0100 Subject: [PATCH] net.minecraft.resources --- .../resources/RegistryDataLoader.java.patch | 71 +++++++++++++++++ .../resources/ResourceLocation.java.patch | 8 +- .../resources/RegistryDataLoader.java.patch | 79 ------------------- 3 files changed, 75 insertions(+), 83 deletions(-) create mode 100644 paper-server/patches/sources/net/minecraft/resources/RegistryDataLoader.java.patch rename paper-server/patches/{unapplied => sources}/net/minecraft/resources/ResourceLocation.java.patch (96%) delete mode 100644 paper-server/patches/unapplied/net/minecraft/resources/RegistryDataLoader.java.patch diff --git a/paper-server/patches/sources/net/minecraft/resources/RegistryDataLoader.java.patch b/paper-server/patches/sources/net/minecraft/resources/RegistryDataLoader.java.patch new file mode 100644 index 0000000000..c625d649d2 --- /dev/null +++ b/paper-server/patches/sources/net/minecraft/resources/RegistryDataLoader.java.patch @@ -0,0 +1,71 @@ +--- a/net/minecraft/resources/RegistryDataLoader.java ++++ b/net/minecraft/resources/RegistryDataLoader.java +@@ -247,13 +_,14 @@ + RegistryOps ops, + ResourceKey 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 = JsonParser.parseReader(reader); + DataResult 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 + } + } + +@@ -267,6 +_,7 @@ + FileToIdConverter fileToIdConverter = FileToIdConverter.registry(registry.key()); + RegistryOps 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 entry : fileToIdConverter.listMatchingResources(resourceManager).entrySet()) { + ResourceLocation resourceLocation = entry.getKey(); + ResourceKey resourceKey = ResourceKey.create(registry.key(), fileToIdConverter.fileToId(resourceLocation)); +@@ -274,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, +@@ -283,7 +_,8 @@ + } + } + +- TagLoader.loadTagsForRegistry(resourceManager, registry); ++ 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 void loadContentsFromNetwork( +@@ -300,6 +_,7 @@ + RegistryOps 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 resourceKey = ResourceKey.create(registry.key(), packedRegistryEntry.id()); + Optional optional = packedRegistryEntry.data(); +@@ -318,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)); + } +@@ -360,6 +_,7 @@ + + RegistryDataLoader.Loader create(Lifecycle registryLifecycle, Map, Exception> loadingErrors) { + WritableRegistry writableRegistry = new MappedRegistry<>(this.key, registryLifecycle); ++ io.papermc.paper.registry.PaperRegistryAccess.instance().registerRegistry(this.key, writableRegistry); // Paper - initialize API registry + return new RegistryDataLoader.Loader<>(this, writableRegistry, loadingErrors); + } + diff --git a/paper-server/patches/unapplied/net/minecraft/resources/ResourceLocation.java.patch b/paper-server/patches/sources/net/minecraft/resources/ResourceLocation.java.patch similarity index 96% rename from paper-server/patches/unapplied/net/minecraft/resources/ResourceLocation.java.patch rename to paper-server/patches/sources/net/minecraft/resources/ResourceLocation.java.patch index 4f2bd280fb..db3f21405a 100644 --- a/paper-server/patches/unapplied/net/minecraft/resources/ResourceLocation.java.patch +++ b/paper-server/patches/sources/net/minecraft/resources/ResourceLocation.java.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/resources/ResourceLocation.java +++ b/net/minecraft/resources/ResourceLocation.java -@@ -32,6 +32,7 @@ +@@ -32,6 +_,7 @@ public static final char NAMESPACE_SEPARATOR = ':'; public static final String DEFAULT_NAMESPACE = "minecraft"; public static final String REALMS_NAMESPACE = "realms"; @@ -8,7 +8,7 @@ private final String namespace; private final String path; -@@ -40,6 +41,13 @@ +@@ -40,6 +_,13 @@ assert isValidPath(path); @@ -22,7 +22,7 @@ this.namespace = namespace; this.path = path; } -@@ -246,7 +254,7 @@ +@@ -252,7 +_,7 @@ private static String assertValidNamespace(String namespace, String path) { if (!isValidNamespace(namespace)) { @@ -31,7 +31,7 @@ } else { return namespace; } -@@ -267,7 +275,7 @@ +@@ -277,7 +_,7 @@ private static String assertValidPath(String namespace, String path) { if (!isValidPath(path)) { diff --git a/paper-server/patches/unapplied/net/minecraft/resources/RegistryDataLoader.java.patch b/paper-server/patches/unapplied/net/minecraft/resources/RegistryDataLoader.java.patch deleted file mode 100644 index 41773a3732..0000000000 --- a/paper-server/patches/unapplied/net/minecraft/resources/RegistryDataLoader.java.patch +++ /dev/null @@ -1,79 +0,0 @@ ---- a/net/minecraft/resources/RegistryDataLoader.java -+++ b/net/minecraft/resources/RegistryDataLoader.java -@@ -74,7 +74,7 @@ - - public class RegistryDataLoader { - private static final Logger LOGGER = LogUtils.getLogger(); -- private static final Comparator> ERROR_KEY_COMPARATOR = Comparator.comparing(ResourceKey::registry).thenComparing(ResourceKey::location); -+ private static final Comparator> ERROR_KEY_COMPARATOR = Comparator., ResourceLocation>comparing(ResourceKey::registry).thenComparing(ResourceKey::location); // Paper - decompile fix - private static final RegistrationInfo NETWORK_REGISTRATION_INFO = new RegistrationInfo(Optional.empty(), Lifecycle.experimental()); - private static final Function, RegistrationInfo> REGISTRATION_INFO_CACHE = Util.memoize(knownPacks -> { - Lifecycle lifecycle = knownPacks.map(KnownPack::isVanilla).map(vanilla -> Lifecycle.stable()).orElse(Lifecycle.experimental()); -@@ -238,13 +238,13 @@ - } - - private static void loadElementFromResource( -- WritableRegistry registry, Decoder decoder, RegistryOps ops, ResourceKey key, Resource resource, RegistrationInfo entryInfo -+ WritableRegistry registry, Decoder decoder, RegistryOps ops, ResourceKey key, Resource resource, RegistrationInfo entryInfo, io.papermc.paper.registry.data.util.Conversions conversions // Paper - pass conversions - ) throws IOException { - try (Reader reader = resource.openAsReader()) { - JsonElement jsonElement = JsonParser.parseReader(reader); - DataResult dataResult = decoder.parse(ops, jsonElement); - E object = dataResult.getOrThrow(); -- registry.register(key, object, entryInfo); -+ io.papermc.paper.registry.PaperRegistryListenerManager.INSTANCE.registerWithListeners(registry, key, object, entryInfo, conversions); // Paper - register with listeners - } - } - -@@ -258,6 +258,7 @@ - FileToIdConverter fileToIdConverter = FileToIdConverter.registry(registry.key()); - RegistryOps registryOps = RegistryOps.create(JsonOps.INSTANCE, infoGetter); - -+ final io.papermc.paper.registry.data.util.Conversions conversions = new io.papermc.paper.registry.data.util.Conversions(infoGetter); // Paper - create conversions - for (Entry entry : fileToIdConverter.listMatchingResources(resourceManager).entrySet()) { - ResourceLocation resourceLocation = entry.getKey(); - ResourceKey resourceKey = ResourceKey.create(registry.key(), fileToIdConverter.fileToId(resourceLocation)); -@@ -265,7 +266,7 @@ - RegistrationInfo registrationInfo = REGISTRATION_INFO_CACHE.apply(resource.knownPackInfo()); - - try { -- loadElementFromResource(registry, elementDecoder, registryOps, resourceKey, resource, registrationInfo); -+ loadElementFromResource(registry, elementDecoder, registryOps, resourceKey, resource, registrationInfo, conversions); // Paper - pass conversions - } catch (Exception var14) { - errors.put( - resourceKey, -@@ -274,7 +275,8 @@ - } - } - -- TagLoader.loadTagsForRegistry(resourceManager, registry); -+ 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 void loadContentsFromNetwork( -@@ -291,6 +293,7 @@ - RegistryOps registryOps2 = RegistryOps.create(JsonOps.INSTANCE, infoGetter); - FileToIdConverter fileToIdConverter = FileToIdConverter.registry(registry.key()); - -+ final io.papermc.paper.registry.data.util.Conversions conversions = new io.papermc.paper.registry.data.util.Conversions(infoGetter); // Paper - create conversions - for (RegistrySynchronization.PackedRegistryEntry packedRegistryEntry : networkedRegistryData.elements) { - ResourceKey resourceKey = ResourceKey.create(registry.key(), packedRegistryEntry.id()); - Optional optional = packedRegistryEntry.data(); -@@ -309,7 +312,7 @@ - - try { - Resource resource = factory.getResourceOrThrow(resourceLocation); -- loadElementFromResource(registry, decoder, registryOps2, resourceKey, resource, NETWORK_REGISTRATION_INFO); -+ loadElementFromResource(registry, decoder, registryOps2, resourceKey, resource, NETWORK_REGISTRATION_INFO, conversions); // Paper - pass conversions - } catch (Exception var17) { - loadingErrors.put(resourceKey, new IllegalStateException("Failed to parse local data", var17)); - } -@@ -349,6 +352,7 @@ - - RegistryDataLoader.Loader create(Lifecycle lifecycle, Map, Exception> errors) { - WritableRegistry writableRegistry = new MappedRegistry<>(this.key, lifecycle); -+ io.papermc.paper.registry.PaperRegistryAccess.instance().registerRegistry(this.key, writableRegistry); // Paper - initialize API registry - return new RegistryDataLoader.Loader<>(this, writableRegistry, errors); - } -