From b15172bc8ed322fde4f9aaa612be11e92e302383 Mon Sep 17 00:00:00 2001 From: Jake Potrebic Date: Wed, 15 Feb 2023 15:00:22 -0800 Subject: [PATCH] Make sure Registry is loaded after Bukkit.setServer() (#8853) --- patches/server/Add-PaperRegistry.patch | 2 +- .../server/Add-StructuresLocateEvent.patch | 20 +++++++++---------- patches/server/Test-changes.patch | 12 +++++------ 3 files changed, 17 insertions(+), 17 deletions(-) diff --git a/patches/server/Add-PaperRegistry.patch b/patches/server/Add-PaperRegistry.patch index 5b49788730..52e0b47041 100644 --- a/patches/server/Add-PaperRegistry.patch +++ b/patches/server/Add-PaperRegistry.patch @@ -225,9 +225,9 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 --- a/src/test/java/org/bukkit/support/AbstractTestingBase.java +++ b/src/test/java/org/bukkit/support/AbstractTestingBase.java @@ -0,0 +0,0 @@ public abstract class AbstractTestingBase { - LayeredRegistryAccess layers = RegistryLayer.createRegistryAccess(); layers = WorldLoader.loadAndReplaceLayer(resourceManager, layers, RegistryLayer.WORLDGEN, RegistryDataLoader.WORLDGEN_REGISTRIES); REGISTRY_CUSTOM = layers.compositeAccess().freeze(); + io.papermc.paper.testing.DummyServer.setup(); // Paper + // Paper start + try { + java.lang.reflect.Field field = io.papermc.paper.registry.PaperRegistry.class.getDeclaredField("REGISTRY_ACCESS"); diff --git a/patches/server/Add-StructuresLocateEvent.patch b/patches/server/Add-StructuresLocateEvent.patch index 6142c549aa..2702105d0a 100644 --- a/patches/server/Add-StructuresLocateEvent.patch +++ b/patches/server/Add-StructuresLocateEvent.patch @@ -105,18 +105,18 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 ChunkGeneratorStructureState chunkgeneratorstructurestate = world.getChunkSource().getGeneratorState(); Map>> map = new Object2ObjectArrayMap(); Iterator iterator = structures.iterator(); -diff --git a/src/main/java/net/minecraft/world/level/levelgen/structure/Structure.java b/src/main/java/net/minecraft/world/level/levelgen/structure/Structure.java +diff --git a/src/main/java/org/bukkit/craftbukkit/CraftServer.java b/src/main/java/org/bukkit/craftbukkit/CraftServer.java index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 ---- a/src/main/java/net/minecraft/world/level/levelgen/structure/Structure.java -+++ b/src/main/java/net/minecraft/world/level/levelgen/structure/Structure.java -@@ -0,0 +0,0 @@ public abstract class Structure { - public static final Codec DIRECT_CODEC = BuiltInRegistries.STRUCTURE_TYPE.byNameCodec().dispatch(Structure::type, StructureType::codec); - public static final Codec> CODEC = RegistryFileCodec.create(Registries.STRUCTURE, DIRECT_CODEC); - protected final Structure.StructureSettings settings; -+ static { io.papermc.paper.world.structure.PaperConfiguredStructure.init(); } // Paper +--- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java ++++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java +@@ -0,0 +0,0 @@ public final class CraftServer implements Server { + this.structureManager = new CraftStructureManager(console.getStructureManager()); - public static RecordCodecBuilder settingsCodec(RecordCodecBuilder.Instance instance) { - return Structure.StructureSettings.CODEC.forGetter((feature) -> { + Bukkit.setServer(this); ++ io.papermc.paper.world.structure.PaperConfiguredStructure.init(); // Paper + + // Register all the Enchantments and PotionTypes now so we can stop new registration immediately after + Enchantments.SHARPNESS.getClass(); diff --git a/src/test/java/io/papermc/paper/world/structure/ConfiguredStructureTest.java b/src/test/java/io/papermc/paper/world/structure/ConfiguredStructureTest.java new file mode 100644 index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 diff --git a/patches/server/Test-changes.patch b/patches/server/Test-changes.patch index 9c8c50be8e..bb549025b2 100644 --- a/patches/server/Test-changes.patch +++ b/patches/server/Test-changes.patch @@ -130,13 +130,13 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 import net.minecraft.SharedConstants; import net.minecraft.commands.Commands; @@ -0,0 +0,0 @@ public abstract class AbstractTestingBase { - public static final Registry BIOMES; - - static { + LayeredRegistryAccess layers = RegistryLayer.createRegistryAccess(); + layers = WorldLoader.loadAndReplaceLayer(resourceManager, layers, RegistryLayer.WORLDGEN, RegistryDataLoader.WORLDGEN_REGISTRIES); + REGISTRY_CUSTOM = layers.compositeAccess().freeze(); + io.papermc.paper.testing.DummyServer.setup(); // Paper - SharedConstants.tryDetectVersion(); - Bootstrap.bootStrap(); - // Set up resource manager + // Register vanilla pack + DATA_PACK = ReloadableServerResources.loadResources(resourceManager, REGISTRY_CUSTOM, FeatureFlags.REGISTRY.allFlags(), Commands.CommandSelection.DEDICATED, 0, MoreExecutors.directExecutor(), MoreExecutors.directExecutor()).join(); + // Bind tags @@ -0,0 +0,0 @@ public abstract class AbstractTestingBase { // Biome shortcut BIOMES = REGISTRY_CUSTOM.registryOrThrow(Registries.BIOME);