net.minecraft.tags

This commit is contained in:
Noah van der Aa 2024-12-14 18:57:57 +01:00
parent 902965e66a
commit 2a274e38c6
No known key found for this signature in database
GPG key ID: 547D90BC6FF753CF

View file

@ -1,56 +1,58 @@
--- a/net/minecraft/tags/TagLoader.java --- a/net/minecraft/tags/TagLoader.java
+++ b/net/minecraft/tags/TagLoader.java +++ b/net/minecraft/tags/TagLoader.java
@@ -86,7 +86,10 @@ @@ -86,7 +_,10 @@
return list.isEmpty() ? Either.right(List.copyOf(sequencedSet)) : Either.left(list); return list.isEmpty() ? Either.right(List.copyOf(set)) : Either.left(list);
} }
- public Map<ResourceLocation, List<T>> build(Map<ResourceLocation, List<TagLoader.EntryWithSource>> tags) { - public Map<ResourceLocation, List<T>> build(Map<ResourceLocation, List<TagLoader.EntryWithSource>> builders) {
+ // Paper start - fire tag registrar events + // Paper start - fire tag registrar events
+ public Map<ResourceLocation, List<T>> build(Map<ResourceLocation, List<TagLoader.EntryWithSource>> tags, @Nullable io.papermc.paper.tag.TagEventConfig<T, ?> eventConfig) { + public Map<ResourceLocation, List<T>> build(Map<ResourceLocation, List<TagLoader.EntryWithSource>> builders, @Nullable io.papermc.paper.tag.TagEventConfig<T, ?> eventConfig) {
+ tags = io.papermc.paper.tag.PaperTagListenerManager.INSTANCE.firePreFlattenEvent(tags, eventConfig); + builders = io.papermc.paper.tag.PaperTagListenerManager.INSTANCE.firePreFlattenEvent(builders, eventConfig);
+ // Paper end - fire tag registrar event + // Paper end
final Map<ResourceLocation, List<T>> map = new HashMap<>(); final Map<ResourceLocation, List<T>> map = new HashMap<>();
TagEntry.Lookup<T> lookup = new TagEntry.Lookup<T>() { TagEntry.Lookup<T> lookup = new TagEntry.Lookup<T>() {
@Nullable @Nullable
@@ -114,7 +117,7 @@ @@ -114,7 +_,7 @@
) )
.ifRight(values -> map.put(id, (List<T>)values)) .ifRight(list -> map.put(path, (List<T>)list))
); );
- return map; - return map;
+ return io.papermc.paper.tag.PaperTagListenerManager.INSTANCE.firePostFlattenEvent(map, eventConfig); // Paper - fire tag registrar events + return io.papermc.paper.tag.PaperTagListenerManager.INSTANCE.firePostFlattenEvent(map, eventConfig); // Paper - fire tag registrar events
} }
public static <T> void loadTagsFromNetwork(TagNetworkSerialization.NetworkPayload tags, WritableRegistry<T> registry) { public static <T> void loadTagsFromNetwork(TagNetworkSerialization.NetworkPayload payload, WritableRegistry<T> registry) {
@@ -122,28 +125,38 @@ @@ -122,16 +_,27 @@
} }
public static List<Registry.PendingTags<?>> loadTagsForExistingRegistries(ResourceManager resourceManager, RegistryAccess registryManager) { public static List<Registry.PendingTags<?>> loadTagsForExistingRegistries(ResourceManager resourceManager, RegistryAccess registryAccess) {
+ // Paper start - tag lifecycle - add cause + // Paper start - tag lifecycle - add cause
+ return loadTagsForExistingRegistries(resourceManager, registryManager, io.papermc.paper.plugin.lifecycle.event.registrar.ReloadableRegistrarEvent.Cause.INITIAL); + return loadTagsForExistingRegistries(resourceManager, registryAccess, io.papermc.paper.plugin.lifecycle.event.registrar.ReloadableRegistrarEvent.Cause.INITIAL);
+ } + }
+ public static List<Registry.PendingTags<?>> loadTagsForExistingRegistries(ResourceManager resourceManager, RegistryAccess registryManager, io.papermc.paper.plugin.lifecycle.event.registrar.ReloadableRegistrarEvent.Cause cause) { +
+ // Paper end - tag lifecycle - add cause + public static List<Registry.PendingTags<?>> loadTagsForExistingRegistries(ResourceManager resourceManager, RegistryAccess registryAccess, io.papermc.paper.plugin.lifecycle.event.registrar.ReloadableRegistrarEvent.Cause cause) {
return registryManager.registries() + // Paper end - tag lifecycle - add cause
- .map(registry -> loadPendingTags(resourceManager, registry.value())) return registryAccess.registries()
+ .map(registry -> loadPendingTags(resourceManager, registry.value(), cause)) // Paper - tag lifecycle - add cause - .map(registryEntry -> loadPendingTags(resourceManager, registryEntry.value()))
+ .map(registryEntry -> loadPendingTags(resourceManager, registryEntry.value(), cause)) // Paper - tag lifecycle - add cause
.flatMap(Optional::stream) .flatMap(Optional::stream)
.collect(Collectors.toUnmodifiableList()); .collect(Collectors.toUnmodifiableList());
} }
public static <T> void loadTagsForRegistry(ResourceManager resourceManager, WritableRegistry<T> registry) { public static <T> void loadTagsForRegistry(ResourceManager resourceManager, WritableRegistry<T> 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); + loadTagsForRegistry(resourceManager, registry, io.papermc.paper.plugin.lifecycle.event.registrar.ReloadableRegistrarEvent.Cause.INITIAL);
+ } + }
+ public static <T> void loadTagsForRegistry(ResourceManager resourceManager, WritableRegistry<T> registry, io.papermc.paper.plugin.lifecycle.event.registrar.ReloadableRegistrarEvent.Cause cause) { + public static <T> void loadTagsForRegistry(ResourceManager resourceManager, WritableRegistry<T> 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<? extends Registry<T>> resourceKey = registry.key(); ResourceKey<? extends Registry<T>> resourceKey = registry.key();
TagLoader<Holder<T>> tagLoader = new TagLoader<>(TagLoader.ElementLookup.fromWritableRegistry(registry), Registries.tagsDirPath(resourceKey)); TagLoader<Holder<T>> 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<Holder<T>>)entries)); - tagLoader.build(tagLoader.load(resourceManager))
+ tagLoader.build(tagLoader.load(resourceManager), io.papermc.paper.tag.PaperTagListenerManager.INSTANCE.createEventConfig(registry, cause)).forEach((id, entries) -> registry.bindTag(TagKey.create(resourceKey, id), (List<Holder<T>>)entries)); // Paper - tag lifecycle - add registrar event cause + 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<Holder<T>>)list));
} }
private static <T> Map<TagKey<T>, List<Holder<T>>> wrapTags(ResourceKey<? extends Registry<T>> registryRef, Map<ResourceLocation, List<Holder<T>>> tags) { @@ -139,12 +_,12 @@
return tags.entrySet().stream().collect(Collectors.toUnmodifiableMap(entry -> TagKey.create(registryRef, entry.getKey()), Entry::getValue)); return tags.entrySet().stream().collect(Collectors.toUnmodifiableMap(entry -> TagKey.create(registryKey, entry.getKey()), Entry::getValue));
} }
- private static <T> Optional<Registry.PendingTags<T>> loadPendingTags(ResourceManager resourceManager, Registry<T> registry) { - private static <T> Optional<Registry.PendingTags<T>> loadPendingTags(ResourceManager resourceManager, Registry<T> registry) {