diff options
-rw-r--r-- | patches/api/0476-Registry-Modification-API.patch | 41 | ||||
-rw-r--r-- | patches/server/1021-Registry-Modification-API.patch | 29 |
2 files changed, 40 insertions, 30 deletions
diff --git a/patches/api/0476-Registry-Modification-API.patch b/patches/api/0476-Registry-Modification-API.patch index 3014764cc7..f566c2d39d 100644 --- a/patches/api/0476-Registry-Modification-API.patch +++ b/patches/api/0476-Registry-Modification-API.patch @@ -335,15 +335,16 @@ index 0000000000000000000000000000000000000000..6de377275097f065c38dd59c6db97040 +} diff --git a/src/main/java/io/papermc/paper/registry/event/type/RegistryEntryAddConfiguration.java b/src/main/java/io/papermc/paper/registry/event/type/RegistryEntryAddConfiguration.java new file mode 100644 -index 0000000000000000000000000000000000000000..ad54c48ff2de18fe135c29102655f39c84063792 +index 0000000000000000000000000000000000000000..c5b484ee5f4a0f283a8d46f5490afac4b58b06be --- /dev/null +++ b/src/main/java/io/papermc/paper/registry/event/type/RegistryEntryAddConfiguration.java -@@ -0,0 +1,30 @@ +@@ -0,0 +1,42 @@ +package io.papermc.paper.registry.event.type; + +import io.papermc.paper.plugin.bootstrap.BootstrapContext; +import io.papermc.paper.plugin.lifecycle.event.handler.configuration.PrioritizedLifecycleEventHandlerConfiguration; +import io.papermc.paper.registry.TypedKey; ++import java.util.function.Predicate; +import org.checkerframework.checker.nullness.qual.NonNull; +import org.jetbrains.annotations.Contract; + @@ -361,7 +362,18 @@ index 0000000000000000000000000000000000000000..ad54c48ff2de18fe135c29102655f39c + * @return this configuration + */ + @Contract(value = "_ -> this", mutates = "this") -+ @NonNull RegistryEntryAddConfiguration<T> onlyFor(@NonNull TypedKey<T> key); ++ default @NonNull RegistryEntryAddConfiguration<T> filter(final @NonNull TypedKey<T> key) { ++ return this.filter(key::equals); ++ } ++ ++ /** ++ * Only call the handler if the value being added passes the provided filter. ++ * ++ * @param filter the predicate to match the key against ++ * @return this configuration ++ */ ++ @Contract(value = "_ -> this", mutates = "this") ++ @NonNull RegistryEntryAddConfiguration<T> filter(@NonNull Predicate<TypedKey<T>> filter); + + @Override + @NonNull RegistryEntryAddConfiguration<T> priority(int priority); @@ -510,7 +522,7 @@ index 0000000000000000000000000000000000000000..c712181ad4c6a9d00bc04f8a48515a38 +} 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..6b8ea31dce5d09389285cef29dfc52001c985dbe +index 0000000000000000000000000000000000000000..108df480e16131781a52c7bbba2ca6581e4c1ca1 --- /dev/null +++ b/src/main/java/io/papermc/paper/registry/set/RegistrySet.java @@ -0,0 +1,112 @@ @@ -532,7 +544,7 @@ index 0000000000000000000000000000000000000000..6b8ea31dce5d09389285cef29dfc5200 + * <ul> + * <li>{@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)}.</li> -+ * <li>{@link RegistryKeySet} which is a set of of values that are present in the registry. These are ++ * <li>{@link RegistryKeySet} which is a set of of keys linked to values that are present in the registry. These are + * created via {@link #keySet(RegistryKey, Iterable)} or {@link #keySetFromValues(RegistryKey, Iterable)}.</li> + * <!-- <li>{@link RegistryValueSet} which is a set of values which are anonymous (don't have keys in the registry). These are + * created via {@link #valueSet(RegistryKey, Iterable)}.</li>--> @@ -778,7 +790,7 @@ index 0000000000000000000000000000000000000000..11d19e339c7c62f2eb4467277552c27e +record TagKeyImpl<T>(RegistryKey<T> registryKey, Key key) implements TagKey<T> { +} diff --git a/src/main/java/org/bukkit/Registry.java b/src/main/java/org/bukkit/Registry.java -index 27b987db385a594fede4e884b6437dc363f6e817..e2ca3b1bdc181d16286d4c2b2535c7ba7b0cdaeb 100644 +index 27b987db385a594fede4e884b6437dc363f6e817..9725580b6458e5d37fbc6059869604f9883bd6d1 100644 --- a/src/main/java/org/bukkit/Registry.java +++ b/src/main/java/org/bukkit/Registry.java @@ -357,6 +357,27 @@ public interface Registry<T extends Keyed> extends Iterable<T> { @@ -809,7 +821,7 @@ index 27b987db385a594fede4e884b6437dc363f6e817..e2ca3b1bdc181d16286d4c2b2535c7ba // Paper start - improve Registry /** -@@ -431,6 +452,30 @@ public interface Registry<T extends Keyed> extends Iterable<T> { +@@ -431,6 +452,34 @@ public interface Registry<T extends Keyed> extends Iterable<T> { } // Paper end - improve Registry @@ -819,6 +831,7 @@ index 27b987db385a594fede4e884b6437dc363f6e817..e2ca3b1bdc181d16286d4c2b2535c7ba + * + * @param key the key to check for + * @return true if this registry has a tag with the given key, false otherwise ++ * @see #getTag(io.papermc.paper.registry.tag.TagKey) + */ + @ApiStatus.Experimental + default boolean hasTag(final io.papermc.paper.registry.tag.@NotNull TagKey<T> key) { @@ -830,6 +843,9 @@ index 27b987db385a594fede4e884b6437dc363f6e817..e2ca3b1bdc181d16286d4c2b2535c7ba + * + * @param key the key to get the tag for + * @return the tag for the key ++ * @throws java.util.NoSuchElementException if no tag with the given key is found ++ * @throws UnsupportedOperationException if this registry doesn't have or support tags ++ * @see #hasTag(io.papermc.paper.registry.tag.TagKey) + */ + @ApiStatus.Experimental + default @NotNull io.papermc.paper.registry.tag.Tag<T> getTag(final io.papermc.paper.registry.tag.@NotNull TagKey<T> key) { @@ -840,16 +856,7 @@ index 27b987db385a594fede4e884b6437dc363f6e817..e2ca3b1bdc181d16286d4c2b2535c7ba /** * Returns a new stream, which contains all registry items, which are registered to the registry. * -@@ -460,7 +505,7 @@ public interface Registry<T extends Keyed> extends Iterable<T> { - return (namespacedKey != null) ? get(namespacedKey) : null; - } - -- static final class SimpleRegistry<T extends Enum<T> & Keyed> implements Registry<T> { -+ static class SimpleRegistry<T extends Enum<T> & Keyed> implements Registry<T> { // Paper - not final - - private final Class<T> type; - private final Map<NamespacedKey, T> map; -@@ -512,5 +557,23 @@ public interface Registry<T extends Keyed> extends Iterable<T> { +@@ -512,5 +561,23 @@ public interface Registry<T extends Keyed> extends Iterable<T> { return value.getKey(); } // Paper end - improve Registry diff --git a/patches/server/1021-Registry-Modification-API.patch b/patches/server/1021-Registry-Modification-API.patch index 6292107ffe..ffe2d836cd 100644 --- a/patches/server/1021-Registry-Modification-API.patch +++ b/patches/server/1021-Registry-Modification-API.patch @@ -841,7 +841,7 @@ index 0000000000000000000000000000000000000000..14d2d9766b8dee763f220c397aba3ad4 +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 +index 0000000000000000000000000000000000000000..5d709ed04e1078b631f5b9c74ca35f042251e14f --- /dev/null +++ b/src/main/java/io/papermc/paper/registry/event/type/RegistryEntryAddEventTypeImpl.java @@ -0,0 +1,32 @@ @@ -874,15 +874,15 @@ index 0000000000000000000000000000000000000000..32303ea9b3da736cbe26d06e57f5dcc3 + + private boolean matchesTarget(final RegistryEntryAddEvent<T, B> event, final RegisteredHandler<BootstrapContext, RegistryEntryAddEvent<T, B>> handler) { + final RegistryEntryAddHandlerConfiguration<T, B> config = (RegistryEntryAddHandlerConfiguration<T, B>) handler.config(); -+ return config.target() == null || event.key().equals(config.target()); ++ return config.filter() == null || config.filter().test(event.key()); + } +} 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 +index 0000000000000000000000000000000000000000..548f5bf979e88708e98d04dfe22ccaa300c91ddd --- /dev/null +++ b/src/main/java/io/papermc/paper/registry/event/type/RegistryEntryAddHandlerConfiguration.java -@@ -0,0 +1,39 @@ +@@ -0,0 +1,42 @@ +package io.papermc.paper.registry.event.type; + +import io.papermc.paper.plugin.bootstrap.BootstrapContext; @@ -892,23 +892,26 @@ index 0000000000000000000000000000000000000000..53df2dd1a9e1cef90bd8504c717b1cc6 +import io.papermc.paper.registry.RegistryBuilder; +import io.papermc.paper.registry.TypedKey; +import io.papermc.paper.registry.event.RegistryEntryAddEvent; ++import java.util.function.Predicate; +import org.checkerframework.checker.nullness.qual.Nullable; ++import org.jetbrains.annotations.Contract; + +public class RegistryEntryAddHandlerConfiguration<T, B extends RegistryBuilder<T>> extends PrioritizedLifecycleEventHandlerConfigurationImpl<BootstrapContext, RegistryEntryAddEvent<T, B>> implements RegistryEntryAddConfiguration<T> { + -+ private @Nullable TypedKey<T> target; ++ private @Nullable Predicate<TypedKey<T>> filter; + + public RegistryEntryAddHandlerConfiguration(final LifecycleEventHandler<? super RegistryEntryAddEvent<T, B>> handler, final AbstractLifecycleEventType<BootstrapContext, RegistryEntryAddEvent<T, B>, ?> eventType) { + super(handler, eventType); + } + -+ public @Nullable TypedKey<T> target() { -+ return this.target; ++ @Contract(pure = true) ++ public @Nullable Predicate<TypedKey<T>> filter() { ++ return this.filter; + } + + @Override -+ public RegistryEntryAddConfiguration<T> onlyFor(final TypedKey<T> key) { -+ this.target = key; ++ public RegistryEntryAddConfiguration<T> filter(final Predicate<TypedKey<T>> filter) { ++ this.filter = filter; + return this; + } + @@ -1328,7 +1331,7 @@ index 397bdacab9517354875ebc0bc68d35059b3c318b..908431652a0fea79b5a0cee1efd0c7a7 return writableRegistry; }, diff --git a/src/main/java/org/bukkit/craftbukkit/CraftRegistry.java b/src/main/java/org/bukkit/craftbukkit/CraftRegistry.java -index d21b7e39d71c785f47f790e1ad4be33a8e8e6e51..f0248e3d3782b1f6b4ff209502f626d66c05647b 100644 +index d21b7e39d71c785f47f790e1ad4be33a8e8e6e51..a47421425a8d5d2f07e08890fded0f7bfec4efb7 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<B extends Keyed, M> implements Registry<B> { @@ -1358,13 +1361,13 @@ index d21b7e39d71c785f47f790e1ad4be33a8e8e6e51..f0248e3d3782b1f6b4ff209502f626d6 + + @Override + public io.papermc.paper.registry.tag.Tag<B> getTag(final io.papermc.paper.registry.tag.TagKey<B> key) { -+ final net.minecraft.core.HolderSet.Named<M> namedHolderSet = this.minecraftRegistry.getTag(net.minecraft.tags.TagKey.create(this.minecraftRegistry.key(), io.papermc.paper.adventure.PaperAdventure.asVanilla(key.key()))).orElseThrow(); ++ final net.minecraft.core.HolderSet.Named<M> namedHolderSet = this.minecraftRegistry.getTag(io.papermc.paper.registry.PaperRegistries.toNms(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..b93641f9637024ef80927ccb0cab1f7fa6ceffe3 100644 +index 5a04134973dd1db7f778a57ec5f185feec370990..8dba6c4a2e1f305cf576e8bfdca5d0c07ab871ae 100644 --- a/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java +++ b/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java @@ -685,6 +685,21 @@ public final class CraftMagicNumbers implements UnsafeValues { @@ -1380,7 +1383,7 @@ index 5a04134973dd1db7f778a57ec5f185feec370990..b93641f9637024ef80927ccb0cab1f7f + final net.minecraft.resources.ResourceKey<? extends net.minecraft.core.Registry<M>> nmsKey = io.papermc.paper.registry.PaperRegistries.registryToNms(tagKey.registryKey()); + final net.minecraft.core.Registry<M> 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()))) ++ .getTag(io.papermc.paper.registry.PaperRegistries.toNms(tagKey)) + .map(named -> new io.papermc.paper.registry.set.NamedRegistryKeySetImpl<>(tagKey, named)) + .orElse(null); + } |