From 4e064745c2c7dd26a0aeab177e7d04f7b5fba3cc Mon Sep 17 00:00:00 2001 From: Jake Potrebic Date: Sat, 11 May 2024 19:26:33 -0700 Subject: RegistrySet API --- patches/api/0434-Improve-Registry.patch | 36 +- patches/api/0478-Registry-Modification-API.patch | 2 +- patches/api/0479-RegistrySet-API.patch | 486 ++++++++++++ .../server/0991-Registry-Modification-API.patch | 864 --------------------- .../server/1001-Registry-Modification-API.patch | 852 ++++++++++++++++++++ patches/server/1002-RegistrySet-API.patch | 224 ++++++ 6 files changed, 1596 insertions(+), 868 deletions(-) create mode 100644 patches/api/0479-RegistrySet-API.patch delete mode 100644 patches/server/0991-Registry-Modification-API.patch create mode 100644 patches/server/1001-Registry-Modification-API.patch create mode 100644 patches/server/1002-RegistrySet-API.patch diff --git a/patches/api/0434-Improve-Registry.patch b/patches/api/0434-Improve-Registry.patch index 1d2d6fa13c..fd25406955 100644 --- a/patches/api/0434-Improve-Registry.patch +++ b/patches/api/0434-Improve-Registry.patch @@ -31,15 +31,45 @@ index 62d2b3f950860dee0898d77b0a29635c3f9a7e23..704dba92f9246ef398ed8d162ebee3cf @Override public @NotNull String translationKey() { diff --git a/src/main/java/org/bukkit/Registry.java b/src/main/java/org/bukkit/Registry.java -index 5ba5cf06bf12fc2e81500e09209e26047e683fa9..802511eaf697d703cadb4b418fe51ea6d31ff3c8 100644 +index 5ba5cf06bf12fc2e81500e09209e26047e683fa9..b02160f42281bc4e20123752a593c5d655305381 100644 --- a/src/main/java/org/bukkit/Registry.java +++ b/src/main/java/org/bukkit/Registry.java -@@ -354,6 +354,49 @@ public interface Registry extends Iterable { +@@ -354,6 +354,79 @@ public interface Registry extends Iterable { @Nullable T get(@NotNull NamespacedKey key); + // Paper start - improve Registry + /** ++ * Gets the object by its key or throws if it doesn't exist. ++ * ++ * @param key the key to get the object of in this registry ++ * @return the object for the key ++ * @throws java.util.NoSuchElementException if the key doesn't point to an object in the registry ++ */ ++ default @NotNull T getOrThrow(final net.kyori.adventure.key.@NotNull Key key) { ++ final T value = this.get(key); ++ if (value == null) { ++ throw new java.util.NoSuchElementException("No value for " + key + " in " + this); ++ } ++ return value; ++ } ++ ++ /** ++ * Gets the object by its key or throws if it doesn't exist. ++ * ++ * @param key the key to get the object of in this registry ++ * @return the object for the key ++ * @throws java.util.NoSuchElementException if the key doesn't point to an object in the registry ++ */ ++ default @NotNull T getOrThrow(final io.papermc.paper.registry.@NotNull TypedKey key) { ++ final T value = this.get(key); ++ if (value == null) { ++ throw new java.util.NoSuchElementException("No value for " + key + " in " + this); ++ } ++ return value; ++ } ++ ++ /** + * Gets the key for this object or throws if it doesn't exist. + *

+ * Some types can exist without being in a registry @@ -84,7 +114,7 @@ index 5ba5cf06bf12fc2e81500e09209e26047e683fa9..802511eaf697d703cadb4b418fe51ea6 /** * Returns a new stream, which contains all registry items, which are registered to the registry. * -@@ -428,5 +471,12 @@ public interface Registry extends Iterable { +@@ -428,5 +501,12 @@ public interface Registry extends Iterable { public Class getType() { return this.type; } diff --git a/patches/api/0478-Registry-Modification-API.patch b/patches/api/0478-Registry-Modification-API.patch index 70f095bc1f..b6d067058b 100644 --- a/patches/api/0478-Registry-Modification-API.patch +++ b/patches/api/0478-Registry-Modification-API.patch @@ -366,7 +366,7 @@ index 0000000000000000000000000000000000000000..f4d4ebf6cbed1b4a9955ceb2d0586782 +public interface RegistryEntryAddEventType> extends LifecycleEventType, RegistryEntryAddConfiguration> { +} diff --git a/src/main/java/org/bukkit/Registry.java b/src/main/java/org/bukkit/Registry.java -index 802511eaf697d703cadb4b418fe51ea6d31ff3c8..85c4f231dc343c73f1678819f1ac95d5a7ffd080 100644 +index b02160f42281bc4e20123752a593c5d655305381..240500771bac439156b4c5d93ff047ae45d56154 100644 --- a/src/main/java/org/bukkit/Registry.java +++ b/src/main/java/org/bukkit/Registry.java @@ -353,6 +353,27 @@ public interface Registry extends Iterable { diff --git a/patches/api/0479-RegistrySet-API.patch b/patches/api/0479-RegistrySet-API.patch new file mode 100644 index 0000000000..7f310e04cb --- /dev/null +++ b/patches/api/0479-RegistrySet-API.patch @@ -0,0 +1,486 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Jake Potrebic +Date: Sat, 11 May 2024 19:25:48 -0700 +Subject: [PATCH] RegistrySet API + +This API is supposed to be the API equivalent of nms' +HolderSet and HolderSet$Named. + +diff --git a/src/main/java/io/papermc/paper/registry/set/RegistryKeySet.java b/src/main/java/io/papermc/paper/registry/set/RegistryKeySet.java +new file mode 100644 +index 0000000000000000000000000000000000000000..2a36c5ec0da05c7ff19023c542e4b6b04326b8ee +--- /dev/null ++++ b/src/main/java/io/papermc/paper/registry/set/RegistryKeySet.java +@@ -0,0 +1,40 @@ ++package io.papermc.paper.registry.set; ++ ++import io.papermc.paper.registry.TypedKey; ++import io.papermc.paper.registry.tag.Tag; ++import java.util.Collection; ++import org.bukkit.Keyed; ++import org.bukkit.Registry; ++import org.checkerframework.checker.nullness.qual.NonNull; ++import org.jetbrains.annotations.ApiStatus; ++import org.jetbrains.annotations.Unmodifiable; ++ ++@ApiStatus.Experimental ++@ApiStatus.NonExtendable ++public non-sealed interface RegistryKeySet extends RegistrySet { // TODO remove Keyed ++ ++ @Override ++ default int size() { ++ return this.values().size(); ++ } ++ ++ /** ++ * Get the keys for the values in this set. ++ * ++ * @return the keys ++ */ ++ @NonNull @Unmodifiable Collection> values(); ++ ++ /** ++ * Resolve this set into a collection of values. Depending on the use ++ * case, it may be better to specifically check if this set is a ++ * {@link RegistryKeySet} or a {@link RegistryValueSet} and access ++ * the keys or values, respectively, directly. May ++ * fail if called too early or a registered value is missing. ++ * ++ * @return the resolved values ++ * @see RegistryKeySet#values() ++ * @see RegistryValueSet#values() ++ */ ++ @NonNull @Unmodifiable Collection resolve(final @NonNull Registry registry); ++} +diff --git a/src/main/java/io/papermc/paper/registry/set/RegistryKeySetImpl.java b/src/main/java/io/papermc/paper/registry/set/RegistryKeySetImpl.java +new file mode 100644 +index 0000000000000000000000000000000000000000..c712181ad4c6a9d00bc04f8a48515a388c692f48 +--- /dev/null ++++ b/src/main/java/io/papermc/paper/registry/set/RegistryKeySetImpl.java +@@ -0,0 +1,53 @@ ++package io.papermc.paper.registry.set; ++ ++import com.google.common.base.Preconditions; ++import io.papermc.paper.registry.RegistryAccess; ++import io.papermc.paper.registry.RegistryKey; ++import io.papermc.paper.registry.TypedKey; ++import java.util.ArrayList; ++import java.util.Collection; ++import java.util.Collections; ++import java.util.List; ++import org.bukkit.Keyed; ++import org.bukkit.NamespacedKey; ++import org.bukkit.Registry; ++import org.checkerframework.checker.nullness.qual.NonNull; ++import org.checkerframework.framework.qual.DefaultQualifier; ++import org.jetbrains.annotations.ApiStatus; ++import org.jetbrains.annotations.Nullable; ++ ++@ApiStatus.Internal ++@DefaultQualifier(NonNull.class) ++record RegistryKeySetImpl(RegistryKey registryKey, List> values) implements RegistryKeySet { // TODO remove Keyed ++ ++ static RegistryKeySet create(final RegistryKey registryKey, final Iterable values) { // TODO remove Keyed ++ final Registry registry = RegistryAccess.registryAccess().getRegistry(registryKey); ++ final ArrayList> keys = new ArrayList<>(); ++ for (final T value : values) { ++ final @Nullable NamespacedKey key = registry.getKey(value); ++ Preconditions.checkArgument(key != null, value + " does not have a key in " + registryKey); ++ keys.add(TypedKey.create(registryKey, key)); ++ } ++ return new RegistryKeySetImpl<>(registryKey, keys); ++ } ++ ++ RegistryKeySetImpl { ++ values = List.copyOf(values); ++ } ++ ++ @Override ++ public boolean contains(final TypedKey valueKey) { ++ return this.values.contains(valueKey); ++ } ++ ++ @Override ++ public Collection resolve(final Registry registry) { ++ final List values = new ArrayList<>(this.values.size()); ++ for (final TypedKey key : this.values) { ++ final @Nullable T value = registry.get(key.key()); ++ Preconditions.checkState(value != null, "Trying to access unbound TypedKey: " + key); ++ values.add(value); ++ } ++ return Collections.unmodifiableList(values); ++ } ++} +diff --git a/src/main/java/io/papermc/paper/registry/set/RegistrySet.java b/src/main/java/io/papermc/paper/registry/set/RegistrySet.java +new file mode 100644 +index 0000000000000000000000000000000000000000..f414df1a114f9d727c27fecc55712b6f5ff415fb +--- /dev/null ++++ b/src/main/java/io/papermc/paper/registry/set/RegistrySet.java +@@ -0,0 +1,101 @@ ++package io.papermc.paper.registry.set; ++ ++import com.google.common.collect.Lists; ++import io.papermc.paper.registry.RegistryKey; ++import io.papermc.paper.registry.TypedKey; ++import io.papermc.paper.registry.tag.Tag; ++import java.util.Collection; ++import java.util.Iterator; ++import org.bukkit.Keyed; ++import org.checkerframework.checker.nullness.qual.NonNull; ++import org.jetbrains.annotations.ApiStatus; ++import org.jetbrains.annotations.Contract; ++import org.jetbrains.annotations.Unmodifiable; ++ ++/** ++ * Represents a collection tied to a registry. ++ *

++ * There are 2 types of registry sets: ++ *

    ++ *
  • {@link Tag} which is a tag from vanilla or a datapack. ++ * These are obtained via {@link org.bukkit.Registry#getTag(io.papermc.paper.registry.tag.TagKey)}.
  • ++ *
  • {@link RegistryKeySet} which is a set of of values that are present in the registry. These are ++ * created via {@link #keySet(RegistryKey, Iterable)} or {@link #keySetFromValues(RegistryKey, Iterable)}.
  • ++ * ++ *
++ * ++ * @param registry value type ++ */ ++@ApiStatus.Experimental ++public sealed interface RegistrySet permits RegistryKeySet, RegistryValueSet { ++ ++ // TODO uncomment when direct holder sets need to be exposed to the API ++ // /** ++ // * Creates a {@link RegistryValueSet} from anonymous values. ++ // *

All values provided must not have keys in the given registry.

++ // * ++ // * @param registryKey the registry key for the type of these values ++ // * @param values the values ++ // * @return a new registry set ++ // * @param the type of the values ++ // */ ++ // @Contract(value = "_, _ -> new", pure = true) ++ // static @NonNull RegistryValueSet valueSet(final @NonNull RegistryKey registryKey, final @NonNull Iterable values) { ++ // return RegistryValueSetImpl.create(registryKey, values); ++ // } ++ ++ /** ++ * Creates a {@link RegistryKeySet} from registry-backed values. ++ *

All values provided must have keys in the given registry. ++ *

++ *

If references to actual objects are not available yet, use {@link #keySet(RegistryKey, Iterable)} to ++ * create an equivalent {@link RegistryKeySet} using just {@link TypedKey TypedKeys}.

++ * ++ * @param registryKey the registry key for the owner of these values ++ * @param values the values ++ * @return a new registry set ++ * @param the type of the values ++ * @throws IllegalArgumentException if the registry isn't available yet or if any value doesn't have a key in that registry ++ */ ++ @Contract(value = "_, _ -> new", pure = true) ++ static @NonNull RegistryKeySet keySetFromValues(final @NonNull RegistryKey registryKey, final @NonNull Iterable values) { // TODO remove Keyed ++ return RegistryKeySetImpl.create(registryKey, values); ++ } ++ ++ /** ++ * Creates a direct {@link RegistrySet} from {@link TypedKey TypedKeys}. ++ * ++ * @param registryKey the registry key for the owner of these keys ++ * @param keys the keys for the values ++ * @return a new registry set ++ * @param the type of the values ++ */ ++ @SuppressWarnings("BoundedWildcard") ++ @Contract(value = "_, _ -> new", pure = true) ++ static @NonNull RegistryKeySet keySet(final @NonNull RegistryKey registryKey, final @NonNull Iterable> keys) { // TODO remove Keyed ++ return new RegistryKeySetImpl<>(registryKey, Lists.newArrayList(keys)); ++ } ++ ++ /** ++ * Get the registry key for this set. ++ * ++ * @return the registry key ++ */ ++ @NonNull RegistryKey registryKey(); ++ ++ /** ++ * Get the size of this set. ++ * ++ * @return the size ++ */ ++ int size(); ++ ++ /** ++ * Checks if this set contains the value with the given key. ++ * ++ * @param valueKey the key to check ++ * @return true if the value is in this set ++ */ ++ boolean contains(@NonNull TypedKey valueKey); ++} +diff --git a/src/main/java/io/papermc/paper/registry/set/RegistryValueSet.java b/src/main/java/io/papermc/paper/registry/set/RegistryValueSet.java +new file mode 100644 +index 0000000000000000000000000000000000000000..9cbbb507738a4cdcd9f48a36ac00d2d5628a7f94 +--- /dev/null ++++ b/src/main/java/io/papermc/paper/registry/set/RegistryValueSet.java +@@ -0,0 +1,45 @@ ++package io.papermc.paper.registry.set; ++ ++import io.papermc.paper.registry.TypedKey; ++import java.util.Collection; ++import org.checkerframework.checker.nullness.qual.NonNull; ++import org.jetbrains.annotations.ApiStatus; ++import org.jetbrains.annotations.Contract; ++import org.jetbrains.annotations.Unmodifiable; ++ ++/** ++ * A collection of anonymous values relating to a registry. These ++ * are values of the same type as the registry, but will not be found ++ * in the registry, hence, anonymous. ++ * @param registry value type ++ */ ++@ApiStatus.Experimental ++public sealed interface RegistryValueSet extends RegistrySet permits RegistryValueSetImpl { ++ ++ @Override ++ default int size() { ++ return this.values().size(); ++ } ++ ++ /** ++ * {@inheritDoc} ++ *

Will always return false because these are anonymous values

++ */ ++ @Contract("_ -> false") ++ @Override ++ default boolean contains(final @NonNull TypedKey valueKey) { ++ return false; ++ } ++ ++ @Override ++ default @NonNull @Unmodifiable Collection resolve() { ++ return this.values(); ++ } ++ ++ /** ++ * Get the collection of values in this direct set. ++ * ++ * @return the values ++ */ ++ @NonNull @Unmodifiable Collection values(); ++} +diff --git a/src/main/java/io/papermc/paper/registry/set/RegistryValueSetImpl.java b/src/main/java/io/papermc/paper/registry/set/RegistryValueSetImpl.java +new file mode 100644 +index 0000000000000000000000000000000000000000..4ce5b26a1fcaae7b28ac8ed3c25014b66c266318 +--- /dev/null ++++ b/src/main/java/io/papermc/paper/registry/set/RegistryValueSetImpl.java +@@ -0,0 +1,18 @@ ++package io.papermc.paper.registry.set; ++ ++import com.google.common.collect.Lists; ++import io.papermc.paper.registry.RegistryKey; ++import java.util.List; ++import org.jetbrains.annotations.ApiStatus; ++ ++@ApiStatus.Internal ++record RegistryValueSetImpl(RegistryKey registryKey, List values) implements RegistryValueSet { ++ ++ RegistryValueSetImpl { ++ values = List.copyOf(values); ++ } ++ ++ static RegistryValueSet create(final RegistryKey registryKey, final Iterable values) { ++ return new RegistryValueSetImpl<>(registryKey, Lists.newArrayList(values)); ++ } ++} +diff --git a/src/main/java/io/papermc/paper/registry/tag/Tag.java b/src/main/java/io/papermc/paper/registry/tag/Tag.java +new file mode 100644 +index 0000000000000000000000000000000000000000..5fce47a5a8a46f9f144d9adb4257a00a4ea84315 +--- /dev/null ++++ b/src/main/java/io/papermc/paper/registry/tag/Tag.java +@@ -0,0 +1,24 @@ ++package io.papermc.paper.registry.tag; ++ ++import io.papermc.paper.registry.set.RegistryKeySet; ++import org.checkerframework.checker.nullness.qual.NonNull; ++import org.jetbrains.annotations.ApiStatus; ++ ++/** ++ * A named {@link RegistryKeySet} which are created ++ * via the datapack tag system. ++ * ++ * @param ++ * @see org.bukkit.Tag ++ * @see org.bukkit.Registry#getTag(TagKey) ++ */ ++@ApiStatus.Experimental ++public interface Tag extends RegistryKeySet { ++ ++ /** ++ * Get the identifier for this named set. ++ * ++ * @return the tag key identifier ++ */ ++ @NonNull TagKey tagKey(); ++} +diff --git a/src/main/java/io/papermc/paper/registry/tag/TagKey.java b/src/main/java/io/papermc/paper/registry/tag/TagKey.java +new file mode 100644 +index 0000000000000000000000000000000000000000..a49d328e95f7fda6567ee6c4f5f1878a2c187277 +--- /dev/null ++++ b/src/main/java/io/papermc/paper/registry/tag/TagKey.java +@@ -0,0 +1,32 @@ ++package io.papermc.paper.registry.tag; ++ ++import io.papermc.paper.registry.RegistryKey; ++import net.kyori.adventure.key.Key; ++import net.kyori.adventure.key.Keyed; ++import org.checkerframework.checker.nullness.qual.NonNull; ++import org.jetbrains.annotations.ApiStatus; ++import org.jetbrains.annotations.Contract; ++ ++@ApiStatus.Experimental ++public sealed interface TagKey extends Keyed permits TagKeyImpl { ++ ++ /** ++ * Creates a new tag key for a registry. ++ * ++ * @param registryKey the registry for the tag ++ * @param key the specific key for the tag ++ * @return a new tag key ++ * @param the registry value type ++ */ ++ @Contract(value = "_, _ -> new", pure = true) ++ static @NonNull TagKey create(final @NonNull RegistryKey registryKey, final @NonNull Key key) { ++ return new TagKeyImpl<>(registryKey, key); ++ } ++ ++ /** ++ * Get the registry key for this tag key. ++ * ++ * @return the registry key ++ */ ++ @NonNull RegistryKey registryKey(); ++} +diff --git a/src/main/java/io/papermc/paper/registry/tag/TagKeyImpl.java b/src/main/java/io/papermc/paper/registry/tag/TagKeyImpl.java +new file mode 100644 +index 0000000000000000000000000000000000000000..11d19e339c7c62f2eb4467277552c27e4e83069c +--- /dev/null ++++ b/src/main/java/io/papermc/paper/registry/tag/TagKeyImpl.java +@@ -0,0 +1,12 @@ ++package io.papermc.paper.registry.tag; ++ ++import io.papermc.paper.registry.RegistryKey; ++import net.kyori.adventure.key.Key; ++import org.checkerframework.checker.nullness.qual.NonNull; ++import org.checkerframework.framework.qual.DefaultQualifier; ++import org.jetbrains.annotations.ApiStatus; ++ ++@ApiStatus.Internal ++@DefaultQualifier(NonNull.class) ++record TagKeyImpl(RegistryKey registryKey, Key key) implements TagKey { ++} +diff --git a/src/main/java/org/bukkit/Registry.java b/src/main/java/org/bukkit/Registry.java +index 240500771bac439156b4c5d93ff047ae45d56154..dd937b18f93987f4c481d154bb263ef194bd4dc4 100644 +--- a/src/main/java/org/bukkit/Registry.java ++++ b/src/main/java/org/bukkit/Registry.java +@@ -146,7 +146,23 @@ public interface Registry extends Iterable { + * + * @see EntityType + */ +- Registry ENTITY_TYPE = new SimpleRegistry<>(EntityType.class, (entity) -> entity != EntityType.UNKNOWN); ++ // Paper start - support tags here ++ Registry ENTITY_TYPE = new SimpleRegistry<>(EntityType.class, (entity) -> entity != EntityType.UNKNOWN) { ++ @Override ++ public boolean hasTag(final io.papermc.paper.registry.tag.@NotNull TagKey key) { ++ return Bukkit.getUnsafe().getTag(key) != null; ++ } ++ ++ @Override ++ public io.papermc.paper.registry.tag.@NotNull Tag getTag(final io.papermc.paper.registry.tag.@NotNull TagKey key) { ++ final io.papermc.paper.registry.tag.Tag tag = Bukkit.getUnsafe().getTag(key); ++ if (tag == null) { ++ throw new java.util.NoSuchElementException("No tag " + key + " found"); ++ } ++ return tag; ++ } ++ }; ++ // Paper end - support tags here + /** + * Server instruments. + * +@@ -290,7 +306,23 @@ public interface Registry extends Iterable { + * + * @see Fluid + */ +- Registry FLUID = new SimpleRegistry<>(Fluid.class); ++ // Paper start - support tags here ++ Registry FLUID = new SimpleRegistry<>(Fluid.class) { ++ @Override ++ public boolean hasTag(final io.papermc.paper.registry.tag.@NotNull TagKey key) { ++ return Bukkit.getUnsafe().getTag(key) != null; ++ } ++ ++ @Override ++ public io.papermc.paper.registry.tag.@NotNull Tag getTag(final io.papermc.paper.registry.tag.@NotNull TagKey key) { ++ final io.papermc.paper.registry.tag.Tag tag = Bukkit.getUnsafe().getTag(key); ++ if (tag == null) { ++ throw new java.util.NoSuchElementException("No tag " + key + " found"); ++ } ++ return tag; ++ } ++ }; ++ // Paper end - support tags here + /** + * Frog variants. + * +@@ -448,6 +480,30 @@ public interface Registry extends Iterable { + } + // Paper end - improve Registry + ++ // Paper start - RegistrySet API ++ /** ++ * Checks if this registry has a tag with the given key. ++ * ++ * @param key the key to check for ++ * @return true if this registry has a tag with the given key, false otherwise ++ */ ++ @ApiStatus.Experimental ++ default boolean hasTag(final io.papermc.paper.registry.tag.@NotNull TagKey key) { ++ throw new UnsupportedOperationException(this + " doesn't have tags"); ++ } ++ ++ /** ++ * Gets the named registry set (tag) for the given key. ++ * ++ * @param key the key to get the tag for ++ * @return the tag for the key ++ */ ++ @ApiStatus.Experimental ++ default @NotNull io.papermc.paper.registry.tag.Tag getTag(final io.papermc.paper.registry.tag.@NotNull TagKey key) { ++ throw new UnsupportedOperationException(this + " doesn't have tags"); ++ } ++ // Paper end - RegistrySet API ++ + /** + * Returns a new stream, which contains all registry items, which are registered to the registry. + * +@@ -477,7 +533,7 @@ public interface Registry extends Iterable { + return (namespacedKey != null) ? get(namespacedKey) : null; + } + +- static final class SimpleRegistry & Keyed> implements Registry { ++ static class SimpleRegistry & Keyed> implements Registry { // Paper - not final + + private final Class type; + private final Map map; +diff --git a/src/main/java/org/bukkit/UnsafeValues.java b/src/main/java/org/bukkit/UnsafeValues.java +index 0e9ccfee7a03d341e7c4d271f53b4ed168b404ef..7332034bb1753f48f7904dafab1ef4b3ee117ea3 100644 +--- a/src/main/java/org/bukkit/UnsafeValues.java ++++ b/src/main/java/org/bukkit/UnsafeValues.java +@@ -275,4 +275,6 @@ public interface UnsafeValues { + // Paper end - lifecycle event API + + @NotNull java.util.List computeTooltipLines(@NotNull ItemStack itemStack, @NotNull io.papermc.paper.inventory.tooltip.TooltipContext tooltipContext, @Nullable org.bukkit.entity.Player player); // Paper - expose itemstack tooltip lines ++ ++ io.papermc.paper.registry.tag.@Nullable Tag getTag(io.papermc.paper.registry.tag.@NotNull TagKey tagKey); // Paper - hack to get tags for non-server backed registries + } diff --git a/patches/server/0991-Registry-Modification-API.patch b/patches/server/0991-Registry-Modification-API.patch deleted file mode 100644 index c770d38c3a..0000000000 --- a/patches/server/0991-Registry-Modification-API.patch +++ /dev/null @@ -1,864 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: Jake Potrebic -Date: Mon, 27 Feb 2023 18:28:39 -0800 -Subject: [PATCH] Registry Modification API - -== AT == -public net.minecraft.core.MappedRegistry validateWrite(Lnet/minecraft/resources/ResourceKey;)V - -diff --git a/src/main/java/io/papermc/paper/registry/PaperRegistries.java b/src/main/java/io/papermc/paper/registry/PaperRegistries.java -index 40ac461d2f1906059377c77229612f540e827d75..7a2fb53ab280893b1c9c886ccb3480b695343cbf 100644 ---- a/src/main/java/io/papermc/paper/registry/PaperRegistries.java -+++ b/src/main/java/io/papermc/paper/registry/PaperRegistries.java -@@ -44,6 +44,7 @@ import org.checkerframework.framework.qual.DefaultQualifier; - - import static io.papermc.paper.registry.entry.RegistryEntry.apiOnly; - import static io.papermc.paper.registry.entry.RegistryEntry.entry; -+import static io.papermc.paper.registry.entry.RegistryEntry.writable; - - @DefaultQualifier(NonNull.class) - public final class PaperRegistries { -diff --git a/src/main/java/io/papermc/paper/registry/PaperRegistryAccess.java b/src/main/java/io/papermc/paper/registry/PaperRegistryAccess.java -index d591e3a2e19d5358a0d25a5a681368943622d231..f05ebf453406a924da3de6fb250f4793a1b3c612 100644 ---- a/src/main/java/io/papermc/paper/registry/PaperRegistryAccess.java -+++ b/src/main/java/io/papermc/paper/registry/PaperRegistryAccess.java -@@ -80,6 +80,14 @@ public class PaperRegistryAccess implements RegistryAccess { - return possiblyUnwrap(registryHolder.get()); - } - -+ public > WritableCraftRegistry getWritableRegistry(final RegistryKey key) { -+ final Registry registry = this.getRegistry(key); -+ if (registry instanceof WritableCraftRegistry) { -+ return (WritableCraftRegistry) registry; -+ } -+ throw new IllegalArgumentException(key + " does not point to a writable registry"); -+ } -+ - private static Registry possiblyUnwrap(final Registry registry) { - if (registry instanceof final DelayedRegistry delayedRegistry) { // if not coming from legacy, unwrap the delayed registry - return delayedRegistry.delegate(); -diff --git a/src/main/java/io/papermc/paper/registry/PaperRegistryBuilder.java b/src/main/java/io/papermc/paper/registry/PaperRegistryBuilder.java -new file mode 100644 -index 0000000000000000000000000000000000000000..4cf32102a134ebef67d3893cfd24bf0add321eb9 ---- /dev/null -+++ b/src/main/java/io/papermc/paper/registry/PaperRegistryBuilder.java -@@ -0,0 +1,24 @@ -+package io.papermc.paper.registry; -+ -+import org.checkerframework.checker.nullness.qual.Nullable; -+ -+public interface PaperRegistryBuilder extends RegistryBuilder { -+ -+ M build(); -+ -+ @FunctionalInterface -+ interface Filler> { -+ -+ B fill(final TypedKey key, final @Nullable M nms); -+ -+ default Factory asFactory() { -+ return key -> this.fill(key, null); -+ } -+ } -+ -+ @FunctionalInterface -+ interface Factory> { -+ -+ B create(final TypedKey key); -+ } -+} -diff --git a/src/main/java/io/papermc/paper/registry/PaperRegistryListenerManager.java b/src/main/java/io/papermc/paper/registry/PaperRegistryListenerManager.java -new file mode 100644 -index 0000000000000000000000000000000000000000..e2605a9324b9dc91cd910e4bb974d5a911b58b1f ---- /dev/null -+++ b/src/main/java/io/papermc/paper/registry/PaperRegistryListenerManager.java -@@ -0,0 +1,167 @@ -+package io.papermc.paper.registry; -+ -+import com.google.common.base.Preconditions; -+import io.papermc.paper.plugin.bootstrap.BootstrapContext; -+import io.papermc.paper.plugin.entrypoint.Entrypoint; -+import io.papermc.paper.plugin.entrypoint.LaunchEntryPointHandler; -+import io.papermc.paper.plugin.lifecycle.event.LifecycleEventRunner; -+import io.papermc.paper.plugin.lifecycle.event.types.LifecycleEventType; -+import io.papermc.paper.registry.entry.RegistryEntry; -+import io.papermc.paper.registry.entry.RegistryEntryInfo; -+import io.papermc.paper.registry.event.RegistryEntryAddEventImpl; -+import io.papermc.paper.registry.event.RegistryEventMap; -+import io.papermc.paper.registry.event.RegistryEventProvider; -+import io.papermc.paper.registry.event.RegistryFreezeEvent; -+import io.papermc.paper.registry.event.RegistryFreezeEventImpl; -+import io.papermc.paper.registry.event.type.RegistryEntryAddEventType; -+import io.papermc.paper.registry.event.type.RegistryEntryAddEventTypeImpl; -+import io.papermc.paper.registry.event.type.RegistryLifecycleEventType; -+import net.kyori.adventure.key.Key; -+import net.minecraft.core.Holder; -+import net.minecraft.core.MappedRegistry; -+import net.minecraft.core.RegistrationInfo; -+import net.minecraft.core.Registry; -+import net.minecraft.core.WritableRegistry; -+import net.minecraft.resources.ResourceKey; -+import net.minecraft.resources.ResourceLocation; -+import org.checkerframework.checker.nullness.qual.Nullable; -+import org.intellij.lang.annotations.Subst; -+ -+public final class PaperRegistryListenerManager { -+ -+ public static final PaperRegistryListenerManager INSTANCE = new PaperRegistryListenerManager(); -+ -+ public final RegistryEventMap valueAddHooks = new RegistryEventMap("value add"); -+ public final RegistryEventMap freezeHooks = new RegistryEventMap("freeze"); -+ -+ private PaperRegistryListenerManager() { -+ } -+ -+ /** -+ * For {@link Registry#register(Registry, String, Object)} -+ */ -+ public M registerWithListeners(final Registry registry, final String id, final M nms) { -+ return this.registerWithListeners(registry, ResourceLocation.withDefaultNamespace(id), nms); -+ } -+ -+ /** -+ * For {@link Registry#register(Registry, ResourceLocation, Object)} -+ */ -+ public M registerWithListeners(final Registry registry, final ResourceLocation loc, final M nms) { -+ return this.registerWithListeners(registry, ResourceKey.create(registry.key(), loc), nms); -+ } -+ -+ /** -+ * For {@link Registry#register(Registry, ResourceKey, Object)} -+ */ -+ public M registerWithListeners(final Registry registry, final ResourceKey key, final M nms) { -+ return this.registerWithListeners(registry, key, nms, RegistrationInfo.BUILT_IN, PaperRegistryListenerManager::registerWithInstance); -+ } -+ -+ /** -+ * For {@link Registry#registerForHolder(Registry, ResourceLocation, Object)} -+ */ -+ public Holder.Reference registerForHolderWithListeners(final Registry registry, final ResourceLocation loc, final M nms) { -+ return this.registerForHolderWithListeners(registry, ResourceKey.create(registry.key(), loc), nms); -+ } -+ -+ /** -+ * For {@link Registry#registerForHolder(Registry, ResourceKey, Object)} -+ */ -+ public Holder.Reference registerForHolderWithListeners(final Registry registry, final ResourceKey key, final M nms) { -+ return this.registerWithListeners(registry, key, nms, RegistrationInfo.BUILT_IN, WritableRegistry::register); -+ } -+ -+ public > void registerWithListeners( -+ final Registry registry, -+ final ResourceKey key, -+ final M nms, -+ final RegistrationInfo registrationInfo -+ ) { -+ this.registerWithListeners(registry, key, nms, registrationInfo, WritableRegistry::register); -+ } -+ -+ public , R> R registerWithListeners( -+ final Registry registry, -+ final ResourceKey key, -+ final M nms, -+ final RegistrationInfo registrationInfo, -+ final RegisterMethod registerMethod -+ ) { -+ Preconditions.checkState(LaunchEntryPointHandler.INSTANCE.hasEntered(Entrypoint.BOOTSTRAPPER), registry.key() + " tried to run modification listeners before bootstrappers have been called"); // verify that bootstrappers have been called -+ final @Nullable RegistryEntryInfo entry = PaperRegistries.getEntry(registry.key()); -+ if (!(entry instanceof RegistryEntry.Modifiable) || !this.valueAddHooks.hasHooks(entry.apiKey())) { -+ return registerMethod.register((WritableRegistry) registry, key, nms, registrationInfo); -+ } -+ final RegistryEntry.Modifiable modifiableEntry = (RegistryEntry.Modifiable) entry; -+ @SuppressWarnings("PatternValidation") final TypedKey typedKey = TypedKey.create(entry.apiKey(), Key.key(key.location().getNamespace(), key.location().getPath())); -+ final B builder = modifiableEntry.fillBuilder(typedKey, nms); -+ return this.registerWithListeners(registry, modifiableEntry, key, nms, builder, registrationInfo, registerMethod); -+ } -+ -+ public > void registerWithListeners( -+ final Registry registry, -+ final RegistryEntry.Modifiable entry, -+ final ResourceKey key, -+ final @Nullable M oldNms, -+ final B builder, -+ final RegistrationInfo registrationInfo -+ ) { -+ this.registerWithListeners(registry, entry, key, oldNms, builder, registrationInfo, WritableRegistry::register); -+ } -+ -+ public , R> R registerWithListeners( -+ final Registry registry, -+ final RegistryEntry.Modifiable entry, -+ final ResourceKey key, -+ final @Nullable M oldNms, -+ final B builder, -+ final RegistrationInfo registrationInfo, -+ final RegisterMethod registerMethod -+ ) { -+ @Subst("namespace:key") final ResourceLocation beingAdded = key.location(); -+ @SuppressWarnings("PatternValidation") final TypedKey typedKey = TypedKey.create(entry.apiKey(), Key.key(beingAdded.getNamespace(), beingAdded.getPath())); -+ final RegistryEntryAddEventImpl event = entry.createEntryAddEvent(typedKey, builder); -+ LifecycleEventRunner.INSTANCE.callEvent(this.valueAddHooks.getHook(entry.apiKey()), event); -+ if (oldNms != null) { -+ ((MappedRegistry) registry).clearIntrusiveHolder(oldNms); -+ } -+ final M newNms = event.builder().build(); -+ return registerMethod.register((WritableRegistry) registry, key, newNms, registrationInfo); -+ } -+ -+ private static M registerWithInstance(final WritableRegistry writableRegistry, final ResourceKey key, final M value, final RegistrationInfo registrationInfo) { -+ writableRegistry.register(key, value, registrationInfo); -+ return value; -+ } -+ -+ @FunctionalInterface -+ public interface RegisterMethod { -+ -+ R register(WritableRegistry writableRegistry, ResourceKey key, M value, RegistrationInfo registrationInfo); -+ } -+ -+ public > void runFreezeListeners(final ResourceKey> resourceKey) { -+ final @Nullable RegistryEntryInfo entry = PaperRegistries.getEntry(resourceKey); -+ if (!(entry instanceof RegistryEntry.Writable) || !this.freezeHooks.hasHooks(entry.apiKey())) { -+ return; -+ } -+ final RegistryEntry.Writable writableEntry = (RegistryEntry.Writable) entry; -+ final RegistryFreezeEventImpl event = writableEntry.createFreezeEvent(PaperRegistryAccess.instance().getWritableRegistry(entry.apiKey())); -+ LifecycleEventRunner.INSTANCE.callEvent(this.freezeHooks.getHook(entry.apiKey()), event); -+ } -+ -+ public > RegistryEntryAddEventType getRegistryValueAddEventType(final RegistryEventProvider type) { -+ if (!(PaperRegistries.getEntry(type.registryKey()) instanceof RegistryEntry.Modifiable)) { -+ throw new IllegalArgumentException(type.registryKey() + " does not support RegistryAdditionEvent"); -+ } -+ return this.valueAddHooks.getOrCreate(type, RegistryEntryAddEventTypeImpl::new); -+ } -+ -+ public > LifecycleEventType.Prioritizable> getRegistryFreezeEventType(final RegistryEventProvider type) { -+ if (!(PaperRegistries.getEntry(type.registryKey()) instanceof RegistryEntry.Writable)) { -+ throw new IllegalArgumentException(type.registryKey() + " does not support RegistryPreFreezeEvent"); -+ } -+ return this.freezeHooks.getOrCreate(type, RegistryLifecycleEventType::new); -+ } -+} -diff --git a/src/main/java/io/papermc/paper/registry/WritableCraftRegistry.java b/src/main/java/io/papermc/paper/registry/WritableCraftRegistry.java -new file mode 100644 -index 0000000000000000000000000000000000000000..aff4895d5add72e22ae9f723b77843435ff044aa ---- /dev/null -+++ b/src/main/java/io/papermc/paper/registry/WritableCraftRegistry.java -@@ -0,0 +1,85 @@ -+package io.papermc.paper.registry; -+ -+import com.mojang.serialization.Lifecycle; -+import io.papermc.paper.adventure.PaperAdventure; -+import io.papermc.paper.registry.entry.RegistryEntry; -+import io.papermc.paper.registry.event.WritableRegistry; -+import java.util.Optional; -+import java.util.function.BiFunction; -+import java.util.function.Consumer; -+import net.minecraft.core.MappedRegistry; -+import net.minecraft.core.RegistrationInfo; -+import net.minecraft.resources.ResourceKey; -+import org.bukkit.Keyed; -+import org.bukkit.NamespacedKey; -+import org.bukkit.craftbukkit.CraftRegistry; -+import org.bukkit.craftbukkit.util.ApiVersion; -+import org.checkerframework.checker.nullness.qual.Nullable; -+ -+public class WritableCraftRegistry> extends CraftRegistry { -+ -+ private static final RegistrationInfo FROM_PLUGIN = new RegistrationInfo(Optional.empty(), Lifecycle.experimental()); -+ -+ private final RegistryEntry.BuilderHolder entry; -+ private final MappedRegistry registry; -+ public final WritableRegistry apiWritableRegistry = new ApiWritableRegistry(); -+ private final PaperRegistryBuilder.Factory builderFactory; -+ private final BiFunction minecraftToBukkit; -+ -+ public WritableCraftRegistry( -+ final RegistryEntry.BuilderHolder entry, -+ final Class classToPreload, -+ final MappedRegistry registry, -+ final BiFunction serializationUpdater, -+ final PaperRegistryBuilder.Factory builderFactory, -+ final BiFunction minecraftToBukkit -+ ) { -+ super(classToPreload, registry, null, serializationUpdater); -+ this.entry = entry; -+ this.registry = registry; -+ this.builderFactory = builderFactory; -+ this.minecraftToBukkit = minecraftToBukkit; -+ } -+ -+ public void register(final TypedKey key, final Consumer value) { -+ final ResourceKey resourceKey = ResourceKey.create(this.registry.key(), PaperAdventure.asVanilla(key.key())); -+ this.registry.validateWrite(resourceKey); -+ final B builder = this.newBuilder(key); -+ value.accept(builder); -+ if (this.entry instanceof final RegistryEntry.Modifiable modifiable && PaperRegistryListenerManager.INSTANCE.valueAddHooks.hasHooks(this.entry.apiKey())) { -+ PaperRegistryListenerManager.INSTANCE.registerWithListeners( -+ this.registry, -+ modifiable, -+ resourceKey, -+ null, -+ builder, -+ FROM_PLUGIN -+ ); -+ } else { -+ this.registry.register(resourceKey, builder.build(), FROM_PLUGIN); -+ } -+ } -+ -+ @Override -+ public final @Nullable T createBukkit(final NamespacedKey namespacedKey, final @Nullable M minecraft) { -+ if (minecraft == null) { -+ return null; -+ } -+ return this.minecraftToBukkit(namespacedKey, minecraft); -+ } -+ -+ public T minecraftToBukkit(final NamespacedKey namespacedKey, final M minecraft) { -+ return this.minecraftToBukkit.apply(namespacedKey, minecraft); -+ } -+ -+ protected B newBuilder(final TypedKey key) { -+ return this.builderFactory.create(key); -+ } -+ -+ public class ApiWritableRegistry implements WritableRegistry { -+ @Override -+ public void register(final TypedKey key, final Consumer value) { -+ WritableCraftRegistry.this.register(key, value); -+ } -+ } -+} -diff --git a/src/main/java/io/papermc/paper/registry/entry/AddableRegistryEntry.java b/src/main/java/io/papermc/paper/registry/entry/AddableRegistryEntry.java -new file mode 100644 -index 0000000000000000000000000000000000000000..a0f24d396e3a258be1978b2baa3f8e07ff54538f ---- /dev/null -+++ b/src/main/java/io/papermc/paper/registry/entry/AddableRegistryEntry.java -@@ -0,0 +1,43 @@ -+package io.papermc.paper.registry.entry; -+ -+import io.papermc.paper.registry.PaperRegistryBuilder; -+import io.papermc.paper.registry.RegistryHolder; -+import io.papermc.paper.registry.RegistryKey; -+import io.papermc.paper.registry.TypedKey; -+import io.papermc.paper.registry.WritableCraftRegistry; -+import java.util.function.BiFunction; -+import net.minecraft.core.MappedRegistry; -+import net.minecraft.core.Registry; -+import net.minecraft.resources.ResourceKey; -+import org.bukkit.Keyed; -+import org.bukkit.NamespacedKey; -+ -+public class AddableRegistryEntry> extends CraftRegistryEntry implements RegistryEntry.Addable { -+ -+ private final PaperRegistryBuilder.Filler builderFiller; -+ -+ protected AddableRegistryEntry( -+ final ResourceKey> mcKey, -+ final RegistryKey apiKey, -+ final Class classToPreload, -+ final BiFunction minecraftToBukkit, -+ final PaperRegistryBuilder.Filler builderFiller -+ ) { -+ super(mcKey, apiKey, classToPreload, minecraftToBukkit); -+ this.builderFiller = builderFiller; -+ } -+ -+ private WritableCraftRegistry createRegistry(final Registry registry) { -+ return new WritableCraftRegistry<>(this, this.classToPreload, (MappedRegistry) registry, this.updater, this.builderFiller.asFactory(), this.minecraftToBukkit); -+ } -+ -+ @Override -+ public RegistryHolder createRegistryHolder(final Registry nmsRegistry) { -+ return new RegistryHolder.Memoized<>(() -> this.createRegistry(nmsRegistry)); -+ } -+ -+ @Override -+ public B fillBuilder(final TypedKey key, final M nms) { -+ return this.builderFiller.fill(key, nms); -+ } -+} -diff --git a/src/main/java/io/papermc/paper/registry/entry/ModifiableRegistryEntry.java b/src/main/java/io/papermc/paper/registry/entry/ModifiableRegistryEntry.java -new file mode 100644 -index 0000000000000000000000000000000000000000..df10008f6bde1047c8a13523c0a8fc01222a4e62 ---- /dev/null -+++ b/src/main/java/io/papermc/paper/registry/entry/ModifiableRegistryEntry.java -@@ -0,0 +1,31 @@ -+package io.papermc.paper.registry.entry; -+ -+import io.papermc.paper.registry.PaperRegistryBuilder; -+import io.papermc.paper.registry.RegistryKey; -+import io.papermc.paper.registry.TypedKey; -+import java.util.function.BiFunction; -+import net.minecraft.core.Registry; -+import net.minecraft.resources.ResourceKey; -+import org.bukkit.Keyed; -+import org.bukkit.NamespacedKey; -+ -+public class ModifiableRegistryEntry> extends CraftRegistryEntry implements RegistryEntry.Modifiable { -+ -+ protected final PaperRegistryBuilder.Filler builderFiller; -+ -+ protected ModifiableRegistryEntry( -+ final ResourceKey> mcKey, -+ final RegistryKey apiKey, -+ final Class toPreload, -+ final BiFunction minecraftToBukkit, -+ final PaperRegistryBuilder.Filler builderFiller -+ ) { -+ super(mcKey, apiKey, toPreload, minecraftToBukkit); -+ this.builderFiller = builderFiller; -+ } -+ -+ @Override -+ public B fillBuilder(final TypedKey key, final M nms) { -+ return this.builderFiller.fill(key, nms); -+ } -+} -diff --git a/src/main/java/io/papermc/paper/registry/entry/RegistryEntry.java b/src/main/java/io/papermc/paper/registry/entry/RegistryEntry.java -index 15991bf13894d850f360a520d1815711d25973ec..c49170d469dca809dc42421168d14e57e24d734b 100644 ---- a/src/main/java/io/papermc/paper/registry/entry/RegistryEntry.java -+++ b/src/main/java/io/papermc/paper/registry/entry/RegistryEntry.java -@@ -1,7 +1,12 @@ - package io.papermc.paper.registry.entry; - -+import io.papermc.paper.registry.PaperRegistryBuilder; - import io.papermc.paper.registry.RegistryHolder; - import io.papermc.paper.registry.RegistryKey; -+import io.papermc.paper.registry.TypedKey; -+import io.papermc.paper.registry.WritableCraftRegistry; -+import io.papermc.paper.registry.event.RegistryEntryAddEventImpl; -+import io.papermc.paper.registry.event.RegistryFreezeEventImpl; - import io.papermc.paper.registry.legacy.DelayedRegistryEntry; - import java.util.function.BiFunction; - import java.util.function.Supplier; -@@ -32,6 +37,37 @@ public interface RegistryEntry extends RegistryEntryInfo(this); - } - -+ interface BuilderHolder> extends RegistryEntryInfo { -+ -+ B fillBuilder(TypedKey key, M nms); -+ } -+ -+ /** -+ * Can mutate values being added to the registry -+ */ -+ interface Modifiable> extends BuilderHolder { -+ -+ default RegistryEntryAddEventImpl createEntryAddEvent(final TypedKey key, final B initialBuilder) { -+ return new RegistryEntryAddEventImpl<>(key, initialBuilder, this.apiKey()); -+ } -+ } -+ -+ /** -+ * Can only add new values to the registry, not modify any values. -+ */ -+ interface Addable> extends BuilderHolder { // TODO remove Keyed -+ -+ default RegistryFreezeEventImpl createFreezeEvent(final WritableCraftRegistry writableRegistry) { -+ return new RegistryFreezeEventImpl<>(this.apiKey(), writableRegistry.apiWritableRegistry); -+ } -+ } -+ -+ /** -+ * Can mutate values and add new values. -+ */ -+ interface Writable> extends Modifiable, Addable { // TODO remove Keyed -+ } -+ - static RegistryEntry entry( - final ResourceKey> mcKey, - final RegistryKey apiKey, -@@ -48,4 +84,24 @@ public interface RegistryEntry extends RegistryEntryInfo(mcKey, apiKey, apiRegistrySupplier); - } -+ -+ static > RegistryEntry modifiable( -+ final ResourceKey> mcKey, -+ final RegistryKey apiKey, -+ final Class toPreload, -+ final BiFunction minecraftToBukkit, -+ final PaperRegistryBuilder.Filler filler -+ ) { -+ return new ModifiableRegistryEntry<>(mcKey, apiKey, toPreload, minecraftToBukkit, filler); -+ } -+ -+ static > RegistryEntry writable( -+ final ResourceKey> mcKey, -+ final RegistryKey apiKey, -+ final Class toPreload, -+ final BiFunction minecraftToBukkit, -+ final PaperRegistryBuilder.Filler filler -+ ) { -+ return new WritableRegistryEntry<>(mcKey, apiKey, toPreload, minecraftToBukkit, filler); -+ } - } -diff --git a/src/main/java/io/papermc/paper/registry/entry/WritableRegistryEntry.java b/src/main/java/io/papermc/paper/registry/entry/WritableRegistryEntry.java -new file mode 100644 -index 0000000000000000000000000000000000000000..562accce731630327d116afd1c9d559df7e386bd ---- /dev/null -+++ b/src/main/java/io/papermc/paper/registry/entry/WritableRegistryEntry.java -@@ -0,0 +1,22 @@ -+package io.papermc.paper.registry.entry; -+ -+import io.papermc.paper.registry.PaperRegistryBuilder; -+import io.papermc.paper.registry.RegistryKey; -+import java.util.function.BiFunction; -+import net.minecraft.core.Registry; -+import net.minecraft.resources.ResourceKey; -+import org.bukkit.Keyed; -+import org.bukkit.NamespacedKey; -+ -+public class WritableRegistryEntry> extends AddableRegistryEntry implements RegistryEntry.Writable { // TODO remove Keyed -+ -+ protected WritableRegistryEntry( -+ final ResourceKey> mcKey, -+ final RegistryKey apiKey, -+ final Class classToPreload, -+ final BiFunction minecraftToBukkit, -+ final PaperRegistryBuilder.Filler builderFiller -+ ) { -+ super(mcKey, apiKey, classToPreload, minecraftToBukkit, builderFiller); -+ } -+} -diff --git a/src/main/java/io/papermc/paper/registry/event/RegistryEntryAddEventImpl.java b/src/main/java/io/papermc/paper/registry/event/RegistryEntryAddEventImpl.java -new file mode 100644 -index 0000000000000000000000000000000000000000..a1d747c1a46d3aa8bcdef82bebb48f1fd760e61f ---- /dev/null -+++ b/src/main/java/io/papermc/paper/registry/event/RegistryEntryAddEventImpl.java -@@ -0,0 +1,13 @@ -+package io.papermc.paper.registry.event; -+ -+import io.papermc.paper.plugin.lifecycle.event.PaperLifecycleEvent; -+import io.papermc.paper.registry.RegistryBuilder; -+import io.papermc.paper.registry.RegistryKey; -+import io.papermc.paper.registry.TypedKey; -+ -+public record RegistryEntryAddEventImpl>( -+ TypedKey key, -+ B builder, -+ RegistryKey registryKey -+) implements RegistryEntryAddEvent, PaperLifecycleEvent { -+} -diff --git a/src/main/java/io/papermc/paper/registry/event/RegistryEventMap.java b/src/main/java/io/papermc/paper/registry/event/RegistryEventMap.java -new file mode 100644 -index 0000000000000000000000000000000000000000..f5ea23173dcbe491742c3dd051c147ef397307a0 ---- /dev/null -+++ b/src/main/java/io/papermc/paper/registry/event/RegistryEventMap.java -@@ -0,0 +1,44 @@ -+package io.papermc.paper.registry.event; -+ -+import io.papermc.paper.plugin.bootstrap.BootstrapContext; -+import io.papermc.paper.plugin.lifecycle.event.LifecycleEventRunner; -+import io.papermc.paper.plugin.lifecycle.event.types.LifecycleEventType; -+import io.papermc.paper.registry.RegistryBuilder; -+import io.papermc.paper.registry.RegistryKey; -+import java.util.HashMap; -+import java.util.Map; -+import java.util.Objects; -+import java.util.function.BiFunction; -+ -+public final class RegistryEventMap { -+ -+ private final Map, LifecycleEventType, ?>> hooks = new HashMap<>(); -+ private final String name; -+ -+ public RegistryEventMap(final String name) { -+ this.name = name; -+ } -+ -+ @SuppressWarnings("unchecked") -+ public , E extends RegistryEvent, ET extends LifecycleEventType> ET getOrCreate(final RegistryEventProvider type, final BiFunction, ? super String, ET> eventTypeCreator) { -+ final ET registerHook; -+ if (this.hooks.containsKey(type.registryKey())) { -+ registerHook = (ET) this.hooks.get(type.registryKey()); -+ } else { -+ registerHook = eventTypeCreator.apply(type, this.name); -+ LifecycleEventRunner.INSTANCE.addEventType(registerHook); -+ this.hooks.put(type.registryKey(), registerHook); -+ } -+ return registerHook; -+ } -+ -+ @SuppressWarnings("unchecked") -+ public > LifecycleEventType getHook(final RegistryKey registryKey) { -+ return (LifecycleEventType) Objects.requireNonNull(this.hooks.get(registryKey), "No hook for " + registryKey); -+ } -+ -+ public boolean hasHooks(final RegistryKey registryKey) { -+ return this.hooks.containsKey(registryKey); -+ } -+ -+} -diff --git a/src/main/java/io/papermc/paper/registry/event/RegistryEventTypeProviderImpl.java b/src/main/java/io/papermc/paper/registry/event/RegistryEventTypeProviderImpl.java -new file mode 100644 -index 0000000000000000000000000000000000000000..34c842ffa355e3c8001dd7b8551bcb49229a6391 ---- /dev/null -+++ b/src/main/java/io/papermc/paper/registry/event/RegistryEventTypeProviderImpl.java -@@ -0,0 +1,24 @@ -+package io.papermc.paper.registry.event; -+ -+import io.papermc.paper.plugin.bootstrap.BootstrapContext; -+import io.papermc.paper.plugin.lifecycle.event.types.LifecycleEventType; -+import io.papermc.paper.registry.PaperRegistryListenerManager; -+import io.papermc.paper.registry.RegistryBuilder; -+import io.papermc.paper.registry.event.type.RegistryEntryAddEventType; -+ -+public class RegistryEventTypeProviderImpl implements RegistryEventTypeProvider { -+ -+ public static RegistryEventTypeProviderImpl instance() { -+ return (RegistryEventTypeProviderImpl) RegistryEventTypeProvider.provider(); -+ } -+ -+ @Override -+ public > RegistryEntryAddEventType registryEntryAdd(final RegistryEventProvider type) { -+ return PaperRegistryListenerManager.INSTANCE.getRegistryValueAddEventType(type); -+ } -+ -+ @Override -+ public > LifecycleEventType.Prioritizable> registryFreeze(final RegistryEventProvider type) { -+ return PaperRegistryListenerManager.INSTANCE.getRegistryFreezeEventType(type); -+ } -+} -diff --git a/src/main/java/io/papermc/paper/registry/event/RegistryFreezeEventImpl.java b/src/main/java/io/papermc/paper/registry/event/RegistryFreezeEventImpl.java -new file mode 100644 -index 0000000000000000000000000000000000000000..2db5d33d0b72ec3c9ff1c3042d9246dfa4344346 ---- /dev/null -+++ b/src/main/java/io/papermc/paper/registry/event/RegistryFreezeEventImpl.java -@@ -0,0 +1,11 @@ -+package io.papermc.paper.registry.event; -+ -+import io.papermc.paper.plugin.lifecycle.event.PaperLifecycleEvent; -+import io.papermc.paper.registry.RegistryBuilder; -+import io.papermc.paper.registry.RegistryKey; -+ -+public record RegistryFreezeEventImpl>( -+ RegistryKey registryKey, -+ WritableRegistry registry -+) implements RegistryFreezeEvent, PaperLifecycleEvent { -+} -diff --git a/src/main/java/io/papermc/paper/registry/event/package-info.java b/src/main/java/io/papermc/paper/registry/event/package-info.java -new file mode 100644 -index 0000000000000000000000000000000000000000..14d2d9766b8dee763f220c397aba3ad432d02aaa ---- /dev/null -+++ b/src/main/java/io/papermc/paper/registry/event/package-info.java -@@ -0,0 +1,5 @@ -+@DefaultQualifier(NonNull.class) -+package io.papermc.paper.registry.event; -+ -+import org.checkerframework.checker.nullness.qual.NonNull; -+import org.checkerframework.framework.qual.DefaultQualifier; -diff --git a/src/main/java/io/papermc/paper/registry/event/type/RegistryEntryAddEventTypeImpl.java b/src/main/java/io/papermc/paper/registry/event/type/RegistryEntryAddEventTypeImpl.java -new file mode 100644 -index 0000000000000000000000000000000000000000..32303ea9b3da736cbe26d06e57f5dcc3aa32a99b ---- /dev/null -+++ b/src/main/java/io/papermc/paper/registry/event/type/RegistryEntryAddEventTypeImpl.java -@@ -0,0 +1,32 @@ -+package io.papermc.paper.registry.event.type; -+ -+import io.papermc.paper.plugin.bootstrap.BootstrapContext; -+import io.papermc.paper.plugin.lifecycle.event.handler.LifecycleEventHandler; -+import io.papermc.paper.plugin.lifecycle.event.types.PrioritizableLifecycleEventType; -+import io.papermc.paper.registry.RegistryBuilder; -+import io.papermc.paper.registry.event.RegistryEntryAddEvent; -+import io.papermc.paper.registry.event.RegistryEventProvider; -+import java.util.function.Consumer; -+import java.util.function.Predicate; -+ -+public class RegistryEntryAddEventTypeImpl> extends PrioritizableLifecycleEventType, RegistryEntryAddConfiguration> implements RegistryEntryAddEventType { -+ -+ public RegistryEntryAddEventTypeImpl(final RegistryEventProvider type, final String eventName) { -+ super(type.registryKey() + " / " + eventName, BootstrapContext.class); -+ } -+ -+ @Override -+ public RegistryEntryAddConfiguration newHandler(final LifecycleEventHandler> handler) { -+ return new RegistryEntryAddHandlerConfiguration<>(handler, this); -+ } -+ -+ @Override -+ public void forEachHandler(final RegistryEntryAddEvent event, final Consumer>> consumer, final Predicate>> predicate) { -+ super.forEachHandler(event, consumer, predicate.and(handler -> this.matchesTarget(event, handler))); -+ } -+ -+ private boolean matchesTarget(final RegistryEntryAddEvent event, final RegisteredHandler> handler) { -+ final RegistryEntryAddHandlerConfiguration config = (RegistryEntryAddHandlerConfiguration) handler.config(); -+ return config.target() == null || event.key().equals(config.target()); -+ } -+} -diff --git a/src/main/java/io/papermc/paper/registry/event/type/RegistryEntryAddHandlerConfiguration.java b/src/main/java/io/papermc/paper/registry/event/type/RegistryEntryAddHandlerConfiguration.java -new file mode 100644 -index 0000000000000000000000000000000000000000..53df2dd1a9e1cef90bd8504c717b1cc6374b6f4e ---- /dev/null -+++ b/src/main/java/io/papermc/paper/registry/event/type/RegistryEntryAddHandlerConfiguration.java -@@ -0,0 +1,39 @@ -+package io.papermc.paper.registry.event.type; -+ -+import io.papermc.paper.plugin.bootstrap.BootstrapContext; -+import io.papermc.paper.plugin.lifecycle.event.handler.LifecycleEventHandler; -+import io.papermc.paper.plugin.lifecycle.event.handler.configuration.PrioritizedLifecycleEventHandlerConfigurationImpl; -+import io.papermc.paper.plugin.lifecycle.event.types.AbstractLifecycleEventType; -+import io.papermc.paper.registry.RegistryBuilder; -+import io.papermc.paper.registry.TypedKey; -+import io.papermc.paper.registry.event.RegistryEntryAddEvent; -+import org.checkerframework.checker.nullness.qual.Nullable; -+ -+public class RegistryEntryAddHandlerConfiguration> extends PrioritizedLifecycleEventHandlerConfigurationImpl> implements RegistryEntryAddConfiguration { -+ -+ private @Nullable TypedKey target; -+ -+ public RegistryEntryAddHandlerConfiguration(final LifecycleEventHandler> handler, final AbstractLifecycleEventType, ?> eventType) { -+ super(handler, eventType); -+ } -+ -+ public @Nullable TypedKey target() { -+ return this.target; -+ } -+ -+ @Override -+ public RegistryEntryAddConfiguration onlyFor(final TypedKey key) { -+ this.target = key; -+ return this; -+ } -+ -+ @Override -+ public RegistryEntryAddConfiguration priority(final int priority) { -+ return (RegistryEntryAddConfiguration) super.priority(priority); -+ } -+ -+ @Override -+ public RegistryEntryAddConfiguration monitor() { -+ return (RegistryEntryAddConfiguration) super.monitor(); -+ } -+} -diff --git a/src/main/java/io/papermc/paper/registry/event/type/RegistryLifecycleEventType.java b/src/main/java/io/papermc/paper/registry/event/type/RegistryLifecycleEventType.java -new file mode 100644 -index 0000000000000000000000000000000000000000..dcc0f6b337840a78d38abdf2eb3f4bbd1676f58f ---- /dev/null -+++ b/src/main/java/io/papermc/paper/registry/event/type/RegistryLifecycleEventType.java -@@ -0,0 +1,14 @@ -+package io.papermc.paper.registry.event.type; -+ -+import io.papermc.paper.plugin.bootstrap.BootstrapContext; -+import io.papermc.paper.plugin.lifecycle.event.types.PrioritizableLifecycleEventType; -+import io.papermc.paper.registry.RegistryBuilder; -+import io.papermc.paper.registry.event.RegistryEvent; -+import io.papermc.paper.registry.event.RegistryEventProvider; -+ -+public final class RegistryLifecycleEventType, E extends RegistryEvent> extends PrioritizableLifecycleEventType.Simple { -+ -+ public RegistryLifecycleEventType(final RegistryEventProvider type, final String eventName) { -+ super(type.registryKey() + " / " + eventName, BootstrapContext.class); -+ } -+} -diff --git a/src/main/java/io/papermc/paper/registry/package-info.java b/src/main/java/io/papermc/paper/registry/package-info.java -new file mode 100644 -index 0000000000000000000000000000000000000000..0b80179ff90e085568d7ceafd9b17511789dc99b ---- /dev/null -+++ b/src/main/java/io/papermc/paper/registry/package-info.java -@@ -0,0 +1,5 @@ -+@DefaultQualifier(NonNull.class) -+package io.papermc.paper.registry; -+ -+import org.checkerframework.checker.nullness.qual.NonNull; -+import org.checkerframework.framework.qual.DefaultQualifier; -diff --git a/src/main/java/net/minecraft/core/MappedRegistry.java b/src/main/java/net/minecraft/core/MappedRegistry.java -index edbbafd1705345282e5e6251eb71bfde5793b7d4..f22d22ebcedcc9c20225677844c86a1ad27c4211 100644 ---- a/src/main/java/net/minecraft/core/MappedRegistry.java -+++ b/src/main/java/net/minecraft/core/MappedRegistry.java -@@ -441,4 +441,12 @@ public class MappedRegistry implements WritableRegistry { - public HolderLookup.RegistryLookup asLookup() { - return this.lookup; - } -+ // Paper start -+ // used to clear intrusive holders from GameEvent, Item, Block, EntityType, and Fluid from unused instances of those types -+ public void clearIntrusiveHolder(final T instance) { -+ if (this.unregisteredIntrusiveHolders != null) { -+ this.unregisteredIntrusiveHolders.remove(instance); -+ } -+ } -+ // Paper end - } -diff --git a/src/main/java/net/minecraft/core/registries/BuiltInRegistries.java b/src/main/java/net/minecraft/core/registries/BuiltInRegistries.java -index 44b7927081b476813505cab6b3a2da2ec2942c54..c96bcd815ec9bf76625b5bedef461da49d7240ce 100644 ---- a/src/main/java/net/minecraft/core/registries/BuiltInRegistries.java -+++ b/src/main/java/net/minecraft/core/registries/BuiltInRegistries.java -@@ -328,6 +328,7 @@ public class BuiltInRegistries { - } - public static void bootStrap(Runnable runnable) { - // Paper end -+ REGISTRY.freeze(); // Paper - freeze main registry early - createContents(); - runnable.run(); // Paper - freeze(); -@@ -346,6 +347,7 @@ public class BuiltInRegistries { - REGISTRY.freeze(); - - for (Registry registry : REGISTRY) { -+ io.papermc.paper.registry.PaperRegistryListenerManager.INSTANCE.runFreezeListeners(registry.key()); // Paper - registry.freeze(); - } - } -diff --git a/src/main/java/net/minecraft/resources/RegistryDataLoader.java b/src/main/java/net/minecraft/resources/RegistryDataLoader.java -index abadf4abe08dc3bb6612b42cbb3f7df3ffa28ce9..56d8dcf2f3fd042ed1e7ed01a0ce5d90c89ee502 100644 ---- a/src/main/java/net/minecraft/resources/RegistryDataLoader.java -+++ b/src/main/java/net/minecraft/resources/RegistryDataLoader.java -@@ -136,6 +136,7 @@ public class RegistryDataLoader { - list.forEach(loader -> loadable.apply((RegistryDataLoader.Loader)loader, registryInfoLookup)); - list.forEach(loader -> { - Registry registry = loader.registry(); -+ io.papermc.paper.registry.PaperRegistryListenerManager.INSTANCE.runFreezeListeners(loader.registry.key()); // Paper - run pre-freeze listeners - - try { - registry.freeze(); -@@ -199,7 +200,7 @@ public class RegistryDataLoader { - 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); // Paper - register with listeners - } - } - -diff --git a/src/main/java/net/minecraft/server/ReloadableServerRegistries.java b/src/main/java/net/minecraft/server/ReloadableServerRegistries.java -index 397bdacab9517354875ebc0bc68d35059b3c318b..705fe42b52414fbac14ec107fda5ad0989a5a115 100644 ---- a/src/main/java/net/minecraft/server/ReloadableServerRegistries.java -+++ b/src/main/java/net/minecraft/server/ReloadableServerRegistries.java -@@ -66,7 +66,7 @@ public class ReloadableServerRegistries { - SimpleJsonResourceReloadListener.scanDirectory(resourceManager, string, GSON, map); - map.forEach( - (id, json) -> type.deserialize(id, ops, json) -- .ifPresent(value -> writableRegistry.register(ResourceKey.create(type.registryKey(), id), (T)value, DEFAULT_REGISTRATION_INFO)) -+ .ifPresent(value -> io.papermc.paper.registry.PaperRegistryListenerManager.INSTANCE.registerWithListeners(writableRegistry, ResourceKey.create(type.registryKey(), id), value, DEFAULT_REGISTRATION_INFO)) // Paper - register with listeners - ); - return writableRegistry; - }, -diff --git a/src/main/java/org/bukkit/craftbukkit/CraftRegistry.java b/src/main/java/org/bukkit/craftbukkit/CraftRegistry.java -index d21b7e39d71c785f47f790e1ad4be33a8e8e6e51..43d686a9958cff96f5b15d93e920c8f2313aa65b 100644 ---- a/src/main/java/org/bukkit/craftbukkit/CraftRegistry.java -+++ b/src/main/java/org/bukkit/craftbukkit/CraftRegistry.java -@@ -156,11 +156,11 @@ public class CraftRegistry implements Registry { - private final Map cache = new HashMap<>(); - private final Map byValue = new java.util.IdentityHashMap<>(); // Paper - improve Registry - private final net.minecraft.core.Registry minecraftRegistry; -- private final BiFunction minecraftToBukkit; -+ private final BiFunction minecraftToBukkit; // Paper - private final BiFunction serializationUpdater; // Paper - rename to make it *clear* what it is *only* for - private boolean init; - -- public CraftRegistry(Class bukkitClass, net.minecraft.core.Registry minecraftRegistry, BiFunction minecraftToBukkit, BiFunction serializationUpdater) { // Paper - relax preload class -+ public CraftRegistry(Class bukkitClass, net.minecraft.core.Registry minecraftRegistry, BiFunction minecraftToBukkit, BiFunction serializationUpdater) { // Paper - relax preload class - this.bukkitClass = bukkitClass; - this.minecraftRegistry = minecraftRegistry; - this.minecraftToBukkit = minecraftToBukkit; -diff --git a/src/main/resources/META-INF/services/io.papermc.paper.registry.event.RegistryEventTypeProvider b/src/main/resources/META-INF/services/io.papermc.paper.registry.event.RegistryEventTypeProvider -new file mode 100644 -index 0000000000000000000000000000000000000000..8bee1a5ed877a04e4d027593df1f42cefdd824e7 ---- /dev/null -+++ b/src/main/resources/META-INF/services/io.papermc.paper.registry.event.RegistryEventTypeProvider -@@ -0,0 +1 @@ -+io.papermc.paper.registry.event.RegistryEventTypeProviderImpl diff --git a/patches/server/1001-Registry-Modification-API.patch b/patches/server/1001-Registry-Modification-API.patch new file mode 100644 index 0000000000..e139aba408 --- /dev/null +++ b/patches/server/1001-Registry-Modification-API.patch @@ -0,0 +1,852 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Jake Potrebic +Date: Mon, 27 Feb 2023 18:28:39 -0800 +Subject: [PATCH] Registry Modification API + +== AT == +public net.minecraft.server.RegistryLayer STATIC_ACCESS +public net.minecraft.core.MappedRegistry validateWrite(Lnet/minecraft/resources/ResourceKey;)V + +diff --git a/src/main/java/io/papermc/paper/registry/PaperRegistries.java b/src/main/java/io/papermc/paper/registry/PaperRegistries.java +index 40ac461d2f1906059377c77229612f540e827d75..7a2fb53ab280893b1c9c886ccb3480b695343cbf 100644 +--- a/src/main/java/io/papermc/paper/registry/PaperRegistries.java ++++ b/src/main/java/io/papermc/paper/registry/PaperRegistries.java +@@ -44,6 +44,7 @@ import org.checkerframework.framework.qual.DefaultQualifier; + + import static io.papermc.paper.registry.entry.RegistryEntry.apiOnly; + import static io.papermc.paper.registry.entry.RegistryEntry.entry; ++import static io.papermc.paper.registry.entry.RegistryEntry.writable; + + @DefaultQualifier(NonNull.class) + public final class PaperRegistries { +diff --git a/src/main/java/io/papermc/paper/registry/PaperRegistryAccess.java b/src/main/java/io/papermc/paper/registry/PaperRegistryAccess.java +index d591e3a2e19d5358a0d25a5a681368943622d231..f05ebf453406a924da3de6fb250f4793a1b3c612 100644 +--- a/src/main/java/io/papermc/paper/registry/PaperRegistryAccess.java ++++ b/src/main/java/io/papermc/paper/registry/PaperRegistryAccess.java +@@ -80,6 +80,14 @@ public class PaperRegistryAccess implements RegistryAccess { + return possiblyUnwrap(registryHolder.get()); + } + ++ public > WritableCraftRegistry getWritableRegistry(final RegistryKey key) { ++ final Registry registry = this.getRegistry(key); ++ if (registry instanceof WritableCraftRegistry) { ++ return (WritableCraftRegistry) registry; ++ } ++ throw new IllegalArgumentException(key + " does not point to a writable registry"); ++ } ++ + private static Registry possiblyUnwrap(final Registry registry) { + if (registry instanceof final DelayedRegistry delayedRegistry) { // if not coming from legacy, unwrap the delayed registry + return delayedRegistry.delegate(); +diff --git a/src/main/java/io/papermc/paper/registry/PaperRegistryBuilder.java b/src/main/java/io/papermc/paper/registry/PaperRegistryBuilder.java +new file mode 100644 +index 0000000000000000000000000000000000000000..4cf32102a134ebef67d3893cfd24bf0add321eb9 +--- /dev/null ++++ b/src/main/java/io/papermc/paper/registry/PaperRegistryBuilder.java +@@ -0,0 +1,24 @@ ++package io.papermc.paper.registry; ++ ++import org.checkerframework.checker.nullness.qual.Nullable; ++ ++public interface PaperRegistryBuilder extends RegistryBuilder { ++ ++ M build(); ++ ++ @FunctionalInterface ++ interface Filler> { ++ ++ B fill(final TypedKey key, final @Nullable M nms); ++ ++ default Factory asFactory() { ++ return key -> this.fill(key, null); ++ } ++ } ++ ++ @FunctionalInterface ++ interface Factory> { ++ ++ B create(final TypedKey key); ++ } ++} +diff --git a/src/main/java/io/papermc/paper/registry/PaperRegistryListenerManager.java b/src/main/java/io/papermc/paper/registry/PaperRegistryListenerManager.java +new file mode 100644 +index 0000000000000000000000000000000000000000..6b3ba059b4f530b9e3d1c3d6bbc033e96c6a9bc2 +--- /dev/null ++++ b/src/main/java/io/papermc/paper/registry/PaperRegistryListenerManager.java +@@ -0,0 +1,167 @@ ++package io.papermc.paper.registry; ++ ++import com.google.common.base.Preconditions; ++import io.papermc.paper.plugin.bootstrap.BootstrapContext; ++import io.papermc.paper.plugin.entrypoint.Entrypoint; ++import io.papermc.paper.plugin.entrypoint.LaunchEntryPointHandler; ++import io.papermc.paper.plugin.lifecycle.event.LifecycleEventRunner; ++import io.papermc.paper.plugin.lifecycle.event.types.LifecycleEventType; ++import io.papermc.paper.registry.entry.RegistryEntry; ++import io.papermc.paper.registry.entry.RegistryEntryInfo; ++import io.papermc.paper.registry.event.RegistryEntryAddEventImpl; ++import io.papermc.paper.registry.event.RegistryEventMap; ++import io.papermc.paper.registry.event.RegistryEventProvider; ++import io.papermc.paper.registry.event.RegistryFreezeEvent; ++import io.papermc.paper.registry.event.RegistryFreezeEventImpl; ++import io.papermc.paper.registry.event.type.RegistryEntryAddEventType; ++import io.papermc.paper.registry.event.type.RegistryEntryAddEventTypeImpl; ++import io.papermc.paper.registry.event.type.RegistryLifecycleEventType; ++import net.kyori.adventure.key.Key; ++import net.minecraft.core.Holder; ++import net.minecraft.core.MappedRegistry; ++import net.minecraft.core.RegistrationInfo; ++import net.minecraft.core.Registry; ++import net.minecraft.core.WritableRegistry; ++import net.minecraft.resources.ResourceKey; ++import net.minecraft.resources.ResourceLocation; ++import org.checkerframework.checker.nullness.qual.Nullable; ++import org.intellij.lang.annotations.Subst; ++ ++public final class PaperRegistryListenerManager { ++ ++ public static final PaperRegistryListenerManager INSTANCE = new PaperRegistryListenerManager(); ++ ++ public final RegistryEventMap valueAddHooks = new RegistryEventMap("value add"); ++ public final RegistryEventMap freezeHooks = new RegistryEventMap("freeze"); ++ ++ private PaperRegistryListenerManager() { ++ } ++ ++ /** ++ * For {@link Registry#register(Registry, String, Object)} ++ */ ++ public M registerWithListeners(final Registry registry, final String id, final M nms) { ++ return this.registerWithListeners(registry, new ResourceLocation(id), nms); ++ } ++ ++ /** ++ * For {@link Registry#register(Registry, ResourceLocation, Object)} ++ */ ++ public M registerWithListeners(final Registry registry, final ResourceLocation loc, final M nms) { ++ return this.registerWithListeners(registry, ResourceKey.create(registry.key(), loc), nms); ++ } ++ ++ /** ++ * For {@link Registry#register(Registry, ResourceKey, Object)} ++ */ ++ public M registerWithListeners(final Registry registry, final ResourceKey key, final M nms) { ++ return this.registerWithListeners(registry, key, nms, RegistrationInfo.BUILT_IN, PaperRegistryListenerManager::registerWithInstance); ++ } ++ ++ /** ++ * For {@link Registry#registerForHolder(Registry, ResourceLocation, Object)} ++ */ ++ public Holder.Reference registerForHolderWithListeners(final Registry registry, final ResourceLocation loc, final M nms) { ++ return this.registerForHolderWithListeners(registry, ResourceKey.create(registry.key(), loc), nms); ++ } ++ ++ /** ++ * For {@link Registry#registerForHolder(Registry, ResourceKey, Object)} ++ */ ++ public Holder.Reference registerForHolderWithListeners(final Registry registry, final ResourceKey key, final M nms) { ++ return this.registerWithListeners(registry, key, nms, RegistrationInfo.BUILT_IN, WritableRegistry::register); ++ } ++ ++ public > void registerWithListeners( ++ final Registry registry, ++ final ResourceKey key, ++ final M nms, ++ final RegistrationInfo registrationInfo ++ ) { ++ this.registerWithListeners(registry, key, nms, registrationInfo, WritableRegistry::register); ++ } ++ ++ public , R> R registerWithListeners( ++ final Registry registry, ++ final ResourceKey key, ++ final M nms, ++ final RegistrationInfo registrationInfo, ++ final RegisterMethod registerMethod ++ ) { ++ Preconditions.checkState(LaunchEntryPointHandler.INSTANCE.hasEntered(Entrypoint.BOOTSTRAPPER), registry.key() + " tried to run modification listeners before bootstrappers have been called"); // verify that bootstrappers have been called ++ final @Nullable RegistryEntryInfo entry = PaperRegistries.getEntry(registry.key()); ++ if (!(entry instanceof RegistryEntry.Modifiable) || !this.valueAddHooks.hasHooks(entry.apiKey())) { ++ return registerMethod.register((WritableRegistry) registry, key, nms, registrationInfo); ++ } ++ final RegistryEntry.Modifiable modifiableEntry = (RegistryEntry.Modifiable) entry; ++ @SuppressWarnings("PatternValidation") final TypedKey typedKey = TypedKey.create(entry.apiKey(), Key.key(key.location().getNamespace(), key.location().getPath())); ++ final B builder = modifiableEntry.fillBuilder(typedKey, nms); ++ return this.registerWithListeners(registry, modifiableEntry, key, nms, builder, registrationInfo, registerMethod); ++ } ++ ++ public > void registerWithListeners( ++ final Registry registry, ++ final RegistryEntry.Modifiable entry, ++ final ResourceKey key, ++ final @Nullable M oldNms, ++ final B builder, ++ final RegistrationInfo registrationInfo ++ ) { ++ this.registerWithListeners(registry, entry, key, oldNms, builder, registrationInfo, WritableRegistry::register); ++ } ++ ++ public , R> R registerWithListeners( ++ final Registry registry, ++ final RegistryEntry.Modifiable entry, ++ final ResourceKey key, ++ final @Nullable M oldNms, ++ final B builder, ++ final RegistrationInfo registrationInfo, ++ final RegisterMethod registerMethod ++ ) { ++ @Subst("namespace:key") final ResourceLocation beingAdded = key.location(); ++ @SuppressWarnings("PatternValidation") final TypedKey typedKey = TypedKey.create(entry.apiKey(), Key.key(beingAdded.getNamespace(), beingAdded.getPath())); ++ final RegistryEntryAddEventImpl event = entry.createEntryAddEvent(typedKey, builder); ++ LifecycleEventRunner.INSTANCE.callEvent(this.valueAddHooks.getHook(entry.apiKey()), event); ++ if (oldNms != null) { ++ ((MappedRegistry) registry).clearIntrusiveHolder(oldNms); ++ } ++ final M newNms = event.builder().build(); ++ return registerMethod.register((WritableRegistry) registry, key, newNms, registrationInfo); ++ } ++ ++ private static M registerWithInstance(final WritableRegistry writableRegistry, final ResourceKey key, final M value, final RegistrationInfo registrationInfo) { ++ writableRegistry.register(key, value, registrationInfo); ++ return value; ++ } ++ ++ @FunctionalInterface ++ public interface RegisterMethod { ++ ++ R register(WritableRegistry writableRegistry, ResourceKey key, M value, RegistrationInfo registrationInfo); ++ } ++ ++ public > void runFreezeListeners(final ResourceKey> resourceKey) { ++ final @Nullable RegistryEntryInfo entry = PaperRegistries.getEntry(resourceKey); ++ if (!(entry instanceof RegistryEntry.Writable) || !this.freezeHooks.hasHooks(entry.apiKey())) { ++ return; ++ } ++ final RegistryEntry.Writable writableEntry = (RegistryEntry.Writable) entry; ++ final RegistryFreezeEventImpl event = writableEntry.createFreezeEvent(PaperRegistryAccess.instance().getWritableRegistry(entry.apiKey())); ++ LifecycleEventRunner.INSTANCE.callEvent(this.freezeHooks.getHook(entry.apiKey()), event); ++ } ++ ++ public > RegistryEntryAddEventType getRegistryValueAddEventType(final RegistryEventProvider type) { ++ if (!(PaperRegistries.getEntry(type.registryKey()) instanceof RegistryEntry.Modifiable)) { ++ throw new IllegalArgumentException(type.registryKey() + " does not support RegistryAdditionEvent"); ++ } ++ return this.valueAddHooks.getOrCreate(type, RegistryEntryAddEventTypeImpl::new); ++ } ++ ++ public > LifecycleEventType.Prioritizable> getRegistryFreezeEventType(final RegistryEventProvider type) { ++ if (!(PaperRegistries.getEntry(type.registryKey()) instanceof RegistryEntry.Writable)) { ++ throw new IllegalArgumentException(type.registryKey() + " does not support RegistryPreFreezeEvent"); ++ } ++ return this.freezeHooks.getOrCreate(type, RegistryLifecycleEventType::new); ++ } ++} +diff --git a/src/main/java/io/papermc/paper/registry/WritableCraftRegistry.java b/src/main/java/io/papermc/paper/registry/WritableCraftRegistry.java +new file mode 100644 +index 0000000000000000000000000000000000000000..aff4895d5add72e22ae9f723b77843435ff044aa +--- /dev/null ++++ b/src/main/java/io/papermc/paper/registry/WritableCraftRegistry.java +@@ -0,0 +1,85 @@ ++package io.papermc.paper.registry; ++ ++import com.mojang.serialization.Lifecycle; ++import io.papermc.paper.adventure.PaperAdventure; ++import io.papermc.paper.registry.entry.RegistryEntry; ++import io.papermc.paper.registry.event.WritableRegistry; ++import java.util.Optional; ++import java.util.function.BiFunction; ++import java.util.function.Consumer; ++import net.minecraft.core.MappedRegistry; ++import net.minecraft.core.RegistrationInfo; ++import net.minecraft.resources.ResourceKey; ++import org.bukkit.Keyed; ++import org.bukkit.NamespacedKey; ++import org.bukkit.craftbukkit.CraftRegistry; ++import org.bukkit.craftbukkit.util.ApiVersion; ++import org.checkerframework.checker.nullness.qual.Nullable; ++ ++public class WritableCraftRegistry> extends CraftRegistry { ++ ++ private static final RegistrationInfo FROM_PLUGIN = new RegistrationInfo(Optional.empty(), Lifecycle.experimental()); ++ ++ private final RegistryEntry.BuilderHolder entry; ++ private final MappedRegistry registry; ++ public final WritableRegistry apiWritableRegistry = new ApiWritableRegistry(); ++ private final PaperRegistryBuilder.Factory builderFactory; ++ private final BiFunction minecraftToBukkit; ++ ++ public WritableCraftRegistry( ++ final RegistryEntry.BuilderHolder entry, ++ final Class classToPreload, ++ final MappedRegistry registry, ++ final BiFunction serializationUpdater, ++ final PaperRegistryBuilder.Factory builderFactory, ++ final BiFunction minecraftToBukkit ++ ) { ++ super(classToPreload, registry, null, serializationUpdater); ++ this.entry = entry; ++ this.registry = registry; ++ this.builderFactory = builderFactory; ++ this.minecraftToBukkit = minecraftToBukkit; ++ } ++ ++ public void register(final TypedKey key, final Consumer value) { ++ final ResourceKey resourceKey = ResourceKey.create(this.registry.key(), PaperAdventure.asVanilla(key.key())); ++ this.registry.validateWrite(resourceKey); ++ final B builder = this.newBuilder(key); ++ value.accept(builder); ++ if (this.entry instanceof final RegistryEntry.Modifiable modifiable && PaperRegistryListenerManager.INSTANCE.valueAddHooks.hasHooks(this.entry.apiKey())) { ++ PaperRegistryListenerManager.INSTANCE.registerWithListeners( ++ this.registry, ++ modifiable, ++ resourceKey, ++ null, ++ builder, ++ FROM_PLUGIN ++ ); ++ } else { ++ this.registry.register(resourceKey, builder.build(), FROM_PLUGIN); ++ } ++ } ++ ++ @Override ++ public final @Nullable T createBukkit(final NamespacedKey namespacedKey, final @Nullable M minecraft) { ++ if (minecraft == null) { ++ return null; ++ } ++ return this.minecraftToBukkit(namespacedKey, minecraft); ++ } ++ ++ public T minecraftToBukkit(final NamespacedKey namespacedKey, final M minecraft) { ++ return this.minecraftToBukkit.apply(namespacedKey, minecraft); ++ } ++ ++ protected B newBuilder(final TypedKey key) { ++ return this.builderFactory.create(key); ++ } ++ ++ public class ApiWritableRegistry implements WritableRegistry { ++ @Override ++ public void register(final TypedKey key, final Consumer value) { ++ WritableCraftRegistry.this.register(key, value); ++ } ++ } ++} +diff --git a/src/main/java/io/papermc/paper/registry/entry/AddableRegistryEntry.java b/src/main/java/io/papermc/paper/registry/entry/AddableRegistryEntry.java +new file mode 100644 +index 0000000000000000000000000000000000000000..a0f24d396e3a258be1978b2baa3f8e07ff54538f +--- /dev/null ++++ b/src/main/java/io/papermc/paper/registry/entry/AddableRegistryEntry.java +@@ -0,0 +1,43 @@ ++package io.papermc.paper.registry.entry; ++ ++import io.papermc.paper.registry.PaperRegistryBuilder; ++import io.papermc.paper.registry.RegistryHolder; ++import io.papermc.paper.registry.RegistryKey; ++import io.papermc.paper.registry.TypedKey; ++import io.papermc.paper.registry.WritableCraftRegistry; ++import java.util.function.BiFunction; ++import net.minecraft.core.MappedRegistry; ++import net.minecraft.core.Registry; ++import net.minecraft.resources.ResourceKey; ++import org.bukkit.Keyed; ++import org.bukkit.NamespacedKey; ++ ++public class AddableRegistryEntry> extends CraftRegistryEntry implements RegistryEntry.Addable { ++ ++ private final PaperRegistryBuilder.Filler builderFiller; ++ ++ protected AddableRegistryEntry( ++ final ResourceKey> mcKey, ++ final RegistryKey apiKey, ++ final Class classToPreload, ++ final BiFunction minecraftToBukkit, ++ final PaperRegistryBuilder.Filler builderFiller ++ ) { ++ super(mcKey, apiKey, classToPreload, minecraftToBukkit); ++ this.builderFiller = builderFiller; ++ } ++ ++ private WritableCraftRegistry createRegistry(final Registry registry) { ++ return new WritableCraftRegistry<>(this, this.classToPreload, (MappedRegistry) registry, this.updater, this.builderFiller.asFactory(), this.minecraftToBukkit); ++ } ++ ++ @Override ++ public RegistryHolder createRegistryHolder(final Registry nmsRegistry) { ++ return new RegistryHolder.Memoized<>(() -> this.createRegistry(nmsRegistry)); ++ } ++ ++ @Override ++ public B fillBuilder(final TypedKey key, final M nms) { ++ return this.builderFiller.fill(key, nms); ++ } ++} +diff --git a/src/main/java/io/papermc/paper/registry/entry/ModifiableRegistryEntry.java b/src/main/java/io/papermc/paper/registry/entry/ModifiableRegistryEntry.java +new file mode 100644 +index 0000000000000000000000000000000000000000..df10008f6bde1047c8a13523c0a8fc01222a4e62 +--- /dev/null ++++ b/src/main/java/io/papermc/paper/registry/entry/ModifiableRegistryEntry.java +@@ -0,0 +1,31 @@ ++package io.papermc.paper.registry.entry; ++ ++import io.papermc.paper.registry.PaperRegistryBuilder; ++import io.papermc.paper.registry.RegistryKey; ++import io.papermc.paper.registry.TypedKey; ++import java.util.function.BiFunction; ++import net.minecraft.core.Registry; ++import net.minecraft.resources.ResourceKey; ++import org.bukkit.Keyed; ++import org.bukkit.NamespacedKey; ++ ++public class ModifiableRegistryEntry> extends CraftRegistryEntry implements RegistryEntry.Modifiable { ++ ++ protected final PaperRegistryBuilder.Filler builderFiller; ++ ++ protected ModifiableRegistryEntry( ++ final ResourceKey> mcKey, ++ final RegistryKey apiKey, ++ final Class toPreload, ++ final BiFunction minecraftToBukkit, ++ final PaperRegistryBuilder.Filler builderFiller ++ ) { ++ super(mcKey, apiKey, toPreload, minecraftToBukkit); ++ this.builderFiller = builderFiller; ++ } ++ ++ @Override ++ public B fillBuilder(final TypedKey key, final M nms) { ++ return this.builderFiller.fill(key, nms); ++ } ++} +diff --git a/src/main/java/io/papermc/paper/registry/entry/RegistryEntry.java b/src/main/java/io/papermc/paper/registry/entry/RegistryEntry.java +index 15991bf13894d850f360a520d1815711d25973ec..c49170d469dca809dc42421168d14e57e24d734b 100644 +--- a/src/main/java/io/papermc/paper/registry/entry/RegistryEntry.java ++++ b/src/main/java/io/papermc/paper/registry/entry/RegistryEntry.java +@@ -1,7 +1,12 @@ + package io.papermc.paper.registry.entry; + ++import io.papermc.paper.registry.PaperRegistryBuilder; + import io.papermc.paper.registry.RegistryHolder; + import io.papermc.paper.registry.RegistryKey; ++import io.papermc.paper.registry.TypedKey; ++import io.papermc.paper.registry.WritableCraftRegistry; ++import io.papermc.paper.registry.event.RegistryEntryAddEventImpl; ++import io.papermc.paper.registry.event.RegistryFreezeEventImpl; + import io.papermc.paper.registry.legacy.DelayedRegistryEntry; + import java.util.function.BiFunction; + import java.util.function.Supplier; +@@ -32,6 +37,37 @@ public interface RegistryEntry extends RegistryEntryInfo(this); + } + ++ interface BuilderHolder> extends RegistryEntryInfo { ++ ++ B fillBuilder(TypedKey key, M nms); ++ } ++ ++ /** ++ * Can mutate values being added to the registry ++ */ ++ interface Modifiable> extends BuilderHolder { ++ ++ default RegistryEntryAddEventImpl createEntryAddEvent(final TypedKey key, final B initialBuilder) { ++ return new RegistryEntryAddEventImpl<>(key, initialBuilder, this.apiKey()); ++ } ++ } ++ ++ /** ++ * Can only add new values to the registry, not modify any values. ++ */ ++ interface Addable> extends BuilderHolder { // TODO remove Keyed ++ ++ default RegistryFreezeEventImpl createFreezeEvent(final WritableCraftRegistry writableRegistry) { ++ return new RegistryFreezeEventImpl<>(this.apiKey(), writableRegistry.apiWritableRegistry); ++ } ++ } ++ ++ /** ++ * Can mutate values and add new values. ++ */ ++ interface Writable> extends Modifiable, Addable { // TODO remove Keyed ++ } ++ + static RegistryEntry entry( + final ResourceKey> mcKey, + final RegistryKey apiKey, +@@ -48,4 +84,24 @@ public interface RegistryEntry extends RegistryEntryInfo(mcKey, apiKey, apiRegistrySupplier); + } ++ ++ static > RegistryEntry modifiable( ++ final ResourceKey> mcKey, ++ final RegistryKey apiKey, ++ final Class toPreload, ++ final BiFunction minecraftToBukkit, ++ final PaperRegistryBuilder.Filler filler ++ ) { ++ return new ModifiableRegistryEntry<>(mcKey, apiKey, toPreload, minecraftToBukkit, filler); ++ } ++ ++ static > RegistryEntry writable( ++ final ResourceKey> mcKey, ++ final RegistryKey apiKey, ++ final Class toPreload, ++ final BiFunction minecraftToBukkit, ++ final PaperRegistryBuilder.Filler filler ++ ) { ++ return new WritableRegistryEntry<>(mcKey, apiKey, toPreload, minecraftToBukkit, filler); ++ } + } +diff --git a/src/main/java/io/papermc/paper/registry/entry/WritableRegistryEntry.java b/src/main/java/io/papermc/paper/registry/entry/WritableRegistryEntry.java +new file mode 100644 +index 0000000000000000000000000000000000000000..562accce731630327d116afd1c9d559df7e386bd +--- /dev/null ++++ b/src/main/java/io/papermc/paper/registry/entry/WritableRegistryEntry.java +@@ -0,0 +1,22 @@ ++package io.papermc.paper.registry.entry; ++ ++import io.papermc.paper.registry.PaperRegistryBuilder; ++import io.papermc.paper.registry.RegistryKey; ++import java.util.function.BiFunction; ++import net.minecraft.core.Registry; ++import net.minecraft.resources.ResourceKey; ++import org.bukkit.Keyed; ++import org.bukkit.NamespacedKey; ++ ++public class WritableRegistryEntry> extends AddableRegistryEntry implements RegistryEntry.Writable { // TODO remove Keyed ++ ++ protected WritableRegistryEntry( ++ final ResourceKey> mcKey, ++ final RegistryKey apiKey, ++ final Class classToPreload, ++ final BiFunction minecraftToBukkit, ++ final PaperRegistryBuilder.Filler builderFiller ++ ) { ++ super(mcKey, apiKey, classToPreload, minecraftToBukkit, builderFiller); ++ } ++} +diff --git a/src/main/java/io/papermc/paper/registry/event/RegistryEntryAddEventImpl.java b/src/main/java/io/papermc/paper/registry/event/RegistryEntryAddEventImpl.java +new file mode 100644 +index 0000000000000000000000000000000000000000..a1d747c1a46d3aa8bcdef82bebb48f1fd760e61f +--- /dev/null ++++ b/src/main/java/io/papermc/paper/registry/event/RegistryEntryAddEventImpl.java +@@ -0,0 +1,13 @@ ++package io.papermc.paper.registry.event; ++ ++import io.papermc.paper.plugin.lifecycle.event.PaperLifecycleEvent; ++import io.papermc.paper.registry.RegistryBuilder; ++import io.papermc.paper.registry.RegistryKey; ++import io.papermc.paper.registry.TypedKey; ++ ++public record RegistryEntryAddEventImpl>( ++ TypedKey key, ++ B builder, ++ RegistryKey registryKey ++) implements RegistryEntryAddEvent, PaperLifecycleEvent { ++} +diff --git a/src/main/java/io/papermc/paper/registry/event/RegistryEventMap.java b/src/main/java/io/papermc/paper/registry/event/RegistryEventMap.java +new file mode 100644 +index 0000000000000000000000000000000000000000..f5ea23173dcbe491742c3dd051c147ef397307a0 +--- /dev/null ++++ b/src/main/java/io/papermc/paper/registry/event/RegistryEventMap.java +@@ -0,0 +1,44 @@ ++package io.papermc.paper.registry.event; ++ ++import io.papermc.paper.plugin.bootstrap.BootstrapContext; ++import io.papermc.paper.plugin.lifecycle.event.LifecycleEventRunner; ++import io.papermc.paper.plugin.lifecycle.event.types.LifecycleEventType; ++import io.papermc.paper.registry.RegistryBuilder; ++import io.papermc.paper.registry.RegistryKey; ++import java.util.HashMap; ++import java.util.Map; ++import java.util.Objects; ++import java.util.function.BiFunction; ++ ++public final class RegistryEventMap { ++ ++ private final Map, LifecycleEventType, ?>> hooks = new HashMap<>(); ++ private final String name; ++ ++ public RegistryEventMap(final String name) { ++ this.name = name; ++ } ++ ++ @SuppressWarnings("unchecked") ++ public , E extends RegistryEvent, ET extends LifecycleEventType> ET getOrCreate(final RegistryEventProvider type, final BiFunction, ? super String, ET> eventTypeCreator) { ++ final ET registerHook; ++ if (this.hooks.containsKey(type.registryKey())) { ++ registerHook = (ET) this.hooks.get(type.registryKey()); ++ } else { ++ registerHook = eventTypeCreator.apply(type, this.name); ++ LifecycleEventRunner.INSTANCE.addEventType(registerHook); ++ this.hooks.put(type.registryKey(), registerHook); ++ } ++ return registerHook; ++ } ++ ++ @SuppressWarnings("unchecked") ++ public > LifecycleEventType getHook(final RegistryKey registryKey) { ++ return (LifecycleEventType) Objects.requireNonNull(this.hooks.get(registryKey), "No hook for " + registryKey); ++ } ++ ++ public boolean hasHooks(final RegistryKey registryKey) { ++ return this.hooks.containsKey(registryKey); ++ } ++ ++} +diff --git a/src/main/java/io/papermc/paper/registry/event/RegistryEventTypeProviderImpl.java b/src/main/java/io/papermc/paper/registry/event/RegistryEventTypeProviderImpl.java +new file mode 100644 +index 0000000000000000000000000000000000000000..34c842ffa355e3c8001dd7b8551bcb49229a6391 +--- /dev/null ++++ b/src/main/java/io/papermc/paper/registry/event/RegistryEventTypeProviderImpl.java +@@ -0,0 +1,24 @@ ++package io.papermc.paper.registry.event; ++ ++import io.papermc.paper.plugin.bootstrap.BootstrapContext; ++import io.papermc.paper.plugin.lifecycle.event.types.LifecycleEventType; ++import io.papermc.paper.registry.PaperRegistryListenerManager; ++import io.papermc.paper.registry.RegistryBuilder; ++import io.papermc.paper.registry.event.type.RegistryEntryAddEventType; ++ ++public class RegistryEventTypeProviderImpl implements RegistryEventTypeProvider { ++ ++ public static RegistryEventTypeProviderImpl instance() { ++ return (RegistryEventTypeProviderImpl) RegistryEventTypeProvider.provider(); ++ } ++ ++ @Override ++ public > RegistryEntryAddEventType registryEntryAdd(final RegistryEventProvider type) { ++ return PaperRegistryListenerManager.INSTANCE.getRegistryValueAddEventType(type); ++ } ++ ++ @Override ++ public > LifecycleEventType.Prioritizable> registryFreeze(final RegistryEventProvider type) { ++ return PaperRegistryListenerManager.INSTANCE.getRegistryFreezeEventType(type); ++ } ++} +diff --git a/src/main/java/io/papermc/paper/registry/event/RegistryFreezeEventImpl.java b/src/main/java/io/papermc/paper/registry/event/RegistryFreezeEventImpl.java +new file mode 100644 +index 0000000000000000000000000000000000000000..2db5d33d0b72ec3c9ff1c3042d9246dfa4344346 +--- /dev/null ++++ b/src/main/java/io/papermc/paper/registry/event/RegistryFreezeEventImpl.java +@@ -0,0 +1,11 @@ ++package io.papermc.paper.registry.event; ++ ++import io.papermc.paper.plugin.lifecycle.event.PaperLifecycleEvent; ++import io.papermc.paper.registry.RegistryBuilder; ++import io.papermc.paper.registry.RegistryKey; ++ ++public record RegistryFreezeEventImpl>( ++ RegistryKey registryKey, ++ WritableRegistry registry ++) implements RegistryFreezeEvent, PaperLifecycleEvent { ++} +diff --git a/src/main/java/io/papermc/paper/registry/event/package-info.java b/src/main/java/io/papermc/paper/registry/event/package-info.java +new file mode 100644 +index 0000000000000000000000000000000000000000..14d2d9766b8dee763f220c397aba3ad432d02aaa +--- /dev/null ++++ b/src/main/java/io/papermc/paper/registry/event/package-info.java +@@ -0,0 +1,5 @@ ++@DefaultQualifier(NonNull.class) ++package io.papermc.paper.registry.event; ++ ++import org.checkerframework.checker.nullness.qual.NonNull; ++import org.checkerframework.framework.qual.DefaultQualifier; +diff --git a/src/main/java/io/papermc/paper/registry/event/type/RegistryEntryAddEventTypeImpl.java b/src/main/java/io/papermc/paper/registry/event/type/RegistryEntryAddEventTypeImpl.java +new file mode 100644 +index 0000000000000000000000000000000000000000..32303ea9b3da736cbe26d06e57f5dcc3aa32a99b +--- /dev/null ++++ b/src/main/java/io/papermc/paper/registry/event/type/RegistryEntryAddEventTypeImpl.java +@@ -0,0 +1,32 @@ ++package io.papermc.paper.registry.event.type; ++ ++import io.papermc.paper.plugin.bootstrap.BootstrapContext; ++import io.papermc.paper.plugin.lifecycle.event.handler.LifecycleEventHandler; ++import io.papermc.paper.plugin.lifecycle.event.types.PrioritizableLifecycleEventType; ++import io.papermc.paper.registry.RegistryBuilder; ++import io.papermc.paper.registry.event.RegistryEntryAddEvent; ++import io.papermc.paper.registry.event.RegistryEventProvider; ++import java.util.function.Consumer; ++import java.util.function.Predicate; ++ ++public class RegistryEntryAddEventTypeImpl> extends PrioritizableLifecycleEventType, RegistryEntryAddConfiguration> implements RegistryEntryAddEventType { ++ ++ public RegistryEntryAddEventTypeImpl(final RegistryEventProvider type, final String eventName) { ++ super(type.registryKey() + " / " + eventName, BootstrapContext.class); ++ } ++ ++ @Override ++ public RegistryEntryAddConfiguration newHandler(final LifecycleEventHandler> handler) { ++ return new RegistryEntryAddHandlerConfiguration<>(handler, this); ++ } ++ ++ @Override ++ public void forEachHandler(final RegistryEntryAddEvent event, final Consumer>> consumer, final Predicate>> predicate) { ++ super.forEachHandler(event, consumer, predicate.and(handler -> this.matchesTarget(event, handler))); ++ } ++ ++ private boolean matchesTarget(final RegistryEntryAddEvent event, final RegisteredHandler> handler) { ++ final RegistryEntryAddHandlerConfiguration config = (RegistryEntryAddHandlerConfiguration) handler.config(); ++ return config.target() == null || event.key().equals(config.target()); ++ } ++} +diff --git a/src/main/java/io/papermc/paper/registry/event/type/RegistryEntryAddHandlerConfiguration.java b/src/main/java/io/papermc/paper/registry/event/type/RegistryEntryAddHandlerConfiguration.java +new file mode 100644 +index 0000000000000000000000000000000000000000..53df2dd1a9e1cef90bd8504c717b1cc6374b6f4e +--- /dev/null ++++ b/src/main/java/io/papermc/paper/registry/event/type/RegistryEntryAddHandlerConfiguration.java +@@ -0,0 +1,39 @@ ++package io.papermc.paper.registry.event.type; ++ ++import io.papermc.paper.plugin.bootstrap.BootstrapContext; ++import io.papermc.paper.plugin.lifecycle.event.handler.LifecycleEventHandler; ++import io.papermc.paper.plugin.lifecycle.event.handler.configuration.PrioritizedLifecycleEventHandlerConfigurationImpl; ++import io.papermc.paper.plugin.lifecycle.event.types.AbstractLifecycleEventType; ++import io.papermc.paper.registry.RegistryBuilder; ++import io.papermc.paper.registry.TypedKey; ++import io.papermc.paper.registry.event.RegistryEntryAddEvent; ++import org.checkerframework.checker.nullness.qual.Nullable; ++ ++public class RegistryEntryAddHandlerConfiguration> extends PrioritizedLifecycleEventHandlerConfigurationImpl> implements RegistryEntryAddConfiguration { ++ ++ private @Nullable TypedKey target; ++ ++ public RegistryEntryAddHandlerConfiguration(final LifecycleEventHandler> handler, final AbstractLifecycleEventType, ?> eventType) { ++ super(handler, eventType); ++ } ++ ++ public @Nullable TypedKey target() { ++ return this.target; ++ } ++ ++ @Override ++ public RegistryEntryAddConfiguration onlyFor(final TypedKey key) { ++ this.target = key; ++ return this; ++ } ++ ++ @Override ++ public RegistryEntryAddConfiguration priority(final int priority) { ++ return (RegistryEntryAddConfiguration) super.priority(priority); ++ } ++ ++ @Override ++ public RegistryEntryAddConfiguration monitor() { ++ return (RegistryEntryAddConfiguration) super.monitor(); ++ } ++} +diff --git a/src/main/java/io/papermc/paper/registry/event/type/RegistryLifecycleEventType.java b/src/main/java/io/papermc/paper/registry/event/type/RegistryLifecycleEventType.java +new file mode 100644 +index 0000000000000000000000000000000000000000..dcc0f6b337840a78d38abdf2eb3f4bbd1676f58f +--- /dev/null ++++ b/src/main/java/io/papermc/paper/registry/event/type/RegistryLifecycleEventType.java +@@ -0,0 +1,14 @@ ++package io.papermc.paper.registry.event.type; ++ ++import io.papermc.paper.plugin.bootstrap.BootstrapContext; ++import io.papermc.paper.plugin.lifecycle.event.types.PrioritizableLifecycleEventType; ++import io.papermc.paper.registry.RegistryBuilder; ++import io.papermc.paper.registry.event.RegistryEvent; ++import io.papermc.paper.registry.event.RegistryEventProvider; ++ ++public final class RegistryLifecycleEventType, E extends RegistryEvent> extends PrioritizableLifecycleEventType.Simple { ++ ++ public RegistryLifecycleEventType(final RegistryEventProvider type, final String eventName) { ++ super(type.registryKey() + " / " + eventName, BootstrapContext.class); ++ } ++} +diff --git a/src/main/java/io/papermc/paper/registry/package-info.java b/src/main/java/io/papermc/paper/registry/package-info.java +new file mode 100644 +index 0000000000000000000000000000000000000000..0b80179ff90e085568d7ceafd9b17511789dc99b +--- /dev/null ++++ b/src/main/java/io/papermc/paper/registry/package-info.java +@@ -0,0 +1,5 @@ ++@DefaultQualifier(NonNull.class) ++package io.papermc.paper.registry; ++ ++import org.checkerframework.checker.nullness.qual.NonNull; ++import org.checkerframework.framework.qual.DefaultQualifier; +diff --git a/src/main/java/net/minecraft/core/MappedRegistry.java b/src/main/java/net/minecraft/core/MappedRegistry.java +index edbbafd1705345282e5e6251eb71bfde5793b7d4..f22d22ebcedcc9c20225677844c86a1ad27c4211 100644 +--- a/src/main/java/net/minecraft/core/MappedRegistry.java ++++ b/src/main/java/net/minecraft/core/MappedRegistry.java +@@ -441,4 +441,12 @@ public class MappedRegistry implements WritableRegistry { + public HolderLookup.RegistryLookup asLookup() { + return this.lookup; + } ++ // Paper start ++ // used to clear intrusive holders from GameEvent, Item, Block, EntityType, and Fluid from unused instances of those types ++ public void clearIntrusiveHolder(final T instance) { ++ if (this.unregisteredIntrusiveHolders != null) { ++ this.unregisteredIntrusiveHolders.remove(instance); ++ } ++ } ++ // Paper end + } +diff --git a/src/main/java/net/minecraft/core/registries/BuiltInRegistries.java b/src/main/java/net/minecraft/core/registries/BuiltInRegistries.java +index 44b7927081b476813505cab6b3a2da2ec2942c54..c96bcd815ec9bf76625b5bedef461da49d7240ce 100644 +--- a/src/main/java/net/minecraft/core/registries/BuiltInRegistries.java ++++ b/src/main/java/net/minecraft/core/registries/BuiltInRegistries.java +@@ -328,6 +328,7 @@ public class BuiltInRegistries { + } + public static void bootStrap(Runnable runnable) { + // Paper end ++ REGISTRY.freeze(); // Paper - freeze main registry early + createContents(); + runnable.run(); // Paper + freeze(); +@@ -346,6 +347,7 @@ public class BuiltInRegistries { + REGISTRY.freeze(); + + for (Registry registry : REGISTRY) { ++ io.papermc.paper.registry.PaperRegistryListenerManager.INSTANCE.runFreezeListeners(registry.key()); // Paper + registry.freeze(); + } + } +diff --git a/src/main/java/net/minecraft/resources/RegistryDataLoader.java b/src/main/java/net/minecraft/resources/RegistryDataLoader.java +index abadf4abe08dc3bb6612b42cbb3f7df3ffa28ce9..ce65f2ea462b920e5e14b8cb687ef371c311d242 100644 +--- a/src/main/java/net/minecraft/resources/RegistryDataLoader.java ++++ b/src/main/java/net/minecraft/resources/RegistryDataLoader.java +@@ -136,6 +136,7 @@ public class RegistryDataLoader { + list.forEach(loader -> loadable.apply((RegistryDataLoader.Loader)loader, registryInfoLookup)); + list.forEach(loader -> { + Registry registry = loader.registry(); ++ io.papermc.paper.registry.PaperRegistryListenerManager.INSTANCE.runFreezeListeners(loader.registry.key()); // Paper - run pre-freeze listeners + + try { + registry.freeze(); +@@ -199,7 +200,7 @@ public class RegistryDataLoader { + 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); // Paper + } + } + +diff --git a/src/main/java/org/bukkit/craftbukkit/CraftRegistry.java b/src/main/java/org/bukkit/craftbukkit/CraftRegistry.java +index d21b7e39d71c785f47f790e1ad4be33a8e8e6e51..43d686a9958cff96f5b15d93e920c8f2313aa65b 100644 +--- a/src/main/java/org/bukkit/craftbukkit/CraftRegistry.java ++++ b/src/main/java/org/bukkit/craftbukkit/CraftRegistry.java +@@ -156,11 +156,11 @@ public class CraftRegistry implements Registry { + private final Map cache = new HashMap<>(); + private final Map byValue = new java.util.IdentityHashMap<>(); // Paper - improve Registry + private final net.minecraft.core.Registry minecraftRegistry; +- private final BiFunction minecraftToBukkit; ++ private final BiFunction minecraftToBukkit; // Paper + private final BiFunction serializationUpdater; // Paper - rename to make it *clear* what it is *only* for + private boolean init; + +- public CraftRegistry(Class bukkitClass, net.minecraft.core.Registry minecraftRegistry, BiFunction minecraftToBukkit, BiFunction serializationUpdater) { // Paper - relax preload class ++ public CraftRegistry(Class bukkitClass, net.minecraft.core.Registry minecraftRegistry, BiFunction minecraftToBukkit, BiFunction serializationUpdater) { // Paper - relax preload class + this.bukkitClass = bukkitClass; + this.minecraftRegistry = minecraftRegistry; + this.minecraftToBukkit = minecraftToBukkit; +diff --git a/src/main/resources/META-INF/services/io.papermc.paper.registry.event.RegistryEventTypeProvider b/src/main/resources/META-INF/services/io.papermc.paper.registry.event.RegistryEventTypeProvider +new file mode 100644 +index 0000000000000000000000000000000000000000..8bee1a5ed877a04e4d027593df1f42cefdd824e7 +--- /dev/null ++++ b/src/main/resources/META-INF/services/io.papermc.paper.registry.event.RegistryEventTypeProvider +@@ -0,0 +1 @@ ++io.papermc.paper.registry.event.RegistryEventTypeProviderImpl diff --git a/patches/server/1002-RegistrySet-API.patch b/patches/server/1002-RegistrySet-API.patch new file mode 100644 index 0000000000..a90bdc3168 --- /dev/null +++ b/patches/server/1002-RegistrySet-API.patch @@ -0,0 +1,224 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Jake Potrebic +Date: Sat, 11 May 2024 19:26:18 -0700 +Subject: [PATCH] RegistrySet API + + +diff --git a/src/main/java/io/papermc/paper/registry/legacy/DelayedRegistry.java b/src/main/java/io/papermc/paper/registry/legacy/DelayedRegistry.java +index 5562e8da5ebaef2a3add46e88d64358b7737b59e..e5880f76cdb8ebf01fcefdf77ba9b95674b997a8 100644 +--- a/src/main/java/io/papermc/paper/registry/legacy/DelayedRegistry.java ++++ b/src/main/java/io/papermc/paper/registry/legacy/DelayedRegistry.java +@@ -1,12 +1,13 @@ + package io.papermc.paper.registry.legacy; + ++import io.papermc.paper.registry.tag.Tag; ++import io.papermc.paper.registry.tag.TagKey; + import java.util.Iterator; + import java.util.function.Supplier; + import java.util.stream.Stream; + import org.bukkit.Keyed; + import org.bukkit.NamespacedKey; + import org.bukkit.Registry; +-import org.bukkit.craftbukkit.CraftRegistry; + import org.checkerframework.checker.nullness.qual.MonotonicNonNull; + import org.checkerframework.checker.nullness.qual.Nullable; + import org.jetbrains.annotations.NotNull; +@@ -52,4 +53,14 @@ public final class DelayedRegistry> imple + public NamespacedKey getKey(final T value) { + return this.delegate().getKey(value); + } ++ ++ @Override ++ public boolean hasTag(final TagKey key) { ++ return this.delegate().hasTag(key); ++ } ++ ++ @Override ++ public @NotNull Tag getTag(final TagKey key) { ++ return this.delegate().getTag(key); ++ } + } +diff --git a/src/main/java/io/papermc/paper/registry/set/NamedRegistryKeySetImpl.java b/src/main/java/io/papermc/paper/registry/set/NamedRegistryKeySetImpl.java +new file mode 100644 +index 0000000000000000000000000000000000000000..918d80542a1185988fcda3d7642548c7935f73af +--- /dev/null ++++ b/src/main/java/io/papermc/paper/registry/set/NamedRegistryKeySetImpl.java +@@ -0,0 +1,75 @@ ++package io.papermc.paper.registry.set; ++ ++import com.google.common.collect.ImmutableList; ++import io.papermc.paper.adventure.PaperAdventure; ++import io.papermc.paper.registry.RegistryAccess; ++import io.papermc.paper.registry.RegistryKey; ++import io.papermc.paper.registry.TypedKey; ++import io.papermc.paper.registry.tag.Tag; ++import io.papermc.paper.registry.tag.TagKey; ++import java.util.Collection; ++import java.util.Set; ++import net.kyori.adventure.key.Key; ++import net.minecraft.core.Holder; ++import net.minecraft.core.HolderSet; ++import org.bukkit.Keyed; ++import org.bukkit.NamespacedKey; ++import org.bukkit.Registry; ++import org.bukkit.craftbukkit.util.CraftNamespacedKey; ++import org.checkerframework.checker.nullness.qual.NonNull; ++import org.checkerframework.framework.qual.DefaultQualifier; ++import org.jetbrains.annotations.NotNull; ++import org.jetbrains.annotations.Unmodifiable; ++ ++@DefaultQualifier(NonNull.class) ++public record NamedRegistryKeySetImpl( // TODO remove Keyed ++ TagKey tagKey, ++ HolderSet.Named namedSet ++) implements Tag, org.bukkit.Tag { ++ ++ @Override ++ public @Unmodifiable Collection> values() { ++ final ImmutableList.Builder> builder = ImmutableList.builder(); ++ for (final Holder holder : this.namedSet) { ++ builder.add(TypedKey.create(this.tagKey.registryKey(), CraftNamespacedKey.fromMinecraft(((Holder.Reference) holder).key().location()))); ++ } ++ return builder.build(); ++ } ++ ++ @Override ++ public RegistryKey registryKey() { ++ return this.tagKey.registryKey(); ++ } ++ ++ @Override ++ public boolean contains(final TypedKey valueKey) { ++ return this.namedSet.stream().anyMatch(h -> { ++ return ((Holder.Reference) h).key().location().equals(PaperAdventure.asVanilla(valueKey.key())); ++ }); ++ } ++ ++ @Override ++ public @Unmodifiable Collection resolve(final Registry registry) { ++ final ImmutableList.Builder builder = ImmutableList.builder(); ++ for (final Holder holder : this.namedSet) { ++ builder.add(registry.getOrThrow(CraftNamespacedKey.fromMinecraft(((Holder.Reference) holder).key().location()))); ++ } ++ return builder.build(); ++ } ++ ++ @Override ++ public boolean isTagged(final T item) { ++ return this.getValues().contains(item); ++ } ++ ++ @Override ++ public Set getValues() { ++ return Set.copyOf(this.resolve(RegistryAccess.registryAccess().getRegistry(this.registryKey()))); ++ } ++ ++ @Override ++ public @NotNull NamespacedKey getKey() { ++ final Key key = this.tagKey().key(); ++ return new NamespacedKey(key.namespace(), key.value()); ++ } ++} +diff --git a/src/main/java/io/papermc/paper/registry/set/PaperRegistrySets.java b/src/main/java/io/papermc/paper/registry/set/PaperRegistrySets.java +new file mode 100644 +index 0000000000000000000000000000000000000000..c3d5545824189f83308f5a62e3a237efaea2bfe1 +--- /dev/null ++++ b/src/main/java/io/papermc/paper/registry/set/PaperRegistrySets.java +@@ -0,0 +1,52 @@ ++package io.papermc.paper.registry.set; ++ ++import io.papermc.paper.adventure.PaperAdventure; ++import io.papermc.paper.registry.PaperRegistries; ++import io.papermc.paper.registry.RegistryKey; ++import io.papermc.paper.registry.TypedKey; ++import io.papermc.paper.registry.tag.TagKey; ++import java.util.ArrayList; ++import java.util.List; ++import net.minecraft.core.Holder; ++import net.minecraft.core.HolderSet; ++import net.minecraft.core.Registry; ++import net.minecraft.resources.ResourceKey; ++import org.bukkit.Keyed; ++import org.bukkit.craftbukkit.CraftRegistry; ++import org.bukkit.craftbukkit.util.CraftNamespacedKey; ++import org.checkerframework.checker.nullness.qual.NonNull; ++import org.checkerframework.framework.qual.DefaultQualifier; ++ ++@DefaultQualifier(NonNull.class) ++public final class PaperRegistrySets { ++ ++ public static HolderSet convertToNms(final ResourceKey> resourceKey, final RegistryKeySet registryKeySet) { // TODO remove Keyed ++ if (registryKeySet instanceof NamedRegistryKeySetImpl) { ++ return ((NamedRegistryKeySetImpl) registryKeySet).namedSet(); ++ } else { ++ final Registry registry = CraftRegistry.getMinecraftRegistry().registryOrThrow(resourceKey); ++ return HolderSet.direct(key -> { ++ return registry.getHolderOrThrow(ResourceKey.create(resourceKey, PaperAdventure.asVanilla(key.key()))); ++ }, registryKeySet.values()); ++ } ++ } ++ ++ public static RegistryKeySet convertToApi(final RegistryKey registryKey, final HolderSet holders) { // TODO remove Keyed ++ if (holders instanceof final HolderSet.Named named) { ++ final RegistryKey apiRegistryKey = PaperRegistries.fromNms(named.key().registry()); ++ return new NamedRegistryKeySetImpl<>(TagKey.create(apiRegistryKey, CraftNamespacedKey.fromMinecraft(named.key().location())), named); ++ } else { ++ final List> keys = new ArrayList<>(); ++ for (final Holder holder : holders) { ++ if (!(holder instanceof final Holder.Reference reference)) { ++ throw new UnsupportedOperationException("Cannot convert a holder set containing direct holders"); ++ } ++ keys.add(TypedKey.create(registryKey, CraftNamespacedKey.fromMinecraft(reference.key().location()))); ++ } ++ return RegistrySet.keySet(registryKey, keys); ++ } ++ } ++ ++ private PaperRegistrySets() { ++ } ++} +diff --git a/src/main/java/org/bukkit/craftbukkit/CraftRegistry.java b/src/main/java/org/bukkit/craftbukkit/CraftRegistry.java +index 43d686a9958cff96f5b15d93e920c8f2313aa65b..f0248e3d3782b1f6b4ff209502f626d66c05647b 100644 +--- a/src/main/java/org/bukkit/craftbukkit/CraftRegistry.java ++++ b/src/main/java/org/bukkit/craftbukkit/CraftRegistry.java +@@ -233,4 +233,17 @@ public class CraftRegistry implements Registry { + return this.byValue.get(value); + } + // Paper end - improve Registry ++ ++ // Paper start - RegistrySet API ++ @Override ++ public boolean hasTag(final io.papermc.paper.registry.tag.TagKey key) { ++ return this.minecraftRegistry.getTag(net.minecraft.tags.TagKey.create(this.minecraftRegistry.key(), io.papermc.paper.adventure.PaperAdventure.asVanilla(key.key()))).isPresent(); ++ } ++ ++ @Override ++ public io.papermc.paper.registry.tag.Tag getTag(final io.papermc.paper.registry.tag.TagKey key) { ++ final net.minecraft.core.HolderSet.Named namedHolderSet = this.minecraftRegistry.getTag(net.minecraft.tags.TagKey.create(this.minecraftRegistry.key(), io.papermc.paper.adventure.PaperAdventure.asVanilla(key.key()))).orElseThrow(); ++ return new io.papermc.paper.registry.set.NamedRegistryKeySetImpl<>(key, namedHolderSet); ++ } ++ // Paper end - RegistrySet API + } +diff --git a/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java b/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java +index 5a04134973dd1db7f778a57ec5f185feec370990..3885dcf255bf8eea19d311da15d4525234983f17 100644 +--- a/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java ++++ b/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java +@@ -685,6 +685,18 @@ public final class CraftMagicNumbers implements UnsafeValues { + } + // Paper end - lifecycle event API + ++ // Paper start - hack to get tags for non server-backed registries ++ @Override ++ public io.papermc.paper.registry.tag.Tag getTag(final io.papermc.paper.registry.tag.TagKey tagKey) { // TODO remove Keyed ++ final net.minecraft.resources.ResourceKey> nmsKey = io.papermc.paper.registry.PaperRegistries.toNms(tagKey.registryKey()); ++ final net.minecraft.core.Registry nmsRegistry = org.bukkit.craftbukkit.CraftRegistry.getMinecraftRegistry().registryOrThrow(nmsKey); ++ return nmsRegistry ++ .getTag(net.minecraft.tags.TagKey.create(nmsKey, io.papermc.paper.adventure.PaperAdventure.asVanilla(tagKey.key()))) ++ .map(named -> new io.papermc.paper.registry.set.NamedRegistryKeySetImpl<>(tagKey, named)) ++ .orElse(null); ++ } ++ // Paper end - hack to get tags for non server-backed registries ++ + /** + * This helper class represents the different NBT Tags. + *

-- cgit v1.2.3