From 2a274e38c6769d3b5e9c6e7a750f0ba4522fda28 Mon Sep 17 00:00:00 2001 From: Noah van der Aa Date: Sat, 14 Dec 2024 18:57:57 +0100 Subject: [PATCH] net.minecraft.tags --- .../net/minecraft/tags/TagLoader.java.patch | 52 ++++++++++--------- 1 file changed, 27 insertions(+), 25 deletions(-) rename paper-server/patches/{unapplied => sources}/net/minecraft/tags/TagLoader.java.patch (63%) diff --git a/paper-server/patches/unapplied/net/minecraft/tags/TagLoader.java.patch b/paper-server/patches/sources/net/minecraft/tags/TagLoader.java.patch similarity index 63% rename from paper-server/patches/unapplied/net/minecraft/tags/TagLoader.java.patch rename to paper-server/patches/sources/net/minecraft/tags/TagLoader.java.patch index 10e1ff5cb3..fc75f3c8b7 100644 --- a/paper-server/patches/unapplied/net/minecraft/tags/TagLoader.java.patch +++ b/paper-server/patches/sources/net/minecraft/tags/TagLoader.java.patch @@ -1,56 +1,58 @@ --- a/net/minecraft/tags/TagLoader.java +++ b/net/minecraft/tags/TagLoader.java -@@ -86,7 +86,10 @@ - return list.isEmpty() ? Either.right(List.copyOf(sequencedSet)) : Either.left(list); +@@ -86,7 +_,10 @@ + return list.isEmpty() ? Either.right(List.copyOf(set)) : Either.left(list); } -- public Map> build(Map> tags) { +- public Map> build(Map> builders) { + // Paper start - fire tag registrar events -+ public Map> build(Map> tags, @Nullable io.papermc.paper.tag.TagEventConfig eventConfig) { -+ tags = io.papermc.paper.tag.PaperTagListenerManager.INSTANCE.firePreFlattenEvent(tags, eventConfig); -+ // Paper end - fire tag registrar event ++ public Map> build(Map> builders, @Nullable io.papermc.paper.tag.TagEventConfig eventConfig) { ++ builders = io.papermc.paper.tag.PaperTagListenerManager.INSTANCE.firePreFlattenEvent(builders, eventConfig); ++ // Paper end final Map> map = new HashMap<>(); TagEntry.Lookup lookup = new TagEntry.Lookup() { @Nullable -@@ -114,7 +117,7 @@ - ) - .ifRight(values -> map.put(id, (List)values)) +@@ -114,7 +_,7 @@ + ) + .ifRight(list -> map.put(path, (List)list)) ); - return map; + return io.papermc.paper.tag.PaperTagListenerManager.INSTANCE.firePostFlattenEvent(map, eventConfig); // Paper - fire tag registrar events } - public static void loadTagsFromNetwork(TagNetworkSerialization.NetworkPayload tags, WritableRegistry registry) { -@@ -122,28 +125,38 @@ + public static void loadTagsFromNetwork(TagNetworkSerialization.NetworkPayload payload, WritableRegistry registry) { +@@ -122,16 +_,27 @@ } - public static List> loadTagsForExistingRegistries(ResourceManager resourceManager, RegistryAccess registryManager) { -+ // Paper start - tag lifecycle - add cause -+ return loadTagsForExistingRegistries(resourceManager, registryManager, io.papermc.paper.plugin.lifecycle.event.registrar.ReloadableRegistrarEvent.Cause.INITIAL); + public static List> loadTagsForExistingRegistries(ResourceManager resourceManager, RegistryAccess registryAccess) { ++ // Paper start - tag lifecycle - add cause ++ return loadTagsForExistingRegistries(resourceManager, registryAccess, io.papermc.paper.plugin.lifecycle.event.registrar.ReloadableRegistrarEvent.Cause.INITIAL); + } -+ public static List> loadTagsForExistingRegistries(ResourceManager resourceManager, RegistryAccess registryManager, io.papermc.paper.plugin.lifecycle.event.registrar.ReloadableRegistrarEvent.Cause cause) { -+ // Paper end - tag lifecycle - add cause - return registryManager.registries() -- .map(registry -> loadPendingTags(resourceManager, registry.value())) -+ .map(registry -> loadPendingTags(resourceManager, registry.value(), cause)) // Paper - tag lifecycle - add cause ++ ++ public static List> loadTagsForExistingRegistries(ResourceManager resourceManager, RegistryAccess registryAccess, io.papermc.paper.plugin.lifecycle.event.registrar.ReloadableRegistrarEvent.Cause cause) { ++ // Paper end - tag lifecycle - add cause + return registryAccess.registries() +- .map(registryEntry -> loadPendingTags(resourceManager, registryEntry.value())) ++ .map(registryEntry -> loadPendingTags(resourceManager, registryEntry.value(), cause)) // Paper - tag lifecycle - add cause .flatMap(Optional::stream) .collect(Collectors.toUnmodifiableList()); } public static void loadTagsForRegistry(ResourceManager resourceManager, WritableRegistry registry) { -+ // Paper start - tag lifecycle - add registrar event cause ++ // Paper start - tag lifecycle - add registrar event cause + loadTagsForRegistry(resourceManager, registry, io.papermc.paper.plugin.lifecycle.event.registrar.ReloadableRegistrarEvent.Cause.INITIAL); + } + public static void loadTagsForRegistry(ResourceManager resourceManager, WritableRegistry registry, io.papermc.paper.plugin.lifecycle.event.registrar.ReloadableRegistrarEvent.Cause cause) { -+ // Paper end - tag lifecycle - add registrar event cause ++ // Paper end - tag lifecycle - add registrar event cause ResourceKey> resourceKey = registry.key(); TagLoader> tagLoader = new TagLoader<>(TagLoader.ElementLookup.fromWritableRegistry(registry), Registries.tagsDirPath(resourceKey)); -- tagLoader.build(tagLoader.load(resourceManager)).forEach((id, entries) -> registry.bindTag(TagKey.create(resourceKey, id), (List>)entries)); -+ tagLoader.build(tagLoader.load(resourceManager), io.papermc.paper.tag.PaperTagListenerManager.INSTANCE.createEventConfig(registry, cause)).forEach((id, entries) -> registry.bindTag(TagKey.create(resourceKey, id), (List>)entries)); // Paper - tag lifecycle - add registrar event cause +- tagLoader.build(tagLoader.load(resourceManager)) ++ tagLoader.build(tagLoader.load(resourceManager), io.papermc.paper.tag.PaperTagListenerManager.INSTANCE.createEventConfig(registry, cause)) // Paper - tag lifecycle - add registrar event cause + .forEach((resourceLocation, list) -> registry.bindTag(TagKey.create(resourceKey, resourceLocation), (List>)list)); } - private static Map, List>> wrapTags(ResourceKey> registryRef, Map>> tags) { - return tags.entrySet().stream().collect(Collectors.toUnmodifiableMap(entry -> TagKey.create(registryRef, entry.getKey()), Entry::getValue)); +@@ -139,12 +_,12 @@ + return tags.entrySet().stream().collect(Collectors.toUnmodifiableMap(entry -> TagKey.create(registryKey, entry.getKey()), Entry::getValue)); } - private static Optional> loadPendingTags(ResourceManager resourceManager, Registry registry) {