diff options
Diffstat (limited to 'patches/server/0474-Add-RegistryAccess-for-managing-Registries.patch')
-rw-r--r-- | patches/server/0474-Add-RegistryAccess-for-managing-Registries.patch | 90 |
1 files changed, 61 insertions, 29 deletions
diff --git a/patches/server/0474-Add-RegistryAccess-for-managing-Registries.patch b/patches/server/0474-Add-RegistryAccess-for-managing-Registries.patch index 5a0885dc09..3b078d9e8b 100644 --- a/patches/server/0474-Add-RegistryAccess-for-managing-Registries.patch +++ b/patches/server/0474-Add-RegistryAccess-for-managing-Registries.patch @@ -12,10 +12,10 @@ 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..1e098dc25bd338ff179491ff3382ac56aad9948e +index 0000000000000000000000000000000000000000..ead718efde812846fefec3e86d896fef7deb3d97 --- /dev/null +++ b/src/main/java/io/papermc/paper/registry/PaperRegistries.java -@@ -0,0 +1,133 @@ +@@ -0,0 +1,141 @@ +package io.papermc.paper.registry; + +import io.papermc.paper.adventure.PaperAdventure; @@ -41,6 +41,9 @@ index 0000000000000000000000000000000000000000..1e098dc25bd338ff179491ff3382ac56 +import org.bukkit.craftbukkit.block.CraftBlockType; +import org.bukkit.craftbukkit.damage.CraftDamageType; +import org.bukkit.craftbukkit.enchantments.CraftEnchantment; ++import org.bukkit.craftbukkit.entity.CraftCat; ++import org.bukkit.craftbukkit.entity.CraftFrog; ++import org.bukkit.craftbukkit.entity.CraftVillager; +import org.bukkit.craftbukkit.entity.CraftWolf; +import org.bukkit.craftbukkit.generator.structure.CraftStructure; +import org.bukkit.craftbukkit.generator.structure.CraftStructureType; @@ -48,15 +51,20 @@ index 0000000000000000000000000000000000000000..1e098dc25bd338ff179491ff3382ac56 +import org.bukkit.craftbukkit.inventory.trim.CraftTrimMaterial; +import org.bukkit.craftbukkit.inventory.trim.CraftTrimPattern; +import org.bukkit.craftbukkit.legacy.FieldRename; ++import org.bukkit.craftbukkit.map.CraftMapCursor; +import org.bukkit.craftbukkit.potion.CraftPotionEffectType; +import org.bukkit.craftbukkit.util.CraftNamespacedKey; +import org.bukkit.damage.DamageType; ++import org.bukkit.entity.Cat; ++import org.bukkit.entity.Frog; ++import org.bukkit.entity.Villager; +import org.bukkit.entity.Wolf; +import org.bukkit.entity.memory.MemoryKey; +import org.bukkit.generator.structure.StructureType; +import org.bukkit.inventory.ItemType; +import org.bukkit.inventory.meta.trim.TrimMaterial; +import org.bukkit.inventory.meta.trim.TrimPattern; ++import org.bukkit.map.MapCursor; +import org.bukkit.potion.PotionEffectType; +import org.checkerframework.checker.nullness.qual.NonNull; +import org.checkerframework.checker.nullness.qual.Nullable; @@ -80,6 +88,11 @@ index 0000000000000000000000000000000000000000..1e098dc25bd338ff179491ff3382ac56 + entry(Registries.STRUCTURE_TYPE, RegistryKey.STRUCTURE_TYPE, StructureType.class, CraftStructureType::new), + entry(Registries.BLOCK, RegistryKey.BLOCK, BlockType.class, CraftBlockType::new), + entry(Registries.ITEM, RegistryKey.ITEM, ItemType.class, CraftItemType::new), ++ entry(Registries.CAT_VARIANT, RegistryKey.CAT_VARIANT, Cat.Type.class, CraftCat.CraftType::new), ++ entry(Registries.FROG_VARIANT, RegistryKey.FROG_VARIANT, Frog.Variant.class, CraftFrog.CraftVariant::new), ++ entry(Registries.VILLAGER_PROFESSION, RegistryKey.VILLAGER_PROFESSION, Villager.Profession.class, CraftVillager.CraftProfession::new), ++ entry(Registries.VILLAGER_TYPE, RegistryKey.VILLAGER_TYPE, Villager.Type.class, CraftVillager.CraftType::new), ++ entry(Registries.MAP_DECORATION_TYPE, RegistryKey.MAP_DECORATION_TYPE, MapCursor.Type.class, CraftMapCursor.CraftType::new), + + // data-drivens + entry(Registries.STRUCTURE, RegistryKey.STRUCTURE, Structure.class, CraftStructure::new).delayed(), @@ -95,17 +108,12 @@ index 0000000000000000000000000000000000000000..1e098dc25bd338ff179491ff3382ac56 + apiOnly(Registries.PAINTING_VARIANT, RegistryKey.PAINTING_VARIANT, () -> org.bukkit.Registry.ART), + apiOnly(Registries.ATTRIBUTE, RegistryKey.ATTRIBUTE, () -> org.bukkit.Registry.ATTRIBUTE), + apiOnly(Registries.BANNER_PATTERN, RegistryKey.BANNER_PATTERN, () -> org.bukkit.Registry.BANNER_PATTERN), -+ apiOnly(Registries.CAT_VARIANT, RegistryKey.CAT_VARIANT, () -> org.bukkit.Registry.CAT_VARIANT), + apiOnly(Registries.ENTITY_TYPE, RegistryKey.ENTITY_TYPE, () -> org.bukkit.Registry.ENTITY_TYPE), + apiOnly(Registries.PARTICLE_TYPE, RegistryKey.PARTICLE_TYPE, () -> org.bukkit.Registry.PARTICLE_TYPE), + apiOnly(Registries.POTION, RegistryKey.POTION, () -> org.bukkit.Registry.POTION), + apiOnly(Registries.SOUND_EVENT, RegistryKey.SOUND_EVENT, () -> org.bukkit.Registry.SOUNDS), -+ apiOnly(Registries.VILLAGER_PROFESSION, RegistryKey.VILLAGER_PROFESSION, () -> org.bukkit.Registry.VILLAGER_PROFESSION), -+ apiOnly(Registries.VILLAGER_TYPE, RegistryKey.VILLAGER_TYPE, () -> org.bukkit.Registry.VILLAGER_TYPE), + apiOnly(Registries.MEMORY_MODULE_TYPE, RegistryKey.MEMORY_MODULE_TYPE, () -> (org.bukkit.Registry<MemoryKey<?>>) (org.bukkit.Registry) org.bukkit.Registry.MEMORY_MODULE_TYPE), -+ apiOnly(Registries.FLUID, RegistryKey.FLUID, () -> org.bukkit.Registry.FLUID), -+ apiOnly(Registries.FROG_VARIANT, RegistryKey.FROG_VARIANT, () -> org.bukkit.Registry.FROG_VARIANT), -+ apiOnly(Registries.MAP_DECORATION_TYPE, RegistryKey.MAP_DECORATION_TYPE, () -> org.bukkit.Registry.MAP_DECORATION_TYPE) ++ apiOnly(Registries.FLUID, RegistryKey.FLUID, () -> org.bukkit.Registry.FLUID) + ); + final Map<RegistryKey<?>, RegistryEntry<?, ?>> byRegistryKey = new IdentityHashMap<>(REGISTRY_ENTRIES.size()); + final Map<ResourceKey<?>, RegistryEntry<?, ?>> byResourceKey = new IdentityHashMap<>(REGISTRY_ENTRIES.size()); @@ -719,10 +727,10 @@ index 1dd22f11b7e2983a3069dea94c0f02b43ff1f736..397bdacab9517354875ebc0bc68d3505 String string = Registries.elementsDirPath(type.registryKey()); SimpleJsonResourceReloadListener.scanDirectory(resourceManager, string, GSON, map); diff --git a/src/main/java/org/bukkit/craftbukkit/CraftRegistry.java b/src/main/java/org/bukkit/craftbukkit/CraftRegistry.java -index d129f7c15c143843429cf8a56fd1e52684531257..f8cf246913040ea4064f8addee0ec6927eb06237 100644 +index 10ce6b9f748b69283e03454e9b1ed0b7df379a17..002449e66f83a419afa8357d2e7192670eaf869e 100644 --- a/src/main/java/org/bukkit/craftbukkit/CraftRegistry.java +++ b/src/main/java/org/bukkit/craftbukkit/CraftRegistry.java -@@ -111,60 +111,12 @@ public class CraftRegistry<B extends Keyed, M> implements Registry<B> { +@@ -118,75 +118,12 @@ public class CraftRegistry<B extends Keyed, M> implements Registry<B> { + ", this can happen if a plugin creates its own registry entry with out properly registering it."); } @@ -750,7 +758,13 @@ index d129f7c15c143843429cf8a56fd1e52684531257..f8cf246913040ea4064f8addee0ec692 - return new CraftRegistry<>(Structure.class, registryHolder.registryOrThrow(Registries.STRUCTURE), CraftStructure::new, FieldRename.NONE); - } - if (bukkitClass == StructureType.class) { -- return new CraftRegistry<>(StructureType.class, BuiltInRegistries.STRUCTURE_TYPE, CraftStructureType::new, FieldRename.NONE); +- return new CraftRegistry<>(StructureType.class, registryHolder.registryOrThrow(Registries.STRUCTURE_TYPE), CraftStructureType::new, FieldRename.NONE); +- } +- if (bukkitClass == Villager.Type.class) { +- return new CraftRegistry<>(Villager.Type.class, registryHolder.registryOrThrow(Registries.VILLAGER_TYPE), CraftVillager.CraftType::new, FieldRename.NONE); +- } +- if (bukkitClass == Villager.Profession.class) { +- return new CraftRegistry<>(Villager.Profession.class, registryHolder.registryOrThrow(Registries.VILLAGER_PROFESSION), CraftVillager.CraftProfession::new, FieldRename.NONE); - } - if (bukkitClass == TrimMaterial.class) { - return new CraftRegistry<>(TrimMaterial.class, registryHolder.registryOrThrow(Registries.TRIM_MATERIAL), CraftTrimMaterial::new, FieldRename.NONE); @@ -773,6 +787,15 @@ index d129f7c15c143843429cf8a56fd1e52684531257..f8cf246913040ea4064f8addee0ec692 - if (bukkitClass == ItemType.class) { - return new CraftRegistry<>(ItemType.class, registryHolder.registryOrThrow(Registries.ITEM), CraftItemType::new, FieldRename.NONE); - } +- if (bukkitClass == Frog.Variant.class) { +- return new CraftRegistry<>(Frog.Variant.class, registryHolder.registryOrThrow(Registries.FROG_VARIANT), CraftFrog.CraftVariant::new, FieldRename.NONE); +- } +- if (bukkitClass == Cat.Type.class) { +- return new CraftRegistry<>(Cat.Type.class, registryHolder.registryOrThrow(Registries.CAT_VARIANT), CraftCat.CraftType::new, FieldRename.NONE); +- } +- if (bukkitClass == MapCursor.Type.class) { +- return new CraftRegistry<>(MapCursor.Type.class, registryHolder.registryOrThrow(Registries.MAP_DECORATION_TYPE), CraftMapCursor.CraftType::new, FieldRename.NONE); +- } - - return null; - } @@ -786,7 +809,7 @@ index d129f7c15c143843429cf8a56fd1e52684531257..f8cf246913040ea4064f8addee0ec692 } if (bukkit instanceof Registry.SimpleRegistry<?> simple) { -@@ -190,23 +142,21 @@ public class CraftRegistry<B extends Keyed, M> implements Registry<B> { +@@ -212,23 +149,21 @@ public class CraftRegistry<B extends Keyed, M> implements Registry<B> { return bukkit.get(namespacedKey); } @@ -816,7 +839,7 @@ index d129f7c15c143843429cf8a56fd1e52684531257..f8cf246913040ea4064f8addee0ec692 @Override public B get(NamespacedKey namespacedKey) { diff --git a/src/main/java/org/bukkit/craftbukkit/CraftServer.java b/src/main/java/org/bukkit/craftbukkit/CraftServer.java -index 92e0f1a948962d4c71f1288dfb8b482d3207cf4c..24c8e9a43affa8ca99c03562aefc3d6402c23281 100644 +index 856de462a5a92d00896b5454244014eae2cdbf24..10f99b75406176bc11947dde53d94a714d8d28e0 100644 --- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java +++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java @@ -281,7 +281,7 @@ public final class CraftServer implements Server { @@ -828,7 +851,7 @@ index 92e0f1a948962d4c71f1288dfb8b482d3207cf4c..24c8e9a43affa8ca99c03562aefc3d64 private YamlConfiguration configuration; private YamlConfiguration commandsConfiguration; private final Yaml yaml = new Yaml(new SafeConstructor(new LoaderOptions())); -@@ -2721,7 +2721,7 @@ public final class CraftServer implements Server { +@@ -2729,7 +2729,7 @@ public final class CraftServer implements Server { @Override public <T extends Keyed> Registry<T> getRegistry(Class<T> aClass) { @@ -838,11 +861,11 @@ index 92e0f1a948962d4c71f1288dfb8b482d3207cf4c..24c8e9a43affa8ca99c03562aefc3d64 @Deprecated diff --git a/src/main/java/org/bukkit/craftbukkit/legacy/FieldRename.java b/src/main/java/org/bukkit/craftbukkit/legacy/FieldRename.java -index d2eef51fb508a2cfc45ce8e11bb0fe0e89a24b0e..4ce818047911922857a5d5b377aa34ae0dfecba4 100644 +index 1f58b92c17d28e14621e8dc28042a5368f1f4a1f..ef80e6b4dff557daaab1b9fde4d8d40171017e6c 100644 --- a/src/main/java/org/bukkit/craftbukkit/legacy/FieldRename.java +++ b/src/main/java/org/bukkit/craftbukkit/legacy/FieldRename.java -@@ -56,11 +56,14 @@ public class FieldRename { - return Enum.valueOf(enumClass, FieldRename.rename(apiVersion, enumClass.getName().replace('.', '/'), name)); +@@ -51,11 +51,14 @@ public class FieldRename { + }; } - @RequireCompatibility("allow-old-keys-in-registry") @@ -852,11 +875,11 @@ index d2eef51fb508a2cfc45ce8e11bb0fe0e89a24b0e..4ce818047911922857a5d5b377aa34ae - } + // Paper start - absolutely not, having this as an expectation for plugin developers opens a huge + // can of worms in the future, especially if mojang comes back and reuses some old key -+ // @RequireCompatibility("allow-old-keys-in-registry") -+ // public static <T extends Keyed> T get(Registry<T> registry, NamespacedKey namespacedKey) { -+ // // We don't have version-specific changes, so just use current, and don't inject a version -+ // return CraftRegistry.get(registry, namespacedKey, ApiVersion.CURRENT); -+ // } ++ //@RequireCompatibility("allow-old-keys-in-registry") ++ //public static <T extends Keyed> T get(Registry<T> registry, NamespacedKey namespacedKey) { ++ // // We don't have version-specific changes, so just use current, and don't inject a version ++ // return CraftRegistry.get(registry, namespacedKey, ApiVersion.CURRENT); ++ //} + // Paper end // PatternType @@ -869,18 +892,17 @@ index 0000000000000000000000000000000000000000..8a083d45004f82fc9c51c219fb20f346 @@ -0,0 +1 @@ +io.papermc.paper.registry.PaperRegistryAccess diff --git a/src/main/resources/configurations/bukkit.yml b/src/main/resources/configurations/bukkit.yml -index 6615fffc4cbeee971f2b0f918cb8a9fd1fac2430..eef7c125b2689f29cae5464659eacdf33f5695b2 100644 +index 543e37737bc6fdca23ed9ed0606805d345515a5a..818a1d2e152e45a28aa5b0d1acd0e6dc300d9054 100644 --- a/src/main/resources/configurations/bukkit.yml +++ b/src/main/resources/configurations/bukkit.yml -@@ -23,8 +23,6 @@ settings: - shutdown-message: Server closed +@@ -24,7 +24,6 @@ settings: minimum-api: none use-map-color-cache: true -- compatibility: + compatibility: - allow-old-keys-in-registry: false + enum-compatibility-mode: false spawn-limits: monsters: 70 - animals: 10 diff --git a/src/test/java/io/papermc/paper/registry/LegacyRegistryIdentifierTest.java b/src/test/java/io/papermc/paper/registry/LegacyRegistryIdentifierTest.java new file mode 100644 index 0000000000000000000000000000000000000000..b9d00e65639521eecd44bd2be3e012264c3785f5 @@ -1084,7 +1106,7 @@ index bfbd80b60ac5df500d03c80de57e38aa7548dd46..cce9e2226ef554c10e1df1dbaa179165 when(instance.getTag(any(), any(), any())).then(mock -> { String registry = mock.getArgument(0); diff --git a/src/test/java/org/bukkit/support/provider/RegistriesArgumentProvider.java b/src/test/java/org/bukkit/support/provider/RegistriesArgumentProvider.java -index 23819f05563a1d8c9f13335bc9a77964e3f8b7c6..a480944e1fc1b79b91be7e8d3e3799b9168cf5a0 100644 +index b4d2546094a154af8fca2f63d02090ed9cb355a5..38b0e091234a00d57e9e9d4fb3eac6afb7343477 100644 --- a/src/test/java/org/bukkit/support/provider/RegistriesArgumentProvider.java +++ b/src/test/java/org/bukkit/support/provider/RegistriesArgumentProvider.java @@ -1,6 +1,7 @@ @@ -1095,7 +1117,7 @@ index 23819f05563a1d8c9f13335bc9a77964e3f8b7c6..a480944e1fc1b79b91be7e8d3e3799b9 import java.util.List; import java.util.stream.Stream; import net.minecraft.core.registries.Registries; -@@ -43,29 +44,29 @@ public class RegistriesArgumentProvider implements ArgumentsProvider { +@@ -56,34 +57,34 @@ public class RegistriesArgumentProvider implements ArgumentsProvider { private static final List<Arguments> DATA = Lists.newArrayList(); static { @@ -1106,6 +1128,8 @@ index 23819f05563a1d8c9f13335bc9a77964e3f8b7c6..a480944e1fc1b79b91be7e8d3e3799b9 - register(PotionEffectType.class, Registries.MOB_EFFECT, CraftPotionEffectType.class, MobEffect.class); - register(Structure.class, Registries.STRUCTURE, CraftStructure.class, net.minecraft.world.level.levelgen.structure.Structure.class); - register(StructureType.class, Registries.STRUCTURE_TYPE, CraftStructureType.class, net.minecraft.world.level.levelgen.structure.StructureType.class); +- register(Villager.Type.class, Registries.VILLAGER_TYPE, CraftVillager.CraftType.class, VillagerType.class); +- register(Villager.Profession.class, Registries.VILLAGER_PROFESSION, CraftVillager.CraftProfession.class, VillagerProfession.class); - register(TrimMaterial.class, Registries.TRIM_MATERIAL, CraftTrimMaterial.class, net.minecraft.world.item.armortrim.TrimMaterial.class); - register(TrimPattern.class, Registries.TRIM_PATTERN, CraftTrimPattern.class, net.minecraft.world.item.armortrim.TrimPattern.class); - register(DamageType.class, Registries.DAMAGE_TYPE, CraftDamageType.class, net.minecraft.world.damagesource.DamageType.class); @@ -1113,6 +1137,9 @@ index 23819f05563a1d8c9f13335bc9a77964e3f8b7c6..a480944e1fc1b79b91be7e8d3e3799b9 - register(Wolf.Variant.class, Registries.WOLF_VARIANT, CraftWolf.CraftVariant.class, WolfVariant.class); - register(ItemType.class, Registries.ITEM, CraftItemType.class, net.minecraft.world.item.Item.class, true); - register(BlockType.class, Registries.BLOCK, CraftBlockType.class, net.minecraft.world.level.block.Block.class, true); +- register(Frog.Variant.class, Registries.FROG_VARIANT, CraftFrog.CraftVariant.class, FrogVariant.class); +- register(Cat.Type.class, Registries.CAT_VARIANT, CraftCat.CraftType.class, CatVariant.class); +- register(MapCursor.Type.class, Registries.MAP_DECORATION_TYPE, CraftMapCursor.CraftType.class, MapDecorationType.class); + // Order: RegistryKey, Bukkit class, Minecraft Registry key, CraftBukkit class, Minecraft class + register(RegistryKey.ENCHANTMENT, Enchantment.class, Registries.ENCHANTMENT, CraftEnchantment.class, net.minecraft.world.item.enchantment.Enchantment.class); + register(RegistryKey.GAME_EVENT, GameEvent.class, Registries.GAME_EVENT, CraftGameEvent.class, net.minecraft.world.level.gameevent.GameEvent.class); @@ -1120,6 +1147,8 @@ index 23819f05563a1d8c9f13335bc9a77964e3f8b7c6..a480944e1fc1b79b91be7e8d3e3799b9 + register(RegistryKey.MOB_EFFECT, PotionEffectType.class, Registries.MOB_EFFECT, CraftPotionEffectType.class, MobEffect.class); + register(RegistryKey.STRUCTURE, Structure.class, Registries.STRUCTURE, CraftStructure.class, net.minecraft.world.level.levelgen.structure.Structure.class); + register(RegistryKey.STRUCTURE_TYPE, StructureType.class, Registries.STRUCTURE_TYPE, CraftStructureType.class, net.minecraft.world.level.levelgen.structure.StructureType.class); ++ register(RegistryKey.VILLAGER_TYPE, Villager.Type.class, Registries.VILLAGER_TYPE, CraftVillager.CraftType.class, VillagerType.class); ++ register(RegistryKey.VILLAGER_PROFESSION, Villager.Profession.class, Registries.VILLAGER_PROFESSION, CraftVillager.CraftProfession.class, VillagerProfession.class); + register(RegistryKey.TRIM_MATERIAL, TrimMaterial.class, Registries.TRIM_MATERIAL, CraftTrimMaterial.class, net.minecraft.world.item.armortrim.TrimMaterial.class); + register(RegistryKey.TRIM_PATTERN, TrimPattern.class, Registries.TRIM_PATTERN, CraftTrimPattern.class, net.minecraft.world.item.armortrim.TrimPattern.class); + register(RegistryKey.DAMAGE_TYPE, DamageType.class, Registries.DAMAGE_TYPE, CraftDamageType.class, net.minecraft.world.damagesource.DamageType.class); @@ -1127,6 +1156,9 @@ index 23819f05563a1d8c9f13335bc9a77964e3f8b7c6..a480944e1fc1b79b91be7e8d3e3799b9 + register(RegistryKey.WOLF_VARIANT, Wolf.Variant.class, Registries.WOLF_VARIANT, CraftWolf.CraftVariant.class, WolfVariant.class); + register(RegistryKey.ITEM, ItemType.class, Registries.ITEM, CraftItemType.class, net.minecraft.world.item.Item.class, true); + register(RegistryKey.BLOCK, BlockType.class, Registries.BLOCK, CraftBlockType.class, net.minecraft.world.level.block.Block.class, true); ++ register(RegistryKey.FROG_VARIANT, Frog.Variant.class, Registries.FROG_VARIANT, CraftFrog.CraftVariant.class, FrogVariant.class); ++ register(RegistryKey.CAT_VARIANT, Cat.Type.class, Registries.CAT_VARIANT, CraftCat.CraftType.class, CatVariant.class); ++ register(RegistryKey.MAP_DECORATION_TYPE, MapCursor.Type.class, Registries.MAP_DECORATION_TYPE, CraftMapCursor.CraftType.class, MapDecorationType.class); } |