|
| 1 | +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 |
| 2 | +From: Jake Potrebic < [email protected]> |
| 3 | +Date: Sun, 24 Nov 2024 02:38:39 -0800 |
| 4 | +Subject: [PATCH] RegistryValue API |
| 5 | + |
| 6 | + |
| 7 | +diff --git a/src/main/java/io/papermc/paper/registry/DirectRegistryValue.java b/src/main/java/io/papermc/paper/registry/DirectRegistryValue.java |
| 8 | +new file mode 100644 |
| 9 | +index 0000000000000000000000000000000000000000..5ed90654e673f7959a03f534e677bfae5dfaca41 |
| 10 | +--- /dev/null |
| 11 | ++++ b/src/main/java/io/papermc/paper/registry/DirectRegistryValue.java |
| 12 | +@@ -0,0 +1,22 @@ |
| 13 | ++package io.papermc.paper.registry; |
| 14 | ++ |
| 15 | ++import io.papermc.paper.registry.tag.TagKey; |
| 16 | ++import net.kyori.adventure.key.Key; |
| 17 | ++ |
| 18 | ++public record DirectRegistryValue<T>(T value) implements RegistryValue.Direct<T> { |
| 19 | ++ |
| 20 | ++ @Override |
| 21 | ++ public boolean is(final Key key) { |
| 22 | ++ return false; |
| 23 | ++ } |
| 24 | ++ |
| 25 | ++ @Override |
| 26 | ++ public boolean is(final TypedKey<T> typedKey) { |
| 27 | ++ return false; |
| 28 | ++ } |
| 29 | ++ |
| 30 | ++ @Override |
| 31 | ++ public boolean is(final TagKey<T> tagKey) { |
| 32 | ++ return false; |
| 33 | ++ } |
| 34 | ++} |
| 35 | +diff --git a/src/main/java/io/papermc/paper/registry/RegistryLookup.java b/src/main/java/io/papermc/paper/registry/RegistryLookup.java |
| 36 | +new file mode 100644 |
| 37 | +index 0000000000000000000000000000000000000000..9ca06481436767745afbfb8385e9820179e64686 |
| 38 | +--- /dev/null |
| 39 | ++++ b/src/main/java/io/papermc/paper/registry/RegistryLookup.java |
| 40 | +@@ -0,0 +1,34 @@ |
| 41 | ++package io.papermc.paper.registry; |
| 42 | ++ |
| 43 | ++import io.papermc.paper.registry.tag.Tag; |
| 44 | ++import io.papermc.paper.registry.tag.TagKey; |
| 45 | ++import org.bukkit.Keyed; |
| 46 | ++import org.jetbrains.annotations.ApiStatus; |
| 47 | ++import org.jspecify.annotations.NullMarked; |
| 48 | ++ |
| 49 | ++@ApiStatus.Experimental |
| 50 | ++@NullMarked |
| 51 | ++@ApiStatus.NonExtendable |
| 52 | ++public interface RegistryLookup { |
| 53 | ++ |
| 54 | ++ /** |
| 55 | ++ * Gets or creates a tag for the given tag key. This tag |
| 56 | ++ * is then required to be filled either from the built-in or |
| 57 | ++ * custom datapack. |
| 58 | ++ * |
| 59 | ++ * @param tagKey the tag key |
| 60 | ++ * @return the tag |
| 61 | ++ * @param <V> the tag value type |
| 62 | ++ */ |
| 63 | ++ <V extends Keyed> Tag<V> getOrCreateTag(TagKey<V> tagKey); |
| 64 | ++ |
| 65 | ++ /** |
| 66 | ++ * Gets or creates a registry value for the given typed key. If |
| 67 | ++ * it's created, it's required to be filled during some later event. |
| 68 | ++ * |
| 69 | ++ * @param typedKey the typed key |
| 70 | ++ * @return the registry value |
| 71 | ++ * @param <V> the value type |
| 72 | ++ */ |
| 73 | ++ <V> RegistryValue.Reference<V> getOrCreateValue(TypedKey<V> typedKey); |
| 74 | ++} |
| 75 | +diff --git a/src/main/java/io/papermc/paper/registry/RegistryValue.java b/src/main/java/io/papermc/paper/registry/RegistryValue.java |
| 76 | +new file mode 100644 |
| 77 | +index 0000000000000000000000000000000000000000..c47c192538750943c190f0aadd4e88bfa7356659 |
| 78 | +--- /dev/null |
| 79 | ++++ b/src/main/java/io/papermc/paper/registry/RegistryValue.java |
| 80 | +@@ -0,0 +1,43 @@ |
| 81 | ++package io.papermc.paper.registry; |
| 82 | ++ |
| 83 | ++import io.papermc.paper.registry.tag.TagKey; |
| 84 | ++import net.kyori.adventure.key.Key; |
| 85 | ++import org.jetbrains.annotations.ApiStatus; |
| 86 | ++import org.jetbrains.annotations.Contract; |
| 87 | ++import org.jspecify.annotations.NullMarked; |
| 88 | ++ |
| 89 | ++@ApiStatus.Experimental |
| 90 | ++@NullMarked |
| 91 | ++@ApiStatus.NonExtendable |
| 92 | ++public sealed interface RegistryValue<T> { |
| 93 | ++ |
| 94 | ++ @Contract(value = "_ -> new", pure = true) |
| 95 | ++ static <T> RegistryValue<T> direct(final T value) { |
| 96 | ++ return new DirectRegistryValue<>(value); |
| 97 | ++ } |
| 98 | ++ |
| 99 | ++ @Contract(pure = true) |
| 100 | ++ boolean is(Key key); |
| 101 | ++ |
| 102 | ++ @Contract(pure = true) |
| 103 | ++ boolean is(TypedKey<T> typedKey); |
| 104 | ++ |
| 105 | ++ @Contract(pure = true) |
| 106 | ++ boolean is(TagKey<T> tagKey); |
| 107 | ++ |
| 108 | ++ @ApiStatus.Experimental |
| 109 | ++ @ApiStatus.NonExtendable |
| 110 | ++ non-sealed interface Reference<T> extends RegistryValue<T> { |
| 111 | ++ |
| 112 | ++ @Contract(pure = true) |
| 113 | ++ TypedKey<T> key(); |
| 114 | ++ } |
| 115 | ++ |
| 116 | ++ @ApiStatus.Experimental |
| 117 | ++ @ApiStatus.NonExtendable |
| 118 | ++ sealed interface Direct<T> extends RegistryValue<T> permits DirectRegistryValue { |
| 119 | ++ |
| 120 | ++ @Contract(pure = true) |
| 121 | ++ T value(); |
| 122 | ++ } |
| 123 | ++} |
| 124 | +diff --git a/src/main/java/io/papermc/paper/registry/event/RegistryEntryAddEvent.java b/src/main/java/io/papermc/paper/registry/event/RegistryEntryAddEvent.java |
| 125 | +index 56468b311e40a6d1aa03c6d31328952b92e95027..98963c3c8a49375fc14e6673f1317f74dcccb833 100644 |
| 126 | +--- a/src/main/java/io/papermc/paper/registry/event/RegistryEntryAddEvent.java |
| 127 | ++++ b/src/main/java/io/papermc/paper/registry/event/RegistryEntryAddEvent.java |
| 128 | +@@ -1,6 +1,8 @@ |
| 129 | + package io.papermc.paper.registry.event; |
| 130 | + |
| 131 | + import io.papermc.paper.registry.RegistryBuilder; |
| 132 | ++import io.papermc.paper.registry.RegistryLookup; |
| 133 | ++import io.papermc.paper.registry.RegistryValue; |
| 134 | + import io.papermc.paper.registry.TypedKey; |
| 135 | + import io.papermc.paper.registry.tag.Tag; |
| 136 | + import io.papermc.paper.registry.tag.TagKey; |
| 137 | +@@ -19,7 +21,7 @@ import org.jspecify.annotations.NullMarked; |
| 138 | + @ApiStatus.Experimental |
| 139 | + @NullMarked |
| 140 | + @ApiStatus.NonExtendable |
| 141 | +-public interface RegistryEntryAddEvent<T, B extends RegistryBuilder<T>> extends RegistryEvent<T> { |
| 142 | ++public interface RegistryEntryAddEvent<T, B extends RegistryBuilder<T>> extends RegistryEvent<T>, RegistryLookup { |
| 143 | + |
| 144 | + /** |
| 145 | + * Gets the builder for the entry being added to the registry. |
| 146 | +@@ -34,15 +36,4 @@ public interface RegistryEntryAddEvent<T, B extends RegistryBuilder<T>> extends |
| 147 | + * @return the key |
| 148 | + */ |
| 149 | + TypedKey<T> key(); |
| 150 | +- |
| 151 | +- /** |
| 152 | +- * Gets or creates a tag for the given tag key. This tag |
| 153 | +- * is then required to be filled either from the built-in or |
| 154 | +- * custom datapack. |
| 155 | +- * |
| 156 | +- * @param tagKey the tag key |
| 157 | +- * @return the tag |
| 158 | +- * @param <V> the tag value type |
| 159 | +- */ |
| 160 | +- <V extends Keyed> Tag<V> getOrCreateTag(TagKey<V> tagKey); |
| 161 | + } |
| 162 | +diff --git a/src/main/java/io/papermc/paper/registry/event/RegistryFreezeEvent.java b/src/main/java/io/papermc/paper/registry/event/RegistryFreezeEvent.java |
| 163 | +index 59e8ca6c5b7fa0424ad9b2c74545ec53444b5fcb..1a95ee135d25f0700e1d6e902c09c0a28092d36e 100644 |
| 164 | +--- a/src/main/java/io/papermc/paper/registry/event/RegistryFreezeEvent.java |
| 165 | ++++ b/src/main/java/io/papermc/paper/registry/event/RegistryFreezeEvent.java |
| 166 | +@@ -1,6 +1,9 @@ |
| 167 | + package io.papermc.paper.registry.event; |
| 168 | + |
| 169 | + import io.papermc.paper.registry.RegistryBuilder; |
| 170 | ++import io.papermc.paper.registry.RegistryLookup; |
| 171 | ++import io.papermc.paper.registry.RegistryValue; |
| 172 | ++import io.papermc.paper.registry.TypedKey; |
| 173 | + import io.papermc.paper.registry.tag.Tag; |
| 174 | + import io.papermc.paper.registry.tag.TagKey; |
| 175 | + import org.bukkit.Keyed; |
| 176 | +@@ -18,7 +21,7 @@ import org.jspecify.annotations.NullMarked; |
| 177 | + @ApiStatus.Experimental |
| 178 | + @NullMarked |
| 179 | + @ApiStatus.NonExtendable |
| 180 | +-public interface RegistryFreezeEvent<T, B extends RegistryBuilder<T>> extends RegistryEvent<T> { |
| 181 | ++public interface RegistryFreezeEvent<T, B extends RegistryBuilder<T>> extends RegistryEvent<T>, RegistryLookup { |
| 182 | + |
| 183 | + /** |
| 184 | + * Get the writable registry. |
| 185 | +@@ -26,15 +29,4 @@ public interface RegistryFreezeEvent<T, B extends RegistryBuilder<T>> extends Re |
| 186 | + * @return a writable registry |
| 187 | + */ |
| 188 | + WritableRegistry<T, B> registry(); |
| 189 | +- |
| 190 | +- /** |
| 191 | +- * Gets or creates a tag for the given tag key. This tag |
| 192 | +- * is then required to be filled either from the built-in or |
| 193 | +- * custom datapack. |
| 194 | +- * |
| 195 | +- * @param tagKey the tag key |
| 196 | +- * @return the tag |
| 197 | +- * @param <V> the tag value type |
| 198 | +- */ |
| 199 | +- <V extends Keyed> Tag<V> getOrCreateTag(TagKey<V> tagKey); |
| 200 | + } |
0 commit comments