aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorJake Potrebic <[email protected]>2024-06-14 14:48:56 -0700
committerJake Potrebic <[email protected]>2024-06-14 14:48:56 -0700
commitdf157b7d6c0979338644003ec18a875f2c9ffad1 (patch)
treeacc2721032a60093c9df324ddb01a18c0378cd94
parentd5477705a262bb1700b1d4c2466b8d723dd5d488 (diff)
downloadPaper-feature/registry-modification.tar.gz
Paper-feature/registry-modification.zip
-rw-r--r--patches/api/0478-Registry-Modification-API.patch (renamed from patches/api/0484-Registry-Modification-API.patch)2
-rw-r--r--patches/server/0237-Optimize-MappedRegistry.patch2
-rw-r--r--patches/server/0475-Add-RegistryAccess-for-managing-Registries.patch4
-rw-r--r--patches/server/0975-Brigadier-based-command-API.patch2
-rw-r--r--patches/server/0991-Registry-Modification-API.patch (renamed from patches/server/1054-Registry-Modification-API.patch)48
-rw-r--r--test-plugin/src/main/java/io/papermc/testplugin/TestPlugin.java14
-rw-r--r--test-plugin/src/main/java/io/papermc/testplugin/TestPluginBootstrap.java23
7 files changed, 36 insertions, 59 deletions
diff --git a/patches/api/0484-Registry-Modification-API.patch b/patches/api/0478-Registry-Modification-API.patch
index ca3b8fdd86..70f095bc1f 100644
--- a/patches/api/0484-Registry-Modification-API.patch
+++ b/patches/api/0478-Registry-Modification-API.patch
@@ -366,7 +366,7 @@ index 0000000000000000000000000000000000000000..f4d4ebf6cbed1b4a9955ceb2d0586782
+public interface RegistryEntryAddEventType<T, B extends RegistryBuilder<T>> extends LifecycleEventType<BootstrapContext, RegistryEntryAddEvent<T, B>, RegistryEntryAddConfiguration<T>> {
+}
diff --git a/src/main/java/org/bukkit/Registry.java b/src/main/java/org/bukkit/Registry.java
-index 73edd472b62441670653eb7e3c90aa9667792df7..1fe814a1a8f318f922c0047c7b9bfa9abd724146 100644
+index 802511eaf697d703cadb4b418fe51ea6d31ff3c8..85c4f231dc343c73f1678819f1ac95d5a7ffd080 100644
--- a/src/main/java/org/bukkit/Registry.java
+++ b/src/main/java/org/bukkit/Registry.java
@@ -353,6 +353,27 @@ public interface Registry<T extends Keyed> extends Iterable<T> {
diff --git a/patches/server/0237-Optimize-MappedRegistry.patch b/patches/server/0237-Optimize-MappedRegistry.patch
index 8f45008c5f..17c68f31d7 100644
--- a/patches/server/0237-Optimize-MappedRegistry.patch
+++ b/patches/server/0237-Optimize-MappedRegistry.patch
@@ -8,7 +8,7 @@ Use larger initial sizes to increase bucket capacity on the BiMap
BiMap.get was seen to be using a good bit of CPU time.
diff --git a/src/main/java/net/minecraft/core/MappedRegistry.java b/src/main/java/net/minecraft/core/MappedRegistry.java
-index 362e49f503f3c792fbecf41ec9f235bbc02644de..6e4d5c168acdb9aaa9fbbee090082e4dc25e89e9 100644
+index 1dcbde18bd9c462cca48887b904a9c43261e1854..edbbafd1705345282e5e6251eb71bfde5793b7d4 100644
--- a/src/main/java/net/minecraft/core/MappedRegistry.java
+++ b/src/main/java/net/minecraft/core/MappedRegistry.java
@@ -35,11 +35,11 @@ public class MappedRegistry<T> implements WritableRegistry<T> {
diff --git a/patches/server/0475-Add-RegistryAccess-for-managing-Registries.patch b/patches/server/0475-Add-RegistryAccess-for-managing-Registries.patch
index 65a892ede4..4f2b6f6c28 100644
--- a/patches/server/0475-Add-RegistryAccess-for-managing-Registries.patch
+++ b/patches/server/0475-Add-RegistryAccess-for-managing-Registries.patch
@@ -12,7 +12,7 @@ public net.minecraft.server.RegistryLayer STATIC_ACCESS
diff --git a/src/main/java/io/papermc/paper/registry/PaperRegistries.java b/src/main/java/io/papermc/paper/registry/PaperRegistries.java
new file mode 100644
-index 0000000000000000000000000000000000000000..55feffc03d2924e5ec0f55fc65e8aa148cb0cc62
+index 0000000000000000000000000000000000000000..40ac461d2f1906059377c77229612f540e827d75
--- /dev/null
+++ b/src/main/java/io/papermc/paper/registry/PaperRegistries.java
@@ -0,0 +1,122 @@
@@ -897,7 +897,7 @@ index 0000000000000000000000000000000000000000..b9d00e65639521eecd44bd2be3e01226
+ }
+}
diff --git a/src/test/java/io/papermc/paper/registry/RegistryKeyTest.java b/src/test/java/io/papermc/paper/registry/RegistryKeyTest.java
-index e1c14886064cde56be7fcd8f22a6ecb2d222a762..f4da2afd8977030e3200ac5d4bf51b7206a90bd7 100644
+index e1c14886064cde56be7fcd8f22a6ecb2d222a762..69cece1537bb558b80e1947fdb1fe25555e82628 100644
--- a/src/test/java/io/papermc/paper/registry/RegistryKeyTest.java
+++ b/src/test/java/io/papermc/paper/registry/RegistryKeyTest.java
@@ -1,15 +1,19 @@
diff --git a/patches/server/0975-Brigadier-based-command-API.patch b/patches/server/0975-Brigadier-based-command-API.patch
index e551e947aa..357047a96b 100644
--- a/patches/server/0975-Brigadier-based-command-API.patch
+++ b/patches/server/0975-Brigadier-based-command-API.patch
@@ -1982,7 +1982,7 @@ index 0000000000000000000000000000000000000000..0c3c82b28e581286b798ee58ca4193ef
+
+}
diff --git a/src/main/java/io/papermc/paper/plugin/lifecycle/event/LifecycleEventRunner.java b/src/main/java/io/papermc/paper/plugin/lifecycle/event/LifecycleEventRunner.java
-index f84c9c80e701231e5c33ac3c5573f1093e80f38b..6c072e44a8144de6658b4eb818c996f0eac5805b 100644
+index 65c106fbc9ab990ed53cc5f789582c8cccc1a218..618e9c5e48062840e623cccc7ace4e5c3c118e78 100644
--- a/src/main/java/io/papermc/paper/plugin/lifecycle/event/LifecycleEventRunner.java
+++ b/src/main/java/io/papermc/paper/plugin/lifecycle/event/LifecycleEventRunner.java
@@ -9,6 +9,7 @@ import io.papermc.paper.plugin.lifecycle.event.registrar.RegistrarEventImpl;
diff --git a/patches/server/1054-Registry-Modification-API.patch b/patches/server/0991-Registry-Modification-API.patch
index 6c9b14be60..c770d38c3a 100644
--- a/patches/server/1054-Registry-Modification-API.patch
+++ b/patches/server/0991-Registry-Modification-API.patch
@@ -4,14 +4,13 @@ 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 e68ac2a9710c9e0ac248ce65b6e0d21fa7033fec..9342f034ef590594db046cd9b0810bd4075d8e6b 100644
+index 40ac461d2f1906059377c77229612f540e827d75..7a2fb53ab280893b1c9c886ccb3480b695343cbf 100644
--- a/src/main/java/io/papermc/paper/registry/PaperRegistries.java
+++ b/src/main/java/io/papermc/paper/registry/PaperRegistries.java
-@@ -42,6 +42,7 @@ import org.checkerframework.framework.qual.DefaultQualifier;
+@@ -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;
@@ -20,10 +19,10 @@ index e68ac2a9710c9e0ac248ce65b6e0d21fa7033fec..9342f034ef590594db046cd9b0810bd4
@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 c34cffd369ead2b3e43464a02d4f8fb98ca969c1..a70d1d8b2aef96c2dff7e20670afa8b82027ebf3 100644
+index d591e3a2e19d5358a0d25a5a681368943622d231..f05ebf453406a924da3de6fb250f4793a1b3c612 100644
--- a/src/main/java/io/papermc/paper/registry/PaperRegistryAccess.java
+++ b/src/main/java/io/papermc/paper/registry/PaperRegistryAccess.java
-@@ -85,6 +85,14 @@ public class PaperRegistryAccess implements RegistryAccess {
+@@ -80,6 +80,14 @@ public class PaperRegistryAccess implements RegistryAccess {
return possiblyUnwrap(registryHolder.get());
}
@@ -70,7 +69,7 @@ index 0000000000000000000000000000000000000000..4cf32102a134ebef67d3893cfd24bf0a
+}
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
+index 0000000000000000000000000000000000000000..e2605a9324b9dc91cd910e4bb974d5a911b58b1f
--- /dev/null
+++ b/src/main/java/io/papermc/paper/registry/PaperRegistryListenerManager.java
@@ -0,0 +1,167 @@
@@ -117,7 +116,7 @@ index 0000000000000000000000000000000000000000..6b3ba059b4f530b9e3d1c3d6bbc033e9
+ * For {@link Registry#register(Registry, String, Object)}
+ */
+ public <M> M registerWithListeners(final Registry<M> registry, final String id, final M nms) {
-+ return this.registerWithListeners(registry, new ResourceLocation(id), nms);
++ return this.registerWithListeners(registry, ResourceLocation.withDefaultNamespace(id), nms);
+ }
+
+ /**
@@ -768,10 +767,10 @@ index 0000000000000000000000000000000000000000..0b80179ff90e085568d7ceafd9b17511
+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 72c0c4a12aea39fa1c1967fa0277ed117471107e..68f575602476dd5127af773e4af098196091ca70 100644
+index edbbafd1705345282e5e6251eb71bfde5793b7d4..f22d22ebcedcc9c20225677844c86a1ad27c4211 100644
--- a/src/main/java/net/minecraft/core/MappedRegistry.java
+++ b/src/main/java/net/minecraft/core/MappedRegistry.java
-@@ -436,4 +436,12 @@ public class MappedRegistry<T> implements WritableRegistry<T> {
+@@ -441,4 +441,12 @@ public class MappedRegistry<T> implements WritableRegistry<T> {
public HolderLookup.RegistryLookup<T> asLookup() {
return this.lookup;
}
@@ -785,10 +784,10 @@ index 72c0c4a12aea39fa1c1967fa0277ed117471107e..68f575602476dd5127af773e4af09819
+ // 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 8daee5a7935e3253834c4cbe81d5e8886f776dad..d7da62360d48d8c12c489296b4ee2ee44c0c2d93 100644
+index 44b7927081b476813505cab6b3a2da2ec2942c54..c96bcd815ec9bf76625b5bedef461da49d7240ce 100644
--- a/src/main/java/net/minecraft/core/registries/BuiltInRegistries.java
+++ b/src/main/java/net/minecraft/core/registries/BuiltInRegistries.java
-@@ -310,6 +310,7 @@ public class BuiltInRegistries {
+@@ -328,6 +328,7 @@ public class BuiltInRegistries {
}
public static void bootStrap(Runnable runnable) {
// Paper end
@@ -796,7 +795,7 @@ index 8daee5a7935e3253834c4cbe81d5e8886f776dad..d7da62360d48d8c12c489296b4ee2ee4
createContents();
runnable.run(); // Paper
freeze();
-@@ -328,6 +329,7 @@ public class BuiltInRegistries {
+@@ -346,6 +347,7 @@ public class BuiltInRegistries {
REGISTRY.freeze();
for (Registry<?> registry : REGISTRY) {
@@ -805,10 +804,10 @@ index 8daee5a7935e3253834c4cbe81d5e8886f776dad..d7da62360d48d8c12c489296b4ee2ee4
}
}
diff --git a/src/main/java/net/minecraft/resources/RegistryDataLoader.java b/src/main/java/net/minecraft/resources/RegistryDataLoader.java
-index d59356df2d98de873fc5accc749f87fa3d685267..9414cadb2766c3b8f50bf811d3408402e9f57670 100644
+index abadf4abe08dc3bb6612b42cbb3f7df3ffa28ce9..56d8dcf2f3fd042ed1e7ed01a0ce5d90c89ee502 100644
--- a/src/main/java/net/minecraft/resources/RegistryDataLoader.java
+++ b/src/main/java/net/minecraft/resources/RegistryDataLoader.java
-@@ -125,6 +125,7 @@ public class RegistryDataLoader {
+@@ -136,6 +136,7 @@ public class RegistryDataLoader {
list.forEach(loader -> loadable.apply((RegistryDataLoader.Loader<?>)loader, registryInfoLookup));
list.forEach(loader -> {
Registry<?> registry = loader.registry();
@@ -816,20 +815,33 @@ index d59356df2d98de873fc5accc749f87fa3d685267..9414cadb2766c3b8f50bf811d3408402
try {
registry.freeze();
-@@ -188,7 +189,7 @@ public class RegistryDataLoader {
+@@ -199,7 +200,7 @@ public class RegistryDataLoader {
JsonElement jsonElement = JsonParser.parseReader(reader);
DataResult<E> 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
++ 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 4a5778d1751b774c825bbce0e870e2998278afe3..55d459731a9d7ab8debfdd6d27f874dba6c41436 100644
+index d21b7e39d71c785f47f790e1ad4be33a8e8e6e51..43d686a9958cff96f5b15d93e920c8f2313aa65b 100644
--- a/src/main/java/org/bukkit/craftbukkit/CraftRegistry.java
+++ b/src/main/java/org/bukkit/craftbukkit/CraftRegistry.java
-@@ -155,11 +155,11 @@ public class CraftRegistry<B extends Keyed, M> implements Registry<B> {
+@@ -156,11 +156,11 @@ public class CraftRegistry<B extends Keyed, M> implements Registry<B> {
private final Map<NamespacedKey, B> cache = new HashMap<>();
private final Map<B, NamespacedKey> byValue = new java.util.IdentityHashMap<>(); // Paper - improve Registry
private final net.minecraft.core.Registry<M> minecraftRegistry;
diff --git a/test-plugin/src/main/java/io/papermc/testplugin/TestPlugin.java b/test-plugin/src/main/java/io/papermc/testplugin/TestPlugin.java
index b8d30202dd..671c37fa40 100644
--- a/test-plugin/src/main/java/io/papermc/testplugin/TestPlugin.java
+++ b/test-plugin/src/main/java/io/papermc/testplugin/TestPlugin.java
@@ -1,8 +1,5 @@
package io.papermc.testplugin;
-import io.papermc.paper.registry.keys.GameEventKeys;
-import org.bukkit.GameEvent;
-import org.bukkit.Registry;
import org.bukkit.event.Listener;
import org.bukkit.plugin.java.JavaPlugin;
@@ -13,17 +10,6 @@ public final class TestPlugin extends JavaPlugin implements Listener {
this.getServer().getPluginManager().registerEvents(this, this);
// io.papermc.testplugin.brigtests.Registration.registerViaOnEnable(this);
-
- final GameEvent newEvent = Registry.GAME_EVENT.get(TestPluginBootstrap.NEW_EVENT);
- if (newEvent == null) {
- throw new RuntimeException("could not find new event");
- } else {
- System.out.println("New event: " + newEvent.getKey() + " " + newEvent.getRange());
- }
- final GameEvent changed = Registry.GAME_EVENT.get(GameEventKeys.BLOCK_OPEN);
- System.out.println("changed: " + changed.getRange());
- final GameEvent same = Registry.GAME_EVENT.get(GameEventKeys.CONTAINER_OPEN);
- System.out.println("same: " + same.getRange());
}
}
diff --git a/test-plugin/src/main/java/io/papermc/testplugin/TestPluginBootstrap.java b/test-plugin/src/main/java/io/papermc/testplugin/TestPluginBootstrap.java
index 26da106c6c..fe2b287b25 100644
--- a/test-plugin/src/main/java/io/papermc/testplugin/TestPluginBootstrap.java
+++ b/test-plugin/src/main/java/io/papermc/testplugin/TestPluginBootstrap.java
@@ -2,34 +2,13 @@ package io.papermc.testplugin;
import io.papermc.paper.plugin.bootstrap.BootstrapContext;
import io.papermc.paper.plugin.bootstrap.PluginBootstrap;
-import io.papermc.paper.plugin.lifecycle.event.LifecycleEventManager;
-import io.papermc.paper.registry.RegistryKey;
-import io.papermc.paper.registry.TypedKey;
-import io.papermc.paper.registry.event.RegistryEvents;
-import io.papermc.paper.registry.keys.GameEventKeys;
-import net.kyori.adventure.key.Key;
-import org.bukkit.GameEvent;
-import org.checkerframework.checker.nullness.qual.NonNull;
-import org.checkerframework.framework.qual.DefaultQualifier;
import org.jetbrains.annotations.NotNull;
-@DefaultQualifier(NonNull.class)
public class TestPluginBootstrap implements PluginBootstrap {
- static final TypedKey<GameEvent> NEW_EVENT = TypedKey.create(RegistryKey.GAME_EVENT, Key.key("machine_maker", "best_event"));
-
@Override
public void bootstrap(@NotNull BootstrapContext context) {
// io.papermc.testplugin.brigtests.Registration.registerViaBootstrap(context);
-
- final LifecycleEventManager<BootstrapContext> lifecycleManager = context.getLifecycleManager();
- lifecycleManager.registerEventHandler(RegistryEvents.GAME_EVENT.entryAdd().newHandler(event -> {
- event.builder().range(event.builder().range() * 40);
- }).priority(10).onlyFor(GameEventKeys.BLOCK_OPEN));
- lifecycleManager.registerEventHandler(RegistryEvents.GAME_EVENT.freeze(), event -> {
- event.registry().register(NEW_EVENT, builder -> {
- builder.range(2);
- });
- });
}
+
}