From ade5611624a00c33b983957181f19f55b66d1ef1 Mon Sep 17 00:00:00 2001 From: Lulu13022002 <41980282+Lulu13022002@users.noreply.github.com> Date: Sat, 28 Feb 2026 22:59:12 +0100 Subject: [PATCH 1/6] Implement entity type registry --- .../paper/registry/keys/EntityTypeKeys.java | 1133 +++++++++++++++++ .../registry/keys/tags/EntityTypeTagKeys.java | 94 +- .../java/co/aikar/timings/TimingHistory.java | 35 +- .../io/papermc/paper/InternalAPIBridge.java | 10 + .../paper/datacomponent/item/Equippable.java | 4 +- .../papermc/paper/registry/RegistryKey.java | 6 +- .../java/io/papermc/paper/tag/BaseTag.java | 2 +- .../io/papermc/paper/tag/EntitySetTag.java | 4 +- .../src/main/java/org/bukkit/Registry.java | 2 +- .../main/java/org/bukkit/UnsafeValues.java | 22 +- .../src/main/java/org/bukkit/block/Biome.java | 7 - .../java/org/bukkit/entity/EntityType.java | 619 +++++---- .../org/bukkit/entity/boat/AcaciaBoat.java | 1 + .../bukkit/entity/boat/AcaciaChestBoat.java | 1 + .../bukkit/entity/boat/BambooChestRaft.java | 1 + .../org/bukkit/entity/boat/BambooRaft.java | 1 + .../org/bukkit/entity/boat/BirchBoat.java | 1 + .../bukkit/entity/boat/BirchChestBoat.java | 1 + .../org/bukkit/entity/boat/CherryBoat.java | 1 + .../bukkit/entity/boat/CherryChestBoat.java | 1 + .../org/bukkit/entity/boat/DarkOakBoat.java | 1 + .../bukkit/entity/boat/DarkOakChestBoat.java | 1 + .../org/bukkit/entity/boat/JungleBoat.java | 1 + .../bukkit/entity/boat/JungleChestBoat.java | 1 + .../org/bukkit/entity/boat/MangroveBoat.java | 1 + .../bukkit/entity/boat/MangroveChestBoat.java | 1 + .../java/org/bukkit/entity/boat/OakBoat.java | 1 + .../org/bukkit/entity/boat/OakChestBoat.java | 1 + .../org/bukkit/entity/boat/PaleOakBoat.java | 1 + .../bukkit/entity/boat/PaleOakChestBoat.java | 1 + .../org/bukkit/entity/boat/SpruceBoat.java | 1 + .../bukkit/entity/boat/SpruceChestBoat.java | 1 + .../org/bukkit/entity/boat/package-info.java | 1 + .../event/player/PlayerEggThrowEvent.java | 4 +- .../meta/components/EquippableComponent.java | 2 +- .../bukkit/support/AbstractTestingBase.java | 13 - .../java/org/bukkit/support/TestServer.java | 63 - .../java/io/papermc/generator/Rewriters.java | 2 +- .../registry/RegistryBootstrapper.java | 4 - .../generator/registry/RegistryEntries.java | 4 +- .../types/simple/EntityTypeRewriter.java | 121 +- .../paper/PaperServerInternalAPIBridge.java | 12 +- .../datacomponent/item/PaperEquippable.java | 4 +- .../paper/registry/PaperRegistries.java | 4 +- .../paper/registry/PaperSimpleRegistry.java | 5 - .../flag/PaperFeatureFlagProviderImpl.java | 7 +- .../org/bukkit/craftbukkit/CraftRegistry.java | 4 - .../bukkit/craftbukkit/block/CraftBiome.java | 25 +- .../craftbukkit/entity/CraftEntityType.java | 292 ++++- .../craftbukkit/event/CraftEventFactory.java | 38 +- .../components/CraftEquippableComponent.java | 11 +- .../craftbukkit/util/CraftMagicNumbers.java | 22 +- .../test/java/org/bukkit}/CriteriaTest.java | 16 +- .../craftbukkit/entity/EntityTypesTest.java | 14 +- .../org/bukkit/entity/EntityTypesTest.java | 20 - .../provider/RegistriesArgumentProvider.java | 9 +- 56 files changed, 1985 insertions(+), 670 deletions(-) create mode 100644 paper-api/src/generated/java/io/papermc/paper/registry/keys/EntityTypeKeys.java delete mode 100644 paper-api/src/test/java/org/bukkit/support/AbstractTestingBase.java delete mode 100644 paper-api/src/test/java/org/bukkit/support/TestServer.java rename {paper-api/src/test/java/org/bukkit/scoreboard => paper-server/src/test/java/org/bukkit}/CriteriaTest.java (81%) delete mode 100644 paper-server/src/test/java/org/bukkit/entity/EntityTypesTest.java diff --git a/paper-api/src/generated/java/io/papermc/paper/registry/keys/EntityTypeKeys.java b/paper-api/src/generated/java/io/papermc/paper/registry/keys/EntityTypeKeys.java new file mode 100644 index 000000000000..cfa3f0f4e282 --- /dev/null +++ b/paper-api/src/generated/java/io/papermc/paper/registry/keys/EntityTypeKeys.java @@ -0,0 +1,1133 @@ +package io.papermc.paper.registry.keys; + +import static net.kyori.adventure.key.Key.key; + +import io.papermc.paper.annotation.GeneratedClass; +import io.papermc.paper.registry.RegistryKey; +import io.papermc.paper.registry.TypedKey; +import net.kyori.adventure.key.Key; +import org.bukkit.entity.EntityType; +import org.jspecify.annotations.NullMarked; + +/** + * Vanilla keys for {@link RegistryKey#ENTITY_TYPE}. + * + * @apiNote The fields provided here are a direct representation of + * what is available from the vanilla game source. They may be + * changed (including removals) on any Minecraft version + * bump, so cross-version compatibility is not provided on the + * same level as it is on most of the other API. + */ +@SuppressWarnings({ + "unused", + "SpellCheckingInspection" +}) +@NullMarked +@GeneratedClass +public final class EntityTypeKeys { + /** + * {@code minecraft:acacia_boat} + * + * @apiNote This field is version-dependant and may be removed in future Minecraft versions + */ + public static final TypedKey> ACACIA_BOAT = create(key("acacia_boat")); + + /** + * {@code minecraft:acacia_chest_boat} + * + * @apiNote This field is version-dependant and may be removed in future Minecraft versions + */ + public static final TypedKey> ACACIA_CHEST_BOAT = create(key("acacia_chest_boat")); + + /** + * {@code minecraft:allay} + * + * @apiNote This field is version-dependant and may be removed in future Minecraft versions + */ + public static final TypedKey> ALLAY = create(key("allay")); + + /** + * {@code minecraft:area_effect_cloud} + * + * @apiNote This field is version-dependant and may be removed in future Minecraft versions + */ + public static final TypedKey> AREA_EFFECT_CLOUD = create(key("area_effect_cloud")); + + /** + * {@code minecraft:armadillo} + * + * @apiNote This field is version-dependant and may be removed in future Minecraft versions + */ + public static final TypedKey> ARMADILLO = create(key("armadillo")); + + /** + * {@code minecraft:armor_stand} + * + * @apiNote This field is version-dependant and may be removed in future Minecraft versions + */ + public static final TypedKey> ARMOR_STAND = create(key("armor_stand")); + + /** + * {@code minecraft:arrow} + * + * @apiNote This field is version-dependant and may be removed in future Minecraft versions + */ + public static final TypedKey> ARROW = create(key("arrow")); + + /** + * {@code minecraft:axolotl} + * + * @apiNote This field is version-dependant and may be removed in future Minecraft versions + */ + public static final TypedKey> AXOLOTL = create(key("axolotl")); + + /** + * {@code minecraft:bamboo_chest_raft} + * + * @apiNote This field is version-dependant and may be removed in future Minecraft versions + */ + public static final TypedKey> BAMBOO_CHEST_RAFT = create(key("bamboo_chest_raft")); + + /** + * {@code minecraft:bamboo_raft} + * + * @apiNote This field is version-dependant and may be removed in future Minecraft versions + */ + public static final TypedKey> BAMBOO_RAFT = create(key("bamboo_raft")); + + /** + * {@code minecraft:bat} + * + * @apiNote This field is version-dependant and may be removed in future Minecraft versions + */ + public static final TypedKey> BAT = create(key("bat")); + + /** + * {@code minecraft:bee} + * + * @apiNote This field is version-dependant and may be removed in future Minecraft versions + */ + public static final TypedKey> BEE = create(key("bee")); + + /** + * {@code minecraft:birch_boat} + * + * @apiNote This field is version-dependant and may be removed in future Minecraft versions + */ + public static final TypedKey> BIRCH_BOAT = create(key("birch_boat")); + + /** + * {@code minecraft:birch_chest_boat} + * + * @apiNote This field is version-dependant and may be removed in future Minecraft versions + */ + public static final TypedKey> BIRCH_CHEST_BOAT = create(key("birch_chest_boat")); + + /** + * {@code minecraft:blaze} + * + * @apiNote This field is version-dependant and may be removed in future Minecraft versions + */ + public static final TypedKey> BLAZE = create(key("blaze")); + + /** + * {@code minecraft:block_display} + * + * @apiNote This field is version-dependant and may be removed in future Minecraft versions + */ + public static final TypedKey> BLOCK_DISPLAY = create(key("block_display")); + + /** + * {@code minecraft:bogged} + * + * @apiNote This field is version-dependant and may be removed in future Minecraft versions + */ + public static final TypedKey> BOGGED = create(key("bogged")); + + /** + * {@code minecraft:breeze} + * + * @apiNote This field is version-dependant and may be removed in future Minecraft versions + */ + public static final TypedKey> BREEZE = create(key("breeze")); + + /** + * {@code minecraft:breeze_wind_charge} + * + * @apiNote This field is version-dependant and may be removed in future Minecraft versions + */ + public static final TypedKey> BREEZE_WIND_CHARGE = create(key("breeze_wind_charge")); + + /** + * {@code minecraft:camel} + * + * @apiNote This field is version-dependant and may be removed in future Minecraft versions + */ + public static final TypedKey> CAMEL = create(key("camel")); + + /** + * {@code minecraft:camel_husk} + * + * @apiNote This field is version-dependant and may be removed in future Minecraft versions + */ + public static final TypedKey> CAMEL_HUSK = create(key("camel_husk")); + + /** + * {@code minecraft:cat} + * + * @apiNote This field is version-dependant and may be removed in future Minecraft versions + */ + public static final TypedKey> CAT = create(key("cat")); + + /** + * {@code minecraft:cave_spider} + * + * @apiNote This field is version-dependant and may be removed in future Minecraft versions + */ + public static final TypedKey> CAVE_SPIDER = create(key("cave_spider")); + + /** + * {@code minecraft:cherry_boat} + * + * @apiNote This field is version-dependant and may be removed in future Minecraft versions + */ + public static final TypedKey> CHERRY_BOAT = create(key("cherry_boat")); + + /** + * {@code minecraft:cherry_chest_boat} + * + * @apiNote This field is version-dependant and may be removed in future Minecraft versions + */ + public static final TypedKey> CHERRY_CHEST_BOAT = create(key("cherry_chest_boat")); + + /** + * {@code minecraft:chest_minecart} + * + * @apiNote This field is version-dependant and may be removed in future Minecraft versions + */ + public static final TypedKey> CHEST_MINECART = create(key("chest_minecart")); + + /** + * {@code minecraft:chicken} + * + * @apiNote This field is version-dependant and may be removed in future Minecraft versions + */ + public static final TypedKey> CHICKEN = create(key("chicken")); + + /** + * {@code minecraft:cod} + * + * @apiNote This field is version-dependant and may be removed in future Minecraft versions + */ + public static final TypedKey> COD = create(key("cod")); + + /** + * {@code minecraft:command_block_minecart} + * + * @apiNote This field is version-dependant and may be removed in future Minecraft versions + */ + public static final TypedKey> COMMAND_BLOCK_MINECART = create(key("command_block_minecart")); + + /** + * {@code minecraft:copper_golem} + * + * @apiNote This field is version-dependant and may be removed in future Minecraft versions + */ + public static final TypedKey> COPPER_GOLEM = create(key("copper_golem")); + + /** + * {@code minecraft:cow} + * + * @apiNote This field is version-dependant and may be removed in future Minecraft versions + */ + public static final TypedKey> COW = create(key("cow")); + + /** + * {@code minecraft:creaking} + * + * @apiNote This field is version-dependant and may be removed in future Minecraft versions + */ + public static final TypedKey> CREAKING = create(key("creaking")); + + /** + * {@code minecraft:creeper} + * + * @apiNote This field is version-dependant and may be removed in future Minecraft versions + */ + public static final TypedKey> CREEPER = create(key("creeper")); + + /** + * {@code minecraft:dark_oak_boat} + * + * @apiNote This field is version-dependant and may be removed in future Minecraft versions + */ + public static final TypedKey> DARK_OAK_BOAT = create(key("dark_oak_boat")); + + /** + * {@code minecraft:dark_oak_chest_boat} + * + * @apiNote This field is version-dependant and may be removed in future Minecraft versions + */ + public static final TypedKey> DARK_OAK_CHEST_BOAT = create(key("dark_oak_chest_boat")); + + /** + * {@code minecraft:dolphin} + * + * @apiNote This field is version-dependant and may be removed in future Minecraft versions + */ + public static final TypedKey> DOLPHIN = create(key("dolphin")); + + /** + * {@code minecraft:donkey} + * + * @apiNote This field is version-dependant and may be removed in future Minecraft versions + */ + public static final TypedKey> DONKEY = create(key("donkey")); + + /** + * {@code minecraft:dragon_fireball} + * + * @apiNote This field is version-dependant and may be removed in future Minecraft versions + */ + public static final TypedKey> DRAGON_FIREBALL = create(key("dragon_fireball")); + + /** + * {@code minecraft:drowned} + * + * @apiNote This field is version-dependant and may be removed in future Minecraft versions + */ + public static final TypedKey> DROWNED = create(key("drowned")); + + /** + * {@code minecraft:egg} + * + * @apiNote This field is version-dependant and may be removed in future Minecraft versions + */ + public static final TypedKey> EGG = create(key("egg")); + + /** + * {@code minecraft:elder_guardian} + * + * @apiNote This field is version-dependant and may be removed in future Minecraft versions + */ + public static final TypedKey> ELDER_GUARDIAN = create(key("elder_guardian")); + + /** + * {@code minecraft:end_crystal} + * + * @apiNote This field is version-dependant and may be removed in future Minecraft versions + */ + public static final TypedKey> END_CRYSTAL = create(key("end_crystal")); + + /** + * {@code minecraft:ender_dragon} + * + * @apiNote This field is version-dependant and may be removed in future Minecraft versions + */ + public static final TypedKey> ENDER_DRAGON = create(key("ender_dragon")); + + /** + * {@code minecraft:ender_pearl} + * + * @apiNote This field is version-dependant and may be removed in future Minecraft versions + */ + public static final TypedKey> ENDER_PEARL = create(key("ender_pearl")); + + /** + * {@code minecraft:enderman} + * + * @apiNote This field is version-dependant and may be removed in future Minecraft versions + */ + public static final TypedKey> ENDERMAN = create(key("enderman")); + + /** + * {@code minecraft:endermite} + * + * @apiNote This field is version-dependant and may be removed in future Minecraft versions + */ + public static final TypedKey> ENDERMITE = create(key("endermite")); + + /** + * {@code minecraft:evoker} + * + * @apiNote This field is version-dependant and may be removed in future Minecraft versions + */ + public static final TypedKey> EVOKER = create(key("evoker")); + + /** + * {@code minecraft:evoker_fangs} + * + * @apiNote This field is version-dependant and may be removed in future Minecraft versions + */ + public static final TypedKey> EVOKER_FANGS = create(key("evoker_fangs")); + + /** + * {@code minecraft:experience_bottle} + * + * @apiNote This field is version-dependant and may be removed in future Minecraft versions + */ + public static final TypedKey> EXPERIENCE_BOTTLE = create(key("experience_bottle")); + + /** + * {@code minecraft:experience_orb} + * + * @apiNote This field is version-dependant and may be removed in future Minecraft versions + */ + public static final TypedKey> EXPERIENCE_ORB = create(key("experience_orb")); + + /** + * {@code minecraft:eye_of_ender} + * + * @apiNote This field is version-dependant and may be removed in future Minecraft versions + */ + public static final TypedKey> EYE_OF_ENDER = create(key("eye_of_ender")); + + /** + * {@code minecraft:falling_block} + * + * @apiNote This field is version-dependant and may be removed in future Minecraft versions + */ + public static final TypedKey> FALLING_BLOCK = create(key("falling_block")); + + /** + * {@code minecraft:fireball} + * + * @apiNote This field is version-dependant and may be removed in future Minecraft versions + */ + public static final TypedKey> FIREBALL = create(key("fireball")); + + /** + * {@code minecraft:firework_rocket} + * + * @apiNote This field is version-dependant and may be removed in future Minecraft versions + */ + public static final TypedKey> FIREWORK_ROCKET = create(key("firework_rocket")); + + /** + * {@code minecraft:fishing_bobber} + * + * @apiNote This field is version-dependant and may be removed in future Minecraft versions + */ + public static final TypedKey> FISHING_BOBBER = create(key("fishing_bobber")); + + /** + * {@code minecraft:fox} + * + * @apiNote This field is version-dependant and may be removed in future Minecraft versions + */ + public static final TypedKey> FOX = create(key("fox")); + + /** + * {@code minecraft:frog} + * + * @apiNote This field is version-dependant and may be removed in future Minecraft versions + */ + public static final TypedKey> FROG = create(key("frog")); + + /** + * {@code minecraft:furnace_minecart} + * + * @apiNote This field is version-dependant and may be removed in future Minecraft versions + */ + public static final TypedKey> FURNACE_MINECART = create(key("furnace_minecart")); + + /** + * {@code minecraft:ghast} + * + * @apiNote This field is version-dependant and may be removed in future Minecraft versions + */ + public static final TypedKey> GHAST = create(key("ghast")); + + /** + * {@code minecraft:giant} + * + * @apiNote This field is version-dependant and may be removed in future Minecraft versions + */ + public static final TypedKey> GIANT = create(key("giant")); + + /** + * {@code minecraft:glow_item_frame} + * + * @apiNote This field is version-dependant and may be removed in future Minecraft versions + */ + public static final TypedKey> GLOW_ITEM_FRAME = create(key("glow_item_frame")); + + /** + * {@code minecraft:glow_squid} + * + * @apiNote This field is version-dependant and may be removed in future Minecraft versions + */ + public static final TypedKey> GLOW_SQUID = create(key("glow_squid")); + + /** + * {@code minecraft:goat} + * + * @apiNote This field is version-dependant and may be removed in future Minecraft versions + */ + public static final TypedKey> GOAT = create(key("goat")); + + /** + * {@code minecraft:guardian} + * + * @apiNote This field is version-dependant and may be removed in future Minecraft versions + */ + public static final TypedKey> GUARDIAN = create(key("guardian")); + + /** + * {@code minecraft:happy_ghast} + * + * @apiNote This field is version-dependant and may be removed in future Minecraft versions + */ + public static final TypedKey> HAPPY_GHAST = create(key("happy_ghast")); + + /** + * {@code minecraft:hoglin} + * + * @apiNote This field is version-dependant and may be removed in future Minecraft versions + */ + public static final TypedKey> HOGLIN = create(key("hoglin")); + + /** + * {@code minecraft:hopper_minecart} + * + * @apiNote This field is version-dependant and may be removed in future Minecraft versions + */ + public static final TypedKey> HOPPER_MINECART = create(key("hopper_minecart")); + + /** + * {@code minecraft:horse} + * + * @apiNote This field is version-dependant and may be removed in future Minecraft versions + */ + public static final TypedKey> HORSE = create(key("horse")); + + /** + * {@code minecraft:husk} + * + * @apiNote This field is version-dependant and may be removed in future Minecraft versions + */ + public static final TypedKey> HUSK = create(key("husk")); + + /** + * {@code minecraft:illusioner} + * + * @apiNote This field is version-dependant and may be removed in future Minecraft versions + */ + public static final TypedKey> ILLUSIONER = create(key("illusioner")); + + /** + * {@code minecraft:interaction} + * + * @apiNote This field is version-dependant and may be removed in future Minecraft versions + */ + public static final TypedKey> INTERACTION = create(key("interaction")); + + /** + * {@code minecraft:iron_golem} + * + * @apiNote This field is version-dependant and may be removed in future Minecraft versions + */ + public static final TypedKey> IRON_GOLEM = create(key("iron_golem")); + + /** + * {@code minecraft:item} + * + * @apiNote This field is version-dependant and may be removed in future Minecraft versions + */ + public static final TypedKey> ITEM = create(key("item")); + + /** + * {@code minecraft:item_display} + * + * @apiNote This field is version-dependant and may be removed in future Minecraft versions + */ + public static final TypedKey> ITEM_DISPLAY = create(key("item_display")); + + /** + * {@code minecraft:item_frame} + * + * @apiNote This field is version-dependant and may be removed in future Minecraft versions + */ + public static final TypedKey> ITEM_FRAME = create(key("item_frame")); + + /** + * {@code minecraft:jungle_boat} + * + * @apiNote This field is version-dependant and may be removed in future Minecraft versions + */ + public static final TypedKey> JUNGLE_BOAT = create(key("jungle_boat")); + + /** + * {@code minecraft:jungle_chest_boat} + * + * @apiNote This field is version-dependant and may be removed in future Minecraft versions + */ + public static final TypedKey> JUNGLE_CHEST_BOAT = create(key("jungle_chest_boat")); + + /** + * {@code minecraft:leash_knot} + * + * @apiNote This field is version-dependant and may be removed in future Minecraft versions + */ + public static final TypedKey> LEASH_KNOT = create(key("leash_knot")); + + /** + * {@code minecraft:lightning_bolt} + * + * @apiNote This field is version-dependant and may be removed in future Minecraft versions + */ + public static final TypedKey> LIGHTNING_BOLT = create(key("lightning_bolt")); + + /** + * {@code minecraft:lingering_potion} + * + * @apiNote This field is version-dependant and may be removed in future Minecraft versions + */ + public static final TypedKey> LINGERING_POTION = create(key("lingering_potion")); + + /** + * {@code minecraft:llama} + * + * @apiNote This field is version-dependant and may be removed in future Minecraft versions + */ + public static final TypedKey> LLAMA = create(key("llama")); + + /** + * {@code minecraft:llama_spit} + * + * @apiNote This field is version-dependant and may be removed in future Minecraft versions + */ + public static final TypedKey> LLAMA_SPIT = create(key("llama_spit")); + + /** + * {@code minecraft:magma_cube} + * + * @apiNote This field is version-dependant and may be removed in future Minecraft versions + */ + public static final TypedKey> MAGMA_CUBE = create(key("magma_cube")); + + /** + * {@code minecraft:mangrove_boat} + * + * @apiNote This field is version-dependant and may be removed in future Minecraft versions + */ + public static final TypedKey> MANGROVE_BOAT = create(key("mangrove_boat")); + + /** + * {@code minecraft:mangrove_chest_boat} + * + * @apiNote This field is version-dependant and may be removed in future Minecraft versions + */ + public static final TypedKey> MANGROVE_CHEST_BOAT = create(key("mangrove_chest_boat")); + + /** + * {@code minecraft:mannequin} + * + * @apiNote This field is version-dependant and may be removed in future Minecraft versions + */ + public static final TypedKey> MANNEQUIN = create(key("mannequin")); + + /** + * {@code minecraft:marker} + * + * @apiNote This field is version-dependant and may be removed in future Minecraft versions + */ + public static final TypedKey> MARKER = create(key("marker")); + + /** + * {@code minecraft:minecart} + * + * @apiNote This field is version-dependant and may be removed in future Minecraft versions + */ + public static final TypedKey> MINECART = create(key("minecart")); + + /** + * {@code minecraft:mooshroom} + * + * @apiNote This field is version-dependant and may be removed in future Minecraft versions + */ + public static final TypedKey> MOOSHROOM = create(key("mooshroom")); + + /** + * {@code minecraft:mule} + * + * @apiNote This field is version-dependant and may be removed in future Minecraft versions + */ + public static final TypedKey> MULE = create(key("mule")); + + /** + * {@code minecraft:nautilus} + * + * @apiNote This field is version-dependant and may be removed in future Minecraft versions + */ + public static final TypedKey> NAUTILUS = create(key("nautilus")); + + /** + * {@code minecraft:oak_boat} + * + * @apiNote This field is version-dependant and may be removed in future Minecraft versions + */ + public static final TypedKey> OAK_BOAT = create(key("oak_boat")); + + /** + * {@code minecraft:oak_chest_boat} + * + * @apiNote This field is version-dependant and may be removed in future Minecraft versions + */ + public static final TypedKey> OAK_CHEST_BOAT = create(key("oak_chest_boat")); + + /** + * {@code minecraft:ocelot} + * + * @apiNote This field is version-dependant and may be removed in future Minecraft versions + */ + public static final TypedKey> OCELOT = create(key("ocelot")); + + /** + * {@code minecraft:ominous_item_spawner} + * + * @apiNote This field is version-dependant and may be removed in future Minecraft versions + */ + public static final TypedKey> OMINOUS_ITEM_SPAWNER = create(key("ominous_item_spawner")); + + /** + * {@code minecraft:painting} + * + * @apiNote This field is version-dependant and may be removed in future Minecraft versions + */ + public static final TypedKey> PAINTING = create(key("painting")); + + /** + * {@code minecraft:pale_oak_boat} + * + * @apiNote This field is version-dependant and may be removed in future Minecraft versions + */ + public static final TypedKey> PALE_OAK_BOAT = create(key("pale_oak_boat")); + + /** + * {@code minecraft:pale_oak_chest_boat} + * + * @apiNote This field is version-dependant and may be removed in future Minecraft versions + */ + public static final TypedKey> PALE_OAK_CHEST_BOAT = create(key("pale_oak_chest_boat")); + + /** + * {@code minecraft:panda} + * + * @apiNote This field is version-dependant and may be removed in future Minecraft versions + */ + public static final TypedKey> PANDA = create(key("panda")); + + /** + * {@code minecraft:parched} + * + * @apiNote This field is version-dependant and may be removed in future Minecraft versions + */ + public static final TypedKey> PARCHED = create(key("parched")); + + /** + * {@code minecraft:parrot} + * + * @apiNote This field is version-dependant and may be removed in future Minecraft versions + */ + public static final TypedKey> PARROT = create(key("parrot")); + + /** + * {@code minecraft:phantom} + * + * @apiNote This field is version-dependant and may be removed in future Minecraft versions + */ + public static final TypedKey> PHANTOM = create(key("phantom")); + + /** + * {@code minecraft:pig} + * + * @apiNote This field is version-dependant and may be removed in future Minecraft versions + */ + public static final TypedKey> PIG = create(key("pig")); + + /** + * {@code minecraft:piglin} + * + * @apiNote This field is version-dependant and may be removed in future Minecraft versions + */ + public static final TypedKey> PIGLIN = create(key("piglin")); + + /** + * {@code minecraft:piglin_brute} + * + * @apiNote This field is version-dependant and may be removed in future Minecraft versions + */ + public static final TypedKey> PIGLIN_BRUTE = create(key("piglin_brute")); + + /** + * {@code minecraft:pillager} + * + * @apiNote This field is version-dependant and may be removed in future Minecraft versions + */ + public static final TypedKey> PILLAGER = create(key("pillager")); + + /** + * {@code minecraft:player} + * + * @apiNote This field is version-dependant and may be removed in future Minecraft versions + */ + public static final TypedKey> PLAYER = create(key("player")); + + /** + * {@code minecraft:polar_bear} + * + * @apiNote This field is version-dependant and may be removed in future Minecraft versions + */ + public static final TypedKey> POLAR_BEAR = create(key("polar_bear")); + + /** + * {@code minecraft:pufferfish} + * + * @apiNote This field is version-dependant and may be removed in future Minecraft versions + */ + public static final TypedKey> PUFFERFISH = create(key("pufferfish")); + + /** + * {@code minecraft:rabbit} + * + * @apiNote This field is version-dependant and may be removed in future Minecraft versions + */ + public static final TypedKey> RABBIT = create(key("rabbit")); + + /** + * {@code minecraft:ravager} + * + * @apiNote This field is version-dependant and may be removed in future Minecraft versions + */ + public static final TypedKey> RAVAGER = create(key("ravager")); + + /** + * {@code minecraft:salmon} + * + * @apiNote This field is version-dependant and may be removed in future Minecraft versions + */ + public static final TypedKey> SALMON = create(key("salmon")); + + /** + * {@code minecraft:sheep} + * + * @apiNote This field is version-dependant and may be removed in future Minecraft versions + */ + public static final TypedKey> SHEEP = create(key("sheep")); + + /** + * {@code minecraft:shulker} + * + * @apiNote This field is version-dependant and may be removed in future Minecraft versions + */ + public static final TypedKey> SHULKER = create(key("shulker")); + + /** + * {@code minecraft:shulker_bullet} + * + * @apiNote This field is version-dependant and may be removed in future Minecraft versions + */ + public static final TypedKey> SHULKER_BULLET = create(key("shulker_bullet")); + + /** + * {@code minecraft:silverfish} + * + * @apiNote This field is version-dependant and may be removed in future Minecraft versions + */ + public static final TypedKey> SILVERFISH = create(key("silverfish")); + + /** + * {@code minecraft:skeleton} + * + * @apiNote This field is version-dependant and may be removed in future Minecraft versions + */ + public static final TypedKey> SKELETON = create(key("skeleton")); + + /** + * {@code minecraft:skeleton_horse} + * + * @apiNote This field is version-dependant and may be removed in future Minecraft versions + */ + public static final TypedKey> SKELETON_HORSE = create(key("skeleton_horse")); + + /** + * {@code minecraft:slime} + * + * @apiNote This field is version-dependant and may be removed in future Minecraft versions + */ + public static final TypedKey> SLIME = create(key("slime")); + + /** + * {@code minecraft:small_fireball} + * + * @apiNote This field is version-dependant and may be removed in future Minecraft versions + */ + public static final TypedKey> SMALL_FIREBALL = create(key("small_fireball")); + + /** + * {@code minecraft:sniffer} + * + * @apiNote This field is version-dependant and may be removed in future Minecraft versions + */ + public static final TypedKey> SNIFFER = create(key("sniffer")); + + /** + * {@code minecraft:snow_golem} + * + * @apiNote This field is version-dependant and may be removed in future Minecraft versions + */ + public static final TypedKey> SNOW_GOLEM = create(key("snow_golem")); + + /** + * {@code minecraft:snowball} + * + * @apiNote This field is version-dependant and may be removed in future Minecraft versions + */ + public static final TypedKey> SNOWBALL = create(key("snowball")); + + /** + * {@code minecraft:spawner_minecart} + * + * @apiNote This field is version-dependant and may be removed in future Minecraft versions + */ + public static final TypedKey> SPAWNER_MINECART = create(key("spawner_minecart")); + + /** + * {@code minecraft:spectral_arrow} + * + * @apiNote This field is version-dependant and may be removed in future Minecraft versions + */ + public static final TypedKey> SPECTRAL_ARROW = create(key("spectral_arrow")); + + /** + * {@code minecraft:spider} + * + * @apiNote This field is version-dependant and may be removed in future Minecraft versions + */ + public static final TypedKey> SPIDER = create(key("spider")); + + /** + * {@code minecraft:splash_potion} + * + * @apiNote This field is version-dependant and may be removed in future Minecraft versions + */ + public static final TypedKey> SPLASH_POTION = create(key("splash_potion")); + + /** + * {@code minecraft:spruce_boat} + * + * @apiNote This field is version-dependant and may be removed in future Minecraft versions + */ + public static final TypedKey> SPRUCE_BOAT = create(key("spruce_boat")); + + /** + * {@code minecraft:spruce_chest_boat} + * + * @apiNote This field is version-dependant and may be removed in future Minecraft versions + */ + public static final TypedKey> SPRUCE_CHEST_BOAT = create(key("spruce_chest_boat")); + + /** + * {@code minecraft:squid} + * + * @apiNote This field is version-dependant and may be removed in future Minecraft versions + */ + public static final TypedKey> SQUID = create(key("squid")); + + /** + * {@code minecraft:stray} + * + * @apiNote This field is version-dependant and may be removed in future Minecraft versions + */ + public static final TypedKey> STRAY = create(key("stray")); + + /** + * {@code minecraft:strider} + * + * @apiNote This field is version-dependant and may be removed in future Minecraft versions + */ + public static final TypedKey> STRIDER = create(key("strider")); + + /** + * {@code minecraft:tadpole} + * + * @apiNote This field is version-dependant and may be removed in future Minecraft versions + */ + public static final TypedKey> TADPOLE = create(key("tadpole")); + + /** + * {@code minecraft:text_display} + * + * @apiNote This field is version-dependant and may be removed in future Minecraft versions + */ + public static final TypedKey> TEXT_DISPLAY = create(key("text_display")); + + /** + * {@code minecraft:tnt} + * + * @apiNote This field is version-dependant and may be removed in future Minecraft versions + */ + public static final TypedKey> TNT = create(key("tnt")); + + /** + * {@code minecraft:tnt_minecart} + * + * @apiNote This field is version-dependant and may be removed in future Minecraft versions + */ + public static final TypedKey> TNT_MINECART = create(key("tnt_minecart")); + + /** + * {@code minecraft:trader_llama} + * + * @apiNote This field is version-dependant and may be removed in future Minecraft versions + */ + public static final TypedKey> TRADER_LLAMA = create(key("trader_llama")); + + /** + * {@code minecraft:trident} + * + * @apiNote This field is version-dependant and may be removed in future Minecraft versions + */ + public static final TypedKey> TRIDENT = create(key("trident")); + + /** + * {@code minecraft:tropical_fish} + * + * @apiNote This field is version-dependant and may be removed in future Minecraft versions + */ + public static final TypedKey> TROPICAL_FISH = create(key("tropical_fish")); + + /** + * {@code minecraft:turtle} + * + * @apiNote This field is version-dependant and may be removed in future Minecraft versions + */ + public static final TypedKey> TURTLE = create(key("turtle")); + + /** + * {@code minecraft:vex} + * + * @apiNote This field is version-dependant and may be removed in future Minecraft versions + */ + public static final TypedKey> VEX = create(key("vex")); + + /** + * {@code minecraft:villager} + * + * @apiNote This field is version-dependant and may be removed in future Minecraft versions + */ + public static final TypedKey> VILLAGER = create(key("villager")); + + /** + * {@code minecraft:vindicator} + * + * @apiNote This field is version-dependant and may be removed in future Minecraft versions + */ + public static final TypedKey> VINDICATOR = create(key("vindicator")); + + /** + * {@code minecraft:wandering_trader} + * + * @apiNote This field is version-dependant and may be removed in future Minecraft versions + */ + public static final TypedKey> WANDERING_TRADER = create(key("wandering_trader")); + + /** + * {@code minecraft:warden} + * + * @apiNote This field is version-dependant and may be removed in future Minecraft versions + */ + public static final TypedKey> WARDEN = create(key("warden")); + + /** + * {@code minecraft:wind_charge} + * + * @apiNote This field is version-dependant and may be removed in future Minecraft versions + */ + public static final TypedKey> WIND_CHARGE = create(key("wind_charge")); + + /** + * {@code minecraft:witch} + * + * @apiNote This field is version-dependant and may be removed in future Minecraft versions + */ + public static final TypedKey> WITCH = create(key("witch")); + + /** + * {@code minecraft:wither} + * + * @apiNote This field is version-dependant and may be removed in future Minecraft versions + */ + public static final TypedKey> WITHER = create(key("wither")); + + /** + * {@code minecraft:wither_skeleton} + * + * @apiNote This field is version-dependant and may be removed in future Minecraft versions + */ + public static final TypedKey> WITHER_SKELETON = create(key("wither_skeleton")); + + /** + * {@code minecraft:wither_skull} + * + * @apiNote This field is version-dependant and may be removed in future Minecraft versions + */ + public static final TypedKey> WITHER_SKULL = create(key("wither_skull")); + + /** + * {@code minecraft:wolf} + * + * @apiNote This field is version-dependant and may be removed in future Minecraft versions + */ + public static final TypedKey> WOLF = create(key("wolf")); + + /** + * {@code minecraft:zoglin} + * + * @apiNote This field is version-dependant and may be removed in future Minecraft versions + */ + public static final TypedKey> ZOGLIN = create(key("zoglin")); + + /** + * {@code minecraft:zombie} + * + * @apiNote This field is version-dependant and may be removed in future Minecraft versions + */ + public static final TypedKey> ZOMBIE = create(key("zombie")); + + /** + * {@code minecraft:zombie_horse} + * + * @apiNote This field is version-dependant and may be removed in future Minecraft versions + */ + public static final TypedKey> ZOMBIE_HORSE = create(key("zombie_horse")); + + /** + * {@code minecraft:zombie_nautilus} + * + * @apiNote This field is version-dependant and may be removed in future Minecraft versions + */ + public static final TypedKey> ZOMBIE_NAUTILUS = create(key("zombie_nautilus")); + + /** + * {@code minecraft:zombie_villager} + * + * @apiNote This field is version-dependant and may be removed in future Minecraft versions + */ + public static final TypedKey> ZOMBIE_VILLAGER = create(key("zombie_villager")); + + /** + * {@code minecraft:zombified_piglin} + * + * @apiNote This field is version-dependant and may be removed in future Minecraft versions + */ + public static final TypedKey> ZOMBIFIED_PIGLIN = create(key("zombified_piglin")); + + private EntityTypeKeys() { + } + + private static TypedKey> create(final Key key) { + return TypedKey.create(RegistryKey.ENTITY_TYPE, key); + } +} diff --git a/paper-api/src/generated/java/io/papermc/paper/registry/keys/tags/EntityTypeTagKeys.java b/paper-api/src/generated/java/io/papermc/paper/registry/keys/tags/EntityTypeTagKeys.java index f24cd0efc90f..85cdd55803f3 100644 --- a/paper-api/src/generated/java/io/papermc/paper/registry/keys/tags/EntityTypeTagKeys.java +++ b/paper-api/src/generated/java/io/papermc/paper/registry/keys/tags/EntityTypeTagKeys.java @@ -30,322 +30,322 @@ public final class EntityTypeTagKeys { * * @apiNote This field is version-dependant and may be removed in future Minecraft versions */ - public static final TagKey ACCEPTS_IRON_GOLEM_GIFT = create(key("accepts_iron_golem_gift")); + public static final TagKey> ACCEPTS_IRON_GOLEM_GIFT = create(key("accepts_iron_golem_gift")); /** * {@code #minecraft:aquatic} * * @apiNote This field is version-dependant and may be removed in future Minecraft versions */ - public static final TagKey AQUATIC = create(key("aquatic")); + public static final TagKey> AQUATIC = create(key("aquatic")); /** * {@code #minecraft:arrows} * * @apiNote This field is version-dependant and may be removed in future Minecraft versions */ - public static final TagKey ARROWS = create(key("arrows")); + public static final TagKey> ARROWS = create(key("arrows")); /** * {@code #minecraft:arthropod} * * @apiNote This field is version-dependant and may be removed in future Minecraft versions */ - public static final TagKey ARTHROPOD = create(key("arthropod")); + public static final TagKey> ARTHROPOD = create(key("arthropod")); /** * {@code #minecraft:axolotl_always_hostiles} * * @apiNote This field is version-dependant and may be removed in future Minecraft versions */ - public static final TagKey AXOLOTL_ALWAYS_HOSTILES = create(key("axolotl_always_hostiles")); + public static final TagKey> AXOLOTL_ALWAYS_HOSTILES = create(key("axolotl_always_hostiles")); /** * {@code #minecraft:axolotl_hunt_targets} * * @apiNote This field is version-dependant and may be removed in future Minecraft versions */ - public static final TagKey AXOLOTL_HUNT_TARGETS = create(key("axolotl_hunt_targets")); + public static final TagKey> AXOLOTL_HUNT_TARGETS = create(key("axolotl_hunt_targets")); /** * {@code #minecraft:beehive_inhabitors} * * @apiNote This field is version-dependant and may be removed in future Minecraft versions */ - public static final TagKey BEEHIVE_INHABITORS = create(key("beehive_inhabitors")); + public static final TagKey> BEEHIVE_INHABITORS = create(key("beehive_inhabitors")); /** * {@code #minecraft:boat} * * @apiNote This field is version-dependant and may be removed in future Minecraft versions */ - public static final TagKey BOAT = create(key("boat")); + public static final TagKey> BOAT = create(key("boat")); /** * {@code #minecraft:burn_in_daylight} * * @apiNote This field is version-dependant and may be removed in future Minecraft versions */ - public static final TagKey BURN_IN_DAYLIGHT = create(key("burn_in_daylight")); + public static final TagKey> BURN_IN_DAYLIGHT = create(key("burn_in_daylight")); /** * {@code #minecraft:can_breathe_under_water} * * @apiNote This field is version-dependant and may be removed in future Minecraft versions */ - public static final TagKey CAN_BREATHE_UNDER_WATER = create(key("can_breathe_under_water")); + public static final TagKey> CAN_BREATHE_UNDER_WATER = create(key("can_breathe_under_water")); /** * {@code #minecraft:can_equip_harness} * * @apiNote This field is version-dependant and may be removed in future Minecraft versions */ - public static final TagKey CAN_EQUIP_HARNESS = create(key("can_equip_harness")); + public static final TagKey> CAN_EQUIP_HARNESS = create(key("can_equip_harness")); /** * {@code #minecraft:can_equip_saddle} * * @apiNote This field is version-dependant and may be removed in future Minecraft versions */ - public static final TagKey CAN_EQUIP_SADDLE = create(key("can_equip_saddle")); + public static final TagKey> CAN_EQUIP_SADDLE = create(key("can_equip_saddle")); /** * {@code #minecraft:can_float_while_ridden} * * @apiNote This field is version-dependant and may be removed in future Minecraft versions */ - public static final TagKey CAN_FLOAT_WHILE_RIDDEN = create(key("can_float_while_ridden")); + public static final TagKey> CAN_FLOAT_WHILE_RIDDEN = create(key("can_float_while_ridden")); /** * {@code #minecraft:can_turn_in_boats} * * @apiNote This field is version-dependant and may be removed in future Minecraft versions */ - public static final TagKey CAN_TURN_IN_BOATS = create(key("can_turn_in_boats")); + public static final TagKey> CAN_TURN_IN_BOATS = create(key("can_turn_in_boats")); /** * {@code #minecraft:can_wear_horse_armor} * * @apiNote This field is version-dependant and may be removed in future Minecraft versions */ - public static final TagKey CAN_WEAR_HORSE_ARMOR = create(key("can_wear_horse_armor")); + public static final TagKey> CAN_WEAR_HORSE_ARMOR = create(key("can_wear_horse_armor")); /** * {@code #minecraft:can_wear_nautilus_armor} * * @apiNote This field is version-dependant and may be removed in future Minecraft versions */ - public static final TagKey CAN_WEAR_NAUTILUS_ARMOR = create(key("can_wear_nautilus_armor")); + public static final TagKey> CAN_WEAR_NAUTILUS_ARMOR = create(key("can_wear_nautilus_armor")); /** * {@code #minecraft:candidate_for_iron_golem_gift} * * @apiNote This field is version-dependant and may be removed in future Minecraft versions */ - public static final TagKey CANDIDATE_FOR_IRON_GOLEM_GIFT = create(key("candidate_for_iron_golem_gift")); + public static final TagKey> CANDIDATE_FOR_IRON_GOLEM_GIFT = create(key("candidate_for_iron_golem_gift")); /** * {@code #minecraft:cannot_be_pushed_onto_boats} * * @apiNote This field is version-dependant and may be removed in future Minecraft versions */ - public static final TagKey CANNOT_BE_PUSHED_ONTO_BOATS = create(key("cannot_be_pushed_onto_boats")); + public static final TagKey> CANNOT_BE_PUSHED_ONTO_BOATS = create(key("cannot_be_pushed_onto_boats")); /** * {@code #minecraft:deflects_projectiles} * * @apiNote This field is version-dependant and may be removed in future Minecraft versions */ - public static final TagKey DEFLECTS_PROJECTILES = create(key("deflects_projectiles")); + public static final TagKey> DEFLECTS_PROJECTILES = create(key("deflects_projectiles")); /** * {@code #minecraft:dismounts_underwater} * * @apiNote This field is version-dependant and may be removed in future Minecraft versions */ - public static final TagKey DISMOUNTS_UNDERWATER = create(key("dismounts_underwater")); + public static final TagKey> DISMOUNTS_UNDERWATER = create(key("dismounts_underwater")); /** * {@code #minecraft:fall_damage_immune} * * @apiNote This field is version-dependant and may be removed in future Minecraft versions */ - public static final TagKey FALL_DAMAGE_IMMUNE = create(key("fall_damage_immune")); + public static final TagKey> FALL_DAMAGE_IMMUNE = create(key("fall_damage_immune")); /** * {@code #minecraft:followable_friendly_mobs} * * @apiNote This field is version-dependant and may be removed in future Minecraft versions */ - public static final TagKey FOLLOWABLE_FRIENDLY_MOBS = create(key("followable_friendly_mobs")); + public static final TagKey> FOLLOWABLE_FRIENDLY_MOBS = create(key("followable_friendly_mobs")); /** * {@code #minecraft:freeze_hurts_extra_types} * * @apiNote This field is version-dependant and may be removed in future Minecraft versions */ - public static final TagKey FREEZE_HURTS_EXTRA_TYPES = create(key("freeze_hurts_extra_types")); + public static final TagKey> FREEZE_HURTS_EXTRA_TYPES = create(key("freeze_hurts_extra_types")); /** * {@code #minecraft:freeze_immune_entity_types} * * @apiNote This field is version-dependant and may be removed in future Minecraft versions */ - public static final TagKey FREEZE_IMMUNE_ENTITY_TYPES = create(key("freeze_immune_entity_types")); + public static final TagKey> FREEZE_IMMUNE_ENTITY_TYPES = create(key("freeze_immune_entity_types")); /** * {@code #minecraft:frog_food} * * @apiNote This field is version-dependant and may be removed in future Minecraft versions */ - public static final TagKey FROG_FOOD = create(key("frog_food")); + public static final TagKey> FROG_FOOD = create(key("frog_food")); /** * {@code #minecraft:ignores_poison_and_regen} * * @apiNote This field is version-dependant and may be removed in future Minecraft versions */ - public static final TagKey IGNORES_POISON_AND_REGEN = create(key("ignores_poison_and_regen")); + public static final TagKey> IGNORES_POISON_AND_REGEN = create(key("ignores_poison_and_regen")); /** * {@code #minecraft:illager} * * @apiNote This field is version-dependant and may be removed in future Minecraft versions */ - public static final TagKey ILLAGER = create(key("illager")); + public static final TagKey> ILLAGER = create(key("illager")); /** * {@code #minecraft:illager_friends} * * @apiNote This field is version-dependant and may be removed in future Minecraft versions */ - public static final TagKey ILLAGER_FRIENDS = create(key("illager_friends")); + public static final TagKey> ILLAGER_FRIENDS = create(key("illager_friends")); /** * {@code #minecraft:immune_to_infested} * * @apiNote This field is version-dependant and may be removed in future Minecraft versions */ - public static final TagKey IMMUNE_TO_INFESTED = create(key("immune_to_infested")); + public static final TagKey> IMMUNE_TO_INFESTED = create(key("immune_to_infested")); /** * {@code #minecraft:immune_to_oozing} * * @apiNote This field is version-dependant and may be removed in future Minecraft versions */ - public static final TagKey IMMUNE_TO_OOZING = create(key("immune_to_oozing")); + public static final TagKey> IMMUNE_TO_OOZING = create(key("immune_to_oozing")); /** * {@code #minecraft:impact_projectiles} * * @apiNote This field is version-dependant and may be removed in future Minecraft versions */ - public static final TagKey IMPACT_PROJECTILES = create(key("impact_projectiles")); + public static final TagKey> IMPACT_PROJECTILES = create(key("impact_projectiles")); /** * {@code #minecraft:inverted_healing_and_harm} * * @apiNote This field is version-dependant and may be removed in future Minecraft versions */ - public static final TagKey INVERTED_HEALING_AND_HARM = create(key("inverted_healing_and_harm")); + public static final TagKey> INVERTED_HEALING_AND_HARM = create(key("inverted_healing_and_harm")); /** * {@code #minecraft:nautilus_hostiles} * * @apiNote This field is version-dependant and may be removed in future Minecraft versions */ - public static final TagKey NAUTILUS_HOSTILES = create(key("nautilus_hostiles")); + public static final TagKey> NAUTILUS_HOSTILES = create(key("nautilus_hostiles")); /** * {@code #minecraft:no_anger_from_wind_charge} * * @apiNote This field is version-dependant and may be removed in future Minecraft versions */ - public static final TagKey NO_ANGER_FROM_WIND_CHARGE = create(key("no_anger_from_wind_charge")); + public static final TagKey> NO_ANGER_FROM_WIND_CHARGE = create(key("no_anger_from_wind_charge")); /** * {@code #minecraft:non_controlling_rider} * * @apiNote This field is version-dependant and may be removed in future Minecraft versions */ - public static final TagKey NON_CONTROLLING_RIDER = create(key("non_controlling_rider")); + public static final TagKey> NON_CONTROLLING_RIDER = create(key("non_controlling_rider")); /** * {@code #minecraft:not_scary_for_pufferfish} * * @apiNote This field is version-dependant and may be removed in future Minecraft versions */ - public static final TagKey NOT_SCARY_FOR_PUFFERFISH = create(key("not_scary_for_pufferfish")); + public static final TagKey> NOT_SCARY_FOR_PUFFERFISH = create(key("not_scary_for_pufferfish")); /** * {@code #minecraft:powder_snow_walkable_mobs} * * @apiNote This field is version-dependant and may be removed in future Minecraft versions */ - public static final TagKey POWDER_SNOW_WALKABLE_MOBS = create(key("powder_snow_walkable_mobs")); + public static final TagKey> POWDER_SNOW_WALKABLE_MOBS = create(key("powder_snow_walkable_mobs")); /** * {@code #minecraft:raiders} * * @apiNote This field is version-dependant and may be removed in future Minecraft versions */ - public static final TagKey RAIDERS = create(key("raiders")); + public static final TagKey> RAIDERS = create(key("raiders")); /** * {@code #minecraft:redirectable_projectile} * * @apiNote This field is version-dependant and may be removed in future Minecraft versions */ - public static final TagKey REDIRECTABLE_PROJECTILE = create(key("redirectable_projectile")); + public static final TagKey> REDIRECTABLE_PROJECTILE = create(key("redirectable_projectile")); /** * {@code #minecraft:sensitive_to_bane_of_arthropods} * * @apiNote This field is version-dependant and may be removed in future Minecraft versions */ - public static final TagKey SENSITIVE_TO_BANE_OF_ARTHROPODS = create(key("sensitive_to_bane_of_arthropods")); + public static final TagKey> SENSITIVE_TO_BANE_OF_ARTHROPODS = create(key("sensitive_to_bane_of_arthropods")); /** * {@code #minecraft:sensitive_to_impaling} * * @apiNote This field is version-dependant and may be removed in future Minecraft versions */ - public static final TagKey SENSITIVE_TO_IMPALING = create(key("sensitive_to_impaling")); + public static final TagKey> SENSITIVE_TO_IMPALING = create(key("sensitive_to_impaling")); /** * {@code #minecraft:sensitive_to_smite} * * @apiNote This field is version-dependant and may be removed in future Minecraft versions */ - public static final TagKey SENSITIVE_TO_SMITE = create(key("sensitive_to_smite")); + public static final TagKey> SENSITIVE_TO_SMITE = create(key("sensitive_to_smite")); /** * {@code #minecraft:skeletons} * * @apiNote This field is version-dependant and may be removed in future Minecraft versions */ - public static final TagKey SKELETONS = create(key("skeletons")); + public static final TagKey> SKELETONS = create(key("skeletons")); /** * {@code #minecraft:undead} * * @apiNote This field is version-dependant and may be removed in future Minecraft versions */ - public static final TagKey UNDEAD = create(key("undead")); + public static final TagKey> UNDEAD = create(key("undead")); /** * {@code #minecraft:wither_friends} * * @apiNote This field is version-dependant and may be removed in future Minecraft versions */ - public static final TagKey WITHER_FRIENDS = create(key("wither_friends")); + public static final TagKey> WITHER_FRIENDS = create(key("wither_friends")); /** * {@code #minecraft:zombies} * * @apiNote This field is version-dependant and may be removed in future Minecraft versions */ - public static final TagKey ZOMBIES = create(key("zombies")); + public static final TagKey> ZOMBIES = create(key("zombies")); private EntityTypeTagKeys() { } @@ -356,7 +356,7 @@ private EntityTypeTagKeys() { * @param key the tag key's key * @return a new tag key */ - public static TagKey create(final Key key) { + public static TagKey> create(final Key key) { return TagKey.create(RegistryKey.ENTITY_TYPE, key); } } diff --git a/paper-api/src/main/java/co/aikar/timings/TimingHistory.java b/paper-api/src/main/java/co/aikar/timings/TimingHistory.java index 143fb3623a3f..142971be15c5 100644 --- a/paper-api/src/main/java/co/aikar/timings/TimingHistory.java +++ b/paper-api/src/main/java/co/aikar/timings/TimingHistory.java @@ -24,8 +24,17 @@ package co.aikar.timings; import co.aikar.timings.TimingHistory.RegionData.RegionId; +import co.aikar.util.LoadingMap; +import co.aikar.util.MRUMapCache; import com.google.common.base.Function; import com.google.common.collect.Sets; +import java.lang.management.ManagementFactory; +import java.util.Collection; +import java.util.EnumMap; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; import org.bukkit.Bukkit; import org.bukkit.Chunk; import org.bukkit.Material; @@ -34,21 +43,17 @@ import org.bukkit.entity.Entity; import org.bukkit.entity.EntityType; import org.bukkit.entity.Player; -import co.aikar.util.LoadingMap; -import co.aikar.util.MRUMapCache; - -import java.lang.management.ManagementFactory; -import java.util.Collection; -import java.util.EnumMap; -import java.util.List; -import java.util.Map; -import java.util.Set; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import static co.aikar.timings.TimingsManager.FULL_SERVER_TICK; import static co.aikar.timings.TimingsManager.MINUTE_REPORTS; -import static co.aikar.util.JSONUtil.*; +import static co.aikar.util.JSONUtil.JSONPair; +import static co.aikar.util.JSONUtil.createObject; +import static co.aikar.util.JSONUtil.pair; +import static co.aikar.util.JSONUtil.toArray; +import static co.aikar.util.JSONUtil.toArrayMapper; +import static co.aikar.util.JSONUtil.toObjectMapper; /** * @hidden @@ -143,10 +148,10 @@ public Object apply(RegionData input) { input.regionId.x, input.regionId.z, toObjectMapper(input.entityCounts.entrySet(), - new Function, JSONPair>() { + new Function, Counter>, JSONPair>() { @NotNull @Override - public JSONPair apply(Map.Entry entry) { + public JSONPair apply(Map.Entry, Counter> entry) { entityTypeSet.add(entry.getKey()); return pair( String.valueOf(entry.getKey().ordinal()), @@ -207,12 +212,12 @@ public int hashCode() { } @SuppressWarnings("unchecked") - final Map entityCounts = MRUMapCache.of(LoadingMap.of( - new EnumMap(EntityType.class), k -> new Counter() + final Map, Counter> entityCounts = MRUMapCache.of(LoadingMap.of( + new HashMap<>(), k -> new Counter() )); @SuppressWarnings("unchecked") final Map tileEntityCounts = MRUMapCache.of(LoadingMap.of( - new EnumMap(Material.class), k -> new Counter() + new EnumMap<>(Material.class), k -> new Counter() )); static class RegionId { diff --git a/paper-api/src/main/java/io/papermc/paper/InternalAPIBridge.java b/paper-api/src/main/java/io/papermc/paper/InternalAPIBridge.java index 7031a6bc9e60..14bb66e15e4d 100644 --- a/paper-api/src/main/java/io/papermc/paper/InternalAPIBridge.java +++ b/paper-api/src/main/java/io/papermc/paper/InternalAPIBridge.java @@ -14,6 +14,7 @@ import org.bukkit.block.Biome; import org.bukkit.damage.DamageEffect; import org.bukkit.damage.DamageSource; +import org.bukkit.entity.EntityType; import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Pose; import org.jetbrains.annotations.ApiStatus; @@ -61,6 +62,15 @@ class Holder { @ApiStatus.ScheduledForRemoval(inVersion = "1.22") Biome constructLegacyCustomBiome(); + /** + * Constructs the legacy unknown entity type instance for the entity type enum. + * + * @return the created entity type. + */ + @Deprecated(forRemoval = true, since = "1.21.11") + @ApiStatus.ScheduledForRemoval(inVersion = "1.22") + EntityType constructLegacyUnknownEntityType(); + /** * Creates a new combat entry. *

diff --git a/paper-api/src/main/java/io/papermc/paper/datacomponent/item/Equippable.java b/paper-api/src/main/java/io/papermc/paper/datacomponent/item/Equippable.java index 570ed9d28af3..6582b1ac7c48 100644 --- a/paper-api/src/main/java/io/papermc/paper/datacomponent/item/Equippable.java +++ b/paper-api/src/main/java/io/papermc/paper/datacomponent/item/Equippable.java @@ -70,7 +70,7 @@ static Equippable.Builder equippable(final EquipmentSlot slot) { * @return the set of allowed entities */ @Contract(pure = true) - @Nullable RegistryKeySet allowedEntities(); + @Nullable RegistryKeySet> allowedEntities(); /** * Checks if the item is dispensable. @@ -161,7 +161,7 @@ interface Builder extends DataComponentBuilder { * @return the builder for chaining */ @Contract(value = "_ -> this", mutates = "this") - Builder allowedEntities(@Nullable RegistryKeySet allowedEntities); + Builder allowedEntities(@Nullable RegistryKeySet> allowedEntities); /** * Sets whether the item is dispensable. diff --git a/paper-api/src/main/java/io/papermc/paper/registry/RegistryKey.java b/paper-api/src/main/java/io/papermc/paper/registry/RegistryKey.java index dcee3d88f5b7..d5921afc2238 100644 --- a/paper-api/src/main/java/io/papermc/paper/registry/RegistryKey.java +++ b/paper-api/src/main/java/io/papermc/paper/registry/RegistryKey.java @@ -132,6 +132,11 @@ public sealed interface RegistryKey extends Keyed permits RegistryKeyImpl { * @see io.papermc.paper.registry.keys.GameRuleKeys */ RegistryKey> GAME_RULE = create("game_rule"); + /** + * Built-in registry for entity types. + * @see io.papermc.paper.registry.keys.EntityTypeKeys + */ + RegistryKey> ENTITY_TYPE = create("entity_type"); /* ********************** * * Data-driven Registries * @@ -236,7 +241,6 @@ public sealed interface RegistryKey extends Keyed permits RegistryKeyImpl { /* ******************* * * API-only Registries * * ******************* */ - RegistryKey ENTITY_TYPE = create("entity_type"); RegistryKey PARTICLE_TYPE = create("particle_type"); RegistryKey POTION = create("potion"); RegistryKey> MEMORY_MODULE_TYPE = create("memory_module_type"); diff --git a/paper-api/src/main/java/io/papermc/paper/tag/BaseTag.java b/paper-api/src/main/java/io/papermc/paper/tag/BaseTag.java index c9abd686b7c0..24e91de90490 100644 --- a/paper-api/src/main/java/io/papermc/paper/tag/BaseTag.java +++ b/paper-api/src/main/java/io/papermc/paper/tag/BaseTag.java @@ -27,7 +27,7 @@ public BaseTag(@NotNull Class clazz, @NotNull NamespacedKey key, @NotNull Pre add(filter); } - public BaseTag(@NotNull Class clazz, @NotNull NamespacedKey key, @NotNull T...values) { + public BaseTag(@NotNull Class clazz, @NotNull NamespacedKey key, @NotNull T... values) { this(clazz, key, Lists.newArrayList(values)); } diff --git a/paper-api/src/main/java/io/papermc/paper/tag/EntitySetTag.java b/paper-api/src/main/java/io/papermc/paper/tag/EntitySetTag.java index 1199fc8a055e..efd8faaec6c0 100644 --- a/paper-api/src/main/java/io/papermc/paper/tag/EntitySetTag.java +++ b/paper-api/src/main/java/io/papermc/paper/tag/EntitySetTag.java @@ -4,8 +4,8 @@ import java.util.Set; import java.util.function.Predicate; import java.util.stream.Collectors; -import java.util.stream.Stream; import org.bukkit.NamespacedKey; +import org.bukkit.Registry; import org.bukkit.entity.EntityType; import org.jetbrains.annotations.NotNull; @@ -30,7 +30,7 @@ public EntitySetTag(@NotNull NamespacedKey key, @NotNull Collection @NotNull @Override protected Set getAllPossibleValues() { - return Stream.of(EntityType.values()).collect(Collectors.toSet()); + return Registry.ENTITY_TYPE.stream().collect(Collectors.toSet()); } @NotNull diff --git a/paper-api/src/main/java/org/bukkit/Registry.java b/paper-api/src/main/java/org/bukkit/Registry.java index 0859653089ac..5c8fb4de1af3 100644 --- a/paper-api/src/main/java/org/bukkit/Registry.java +++ b/paper-api/src/main/java/org/bukkit/Registry.java @@ -164,7 +164,7 @@ public Iterator iterator() { * * @see EntityType */ - Registry ENTITY_TYPE = registryFor(RegistryKey.ENTITY_TYPE); + Registry> ENTITY_TYPE = registryFor(RegistryKey.ENTITY_TYPE); /** * Server instruments. * diff --git a/paper-api/src/main/java/org/bukkit/UnsafeValues.java b/paper-api/src/main/java/org/bukkit/UnsafeValues.java index 82d8febbc565..049af27581ab 100644 --- a/paper-api/src/main/java/org/bukkit/UnsafeValues.java +++ b/paper-api/src/main/java/org/bukkit/UnsafeValues.java @@ -3,11 +3,11 @@ import com.google.common.collect.Multimap; import io.papermc.paper.entity.EntitySerializationFlag; import io.papermc.paper.registry.RegistryKey; +import java.util.Map; import net.kyori.adventure.text.event.HoverEvent; import org.bukkit.advancement.Advancement; import org.bukkit.attribute.Attribute; import org.bukkit.attribute.AttributeModifier; -import org.bukkit.block.Biome; import org.bukkit.block.data.BlockData; import org.bukkit.damage.DamageSource; import org.bukkit.damage.DamageType; @@ -24,7 +24,6 @@ import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import java.util.Map; /** * This interface provides value conversions that may be specific to a @@ -109,8 +108,6 @@ public interface UnsafeValues { @Deprecated(since = "1.21", forRemoval = true) String getItemTranslationKey(Material material); - String getTranslationKey(EntityType entityType); - String getTranslationKey(ItemStack itemStack); @Deprecated(since = "1.21.3", forRemoval = true) @@ -300,23 +297,6 @@ default com.destroystokyo.paper.util.VersionFetcher getVersionFetcher() { * @return true if valid repair, false if not */ public boolean isValidRepairItemStack(@org.jetbrains.annotations.NotNull ItemStack itemToBeRepaired, @org.jetbrains.annotations.NotNull ItemStack repairMaterial); - - /** - * Checks if the entity represented by the namespaced key has default attributes. - * - * @param entityKey the entity's key - * @return true if it has default attributes - */ - boolean hasDefaultEntityAttributes(@org.jetbrains.annotations.NotNull NamespacedKey entityKey); - - /** - * Gets the default attributes for the entity represented by the namespaced key. - * - * @param entityKey the entity's key - * @return an unmodifiable instance of Attributable for reading default attributes. - * @throws IllegalArgumentException if the entity does not exist of have default attributes (use {@link #hasDefaultEntityAttributes(NamespacedKey)} first) - */ - @org.jetbrains.annotations.NotNull org.bukkit.attribute.Attributable getDefaultEntityAttributes(@org.jetbrains.annotations.NotNull NamespacedKey entityKey); // Paper end // Paper start - namespaced key biome methods diff --git a/paper-api/src/main/java/org/bukkit/block/Biome.java b/paper-api/src/main/java/org/bukkit/block/Biome.java index 572f917374f8..75ed9075415b 100644 --- a/paper-api/src/main/java/org/bukkit/block/Biome.java +++ b/paper-api/src/main/java/org/bukkit/block/Biome.java @@ -195,11 +195,4 @@ static Biome valueOf(@NotNull String name) { static Biome[] values() { return Lists.newArrayList(Registry.BIOME).toArray(new Biome[0]); } - - // Paper start - @Override - default @NotNull String translationKey() { - return "biome.minecraft." + this.getKey().getKey(); - } - // Paper end } diff --git a/paper-api/src/main/java/org/bukkit/entity/EntityType.java b/paper-api/src/main/java/org/bukkit/entity/EntityType.java index e84da0628407..dfd27d40ae3f 100644 --- a/paper-api/src/main/java/org/bukkit/entity/EntityType.java +++ b/paper-api/src/main/java/org/bukkit/entity/EntityType.java @@ -1,15 +1,20 @@ package org.bukkit.entity; import com.google.common.base.Preconditions; -import java.util.HashMap; +import io.papermc.paper.InternalAPIBridge; +import io.papermc.paper.registry.RegistryKey; +import io.papermc.paper.world.flag.FeatureDependant; import java.util.Locale; -import java.util.Map; +import net.kyori.adventure.key.Key; +import net.kyori.adventure.key.KeyPattern; import org.bukkit.Bukkit; import org.bukkit.Keyed; import org.bukkit.Location; import org.bukkit.NamespacedKey; +import org.bukkit.Registry; import org.bukkit.Translatable; import org.bukkit.World; +import org.bukkit.attribute.Attributable; import org.bukkit.entity.boat.AcaciaBoat; import org.bukkit.entity.boat.AcaciaChestBoat; import org.bukkit.entity.boat.BambooChestRaft; @@ -37,209 +42,340 @@ import org.bukkit.entity.minecart.RideableMinecart; import org.bukkit.entity.minecart.SpawnerMinecart; import org.bukkit.entity.minecart.StorageMinecart; -import org.bukkit.inventory.ItemStack; -import org.bukkit.potion.PotionEffectType; +import org.bukkit.util.OldEnum; +import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.Contract; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; +import org.jspecify.annotations.NullMarked; +import org.jspecify.annotations.Nullable; -public enum EntityType implements Keyed, Translatable, net.kyori.adventure.translation.Translatable, io.papermc.paper.world.flag.FeatureDependant { // Paper - translatable +@NullMarked +public interface EntityType extends OldEnum>, Keyed, Translatable, net.kyori.adventure.translation.Translatable, FeatureDependant { // Start generate - EntityType - ACACIA_BOAT("acacia_boat", AcaciaBoat.class, -1), - ACACIA_CHEST_BOAT("acacia_chest_boat", AcaciaChestBoat.class, -1), - ALLAY("allay", Allay.class, -1), - AREA_EFFECT_CLOUD("area_effect_cloud", AreaEffectCloud.class, 3), - ARMADILLO("armadillo", Armadillo.class, -1), - ARMOR_STAND("armor_stand", ArmorStand.class, 30), - ARROW("arrow", Arrow.class, 10), - AXOLOTL("axolotl", Axolotl.class, -1), - BAMBOO_CHEST_RAFT("bamboo_chest_raft", BambooChestRaft.class, -1), - BAMBOO_RAFT("bamboo_raft", BambooRaft.class, -1), - BAT("bat", Bat.class, 65), - BEE("bee", Bee.class, -1), - BIRCH_BOAT("birch_boat", BirchBoat.class, -1), - BIRCH_CHEST_BOAT("birch_chest_boat", BirchChestBoat.class, -1), - BLAZE("blaze", Blaze.class, 61), - BLOCK_DISPLAY("block_display", BlockDisplay.class, -1), - BOGGED("bogged", Bogged.class, -1), - BREEZE("breeze", Breeze.class, -1), - BREEZE_WIND_CHARGE("breeze_wind_charge", BreezeWindCharge.class, -1), - CAMEL("camel", Camel.class, -1), - CAMEL_HUSK("camel_husk", CamelHusk.class, -1), - CAT("cat", Cat.class, -1), - CAVE_SPIDER("cave_spider", CaveSpider.class, 59), - CHERRY_BOAT("cherry_boat", CherryBoat.class, -1), - CHERRY_CHEST_BOAT("cherry_chest_boat", CherryChestBoat.class, -1), - CHEST_MINECART("chest_minecart", StorageMinecart.class, 43), - CHICKEN("chicken", Chicken.class, 93), - COD("cod", Cod.class, -1), - COMMAND_BLOCK_MINECART("command_block_minecart", CommandMinecart.class, 40), - COPPER_GOLEM("copper_golem", CopperGolem.class, -1), - COW("cow", Cow.class, 92), - CREAKING("creaking", Creaking.class, -1), - CREEPER("creeper", Creeper.class, 50), - DARK_OAK_BOAT("dark_oak_boat", DarkOakBoat.class, -1), - DARK_OAK_CHEST_BOAT("dark_oak_chest_boat", DarkOakChestBoat.class, -1), - DOLPHIN("dolphin", Dolphin.class, -1), - DONKEY("donkey", Donkey.class, 31), - DRAGON_FIREBALL("dragon_fireball", DragonFireball.class, 26), - DROWNED("drowned", Drowned.class, -1), - EGG("egg", Egg.class, 7), - ELDER_GUARDIAN("elder_guardian", ElderGuardian.class, 4), - END_CRYSTAL("end_crystal", EnderCrystal.class, 200), - ENDER_DRAGON("ender_dragon", EnderDragon.class, 63), - ENDER_PEARL("ender_pearl", EnderPearl.class, 14), - ENDERMAN("enderman", Enderman.class, 58), - ENDERMITE("endermite", Endermite.class, 67), - EVOKER("evoker", Evoker.class, 34), - EVOKER_FANGS("evoker_fangs", EvokerFangs.class, 33), - EXPERIENCE_BOTTLE("experience_bottle", ThrownExpBottle.class, 17), - EXPERIENCE_ORB("experience_orb", ExperienceOrb.class, 2), - EYE_OF_ENDER("eye_of_ender", EnderSignal.class, 15), - FALLING_BLOCK("falling_block", FallingBlock.class, 21), - FIREBALL("fireball", Fireball.class, 12), - FIREWORK_ROCKET("firework_rocket", Firework.class, 22), - FISHING_BOBBER("fishing_bobber", FishHook.class, -1, false), - FOX("fox", Fox.class, -1), - FROG("frog", Frog.class, -1), - FURNACE_MINECART("furnace_minecart", PoweredMinecart.class, 44), - GHAST("ghast", Ghast.class, 56), - GIANT("giant", Giant.class, 53), - GLOW_ITEM_FRAME("glow_item_frame", GlowItemFrame.class, -1), - GLOW_SQUID("glow_squid", GlowSquid.class, -1), - GOAT("goat", Goat.class, -1), - GUARDIAN("guardian", Guardian.class, 68), - HAPPY_GHAST("happy_ghast", HappyGhast.class, -1), - HOGLIN("hoglin", Hoglin.class, -1), - HOPPER_MINECART("hopper_minecart", HopperMinecart.class, 46), - HORSE("horse", Horse.class, 100), - HUSK("husk", Husk.class, 23), - ILLUSIONER("illusioner", Illusioner.class, 37), - INTERACTION("interaction", Interaction.class, -1), - IRON_GOLEM("iron_golem", IronGolem.class, 99), - ITEM("item", Item.class, 1), - ITEM_DISPLAY("item_display", ItemDisplay.class, -1), - ITEM_FRAME("item_frame", ItemFrame.class, 18), - JUNGLE_BOAT("jungle_boat", JungleBoat.class, -1), - JUNGLE_CHEST_BOAT("jungle_chest_boat", JungleChestBoat.class, -1), - LEASH_KNOT("leash_knot", LeashHitch.class, 8), - LIGHTNING_BOLT("lightning_bolt", LightningStrike.class, -1), - LINGERING_POTION("lingering_potion", LingeringPotion.class, -1), - LLAMA("llama", Llama.class, 103), - LLAMA_SPIT("llama_spit", LlamaSpit.class, 104), - MAGMA_CUBE("magma_cube", MagmaCube.class, 62), - MANGROVE_BOAT("mangrove_boat", MangroveBoat.class, -1), - MANGROVE_CHEST_BOAT("mangrove_chest_boat", MangroveChestBoat.class, -1), - MANNEQUIN("mannequin", Mannequin.class, -1), - MARKER("marker", Marker.class, -1), - MINECART("minecart", RideableMinecart.class, 42), - MOOSHROOM("mooshroom", MushroomCow.class, 96), - MULE("mule", Mule.class, 32), - NAUTILUS("nautilus", Nautilus.class, -1), - OAK_BOAT("oak_boat", OakBoat.class, -1), - OAK_CHEST_BOAT("oak_chest_boat", OakChestBoat.class, -1), - OCELOT("ocelot", Ocelot.class, 98), - OMINOUS_ITEM_SPAWNER("ominous_item_spawner", OminousItemSpawner.class, -1), - PAINTING("painting", Painting.class, 9), - PALE_OAK_BOAT("pale_oak_boat", PaleOakBoat.class, -1), - PALE_OAK_CHEST_BOAT("pale_oak_chest_boat", PaleOakChestBoat.class, -1), - PANDA("panda", Panda.class, -1), - PARCHED("parched", Parched.class, -1), - PARROT("parrot", Parrot.class, 105), - PHANTOM("phantom", Phantom.class, -1), - PIG("pig", Pig.class, 90), - PIGLIN("piglin", Piglin.class, -1), - PIGLIN_BRUTE("piglin_brute", PiglinBrute.class, -1), - PILLAGER("pillager", Pillager.class, -1), - PLAYER("player", Player.class, -1, false), - POLAR_BEAR("polar_bear", PolarBear.class, 102), - PUFFERFISH("pufferfish", PufferFish.class, -1), - RABBIT("rabbit", Rabbit.class, 101), - RAVAGER("ravager", Ravager.class, -1), - SALMON("salmon", Salmon.class, -1), - SHEEP("sheep", Sheep.class, 91), - SHULKER("shulker", Shulker.class, 69), - SHULKER_BULLET("shulker_bullet", ShulkerBullet.class, 25), - SILVERFISH("silverfish", Silverfish.class, 60), - SKELETON("skeleton", Skeleton.class, 51), - SKELETON_HORSE("skeleton_horse", SkeletonHorse.class, 28), - SLIME("slime", Slime.class, 55), - SMALL_FIREBALL("small_fireball", SmallFireball.class, 13), - SNIFFER("sniffer", Sniffer.class, -1), - SNOW_GOLEM("snow_golem", Snowman.class, 97), - SNOWBALL("snowball", Snowball.class, 11), - SPAWNER_MINECART("spawner_minecart", SpawnerMinecart.class, 47), - SPECTRAL_ARROW("spectral_arrow", SpectralArrow.class, 24), - SPIDER("spider", Spider.class, 52), - SPLASH_POTION("splash_potion", SplashPotion.class, 16), - SPRUCE_BOAT("spruce_boat", SpruceBoat.class, -1), - SPRUCE_CHEST_BOAT("spruce_chest_boat", SpruceChestBoat.class, -1), - SQUID("squid", Squid.class, 94), - STRAY("stray", Stray.class, 6), - STRIDER("strider", Strider.class, -1), - TADPOLE("tadpole", Tadpole.class, -1), - TEXT_DISPLAY("text_display", TextDisplay.class, -1), - TNT("tnt", TNTPrimed.class, 20), - TNT_MINECART("tnt_minecart", ExplosiveMinecart.class, 45), - TRADER_LLAMA("trader_llama", TraderLlama.class, -1), - TRIDENT("trident", Trident.class, -1), - TROPICAL_FISH("tropical_fish", TropicalFish.class, -1), - TURTLE("turtle", Turtle.class, -1), - VEX("vex", Vex.class, 35), - VILLAGER("villager", Villager.class, 120), - VINDICATOR("vindicator", Vindicator.class, 36), - WANDERING_TRADER("wandering_trader", WanderingTrader.class, -1), - WARDEN("warden", Warden.class, -1), - WIND_CHARGE("wind_charge", WindCharge.class, -1), - WITCH("witch", Witch.class, 66), - WITHER("wither", Wither.class, 64), - WITHER_SKELETON("wither_skeleton", WitherSkeleton.class, 5), - WITHER_SKULL("wither_skull", WitherSkull.class, 19), - WOLF("wolf", Wolf.class, 95), - ZOGLIN("zoglin", Zoglin.class, -1), - ZOMBIE("zombie", Zombie.class, 54), - ZOMBIE_HORSE("zombie_horse", ZombieHorse.class, 29), - ZOMBIE_NAUTILUS("zombie_nautilus", ZombieNautilus.class, -1), - ZOMBIE_VILLAGER("zombie_villager", ZombieVillager.class, 27), - ZOMBIFIED_PIGLIN("zombified_piglin", PigZombie.class, 57), + EntityType ACACIA_BOAT = getType("acacia_boat"); + + EntityType ACACIA_CHEST_BOAT = getType("acacia_chest_boat"); + + EntityType ALLAY = getType("allay"); + + EntityType AREA_EFFECT_CLOUD = getType("area_effect_cloud"); + + EntityType ARMADILLO = getType("armadillo"); + + EntityType ARMOR_STAND = getType("armor_stand"); + + EntityType ARROW = getType("arrow"); + + EntityType AXOLOTL = getType("axolotl"); + + EntityType BAMBOO_CHEST_RAFT = getType("bamboo_chest_raft"); + + EntityType BAMBOO_RAFT = getType("bamboo_raft"); + + EntityType BAT = getType("bat"); + + EntityType BEE = getType("bee"); + + EntityType BIRCH_BOAT = getType("birch_boat"); + + EntityType BIRCH_CHEST_BOAT = getType("birch_chest_boat"); + + EntityType BLAZE = getType("blaze"); + + EntityType BLOCK_DISPLAY = getType("block_display"); + + EntityType BOGGED = getType("bogged"); + + EntityType BREEZE = getType("breeze"); + + EntityType BREEZE_WIND_CHARGE = getType("breeze_wind_charge"); + + EntityType CAMEL = getType("camel"); + + EntityType CAMEL_HUSK = getType("camel_husk"); + + EntityType CAT = getType("cat"); + + EntityType CAVE_SPIDER = getType("cave_spider"); + + EntityType CHERRY_BOAT = getType("cherry_boat"); + + EntityType CHERRY_CHEST_BOAT = getType("cherry_chest_boat"); + + EntityType CHEST_MINECART = getType("chest_minecart"); + + EntityType CHICKEN = getType("chicken"); + + EntityType COD = getType("cod"); + + EntityType COMMAND_BLOCK_MINECART = getType("command_block_minecart"); + + EntityType COPPER_GOLEM = getType("copper_golem"); + + EntityType COW = getType("cow"); + + EntityType CREAKING = getType("creaking"); + + EntityType CREEPER = getType("creeper"); + + EntityType DARK_OAK_BOAT = getType("dark_oak_boat"); + + EntityType DARK_OAK_CHEST_BOAT = getType("dark_oak_chest_boat"); + + EntityType DOLPHIN = getType("dolphin"); + + EntityType DONKEY = getType("donkey"); + + EntityType DRAGON_FIREBALL = getType("dragon_fireball"); + + EntityType DROWNED = getType("drowned"); + + EntityType EGG = getType("egg"); + + EntityType ELDER_GUARDIAN = getType("elder_guardian"); + + EntityType END_CRYSTAL = getType("end_crystal"); + + EntityType ENDER_DRAGON = getType("ender_dragon"); + + EntityType ENDER_PEARL = getType("ender_pearl"); + + EntityType ENDERMAN = getType("enderman"); + + EntityType ENDERMITE = getType("endermite"); + + EntityType EVOKER = getType("evoker"); + + EntityType EVOKER_FANGS = getType("evoker_fangs"); + + EntityType EXPERIENCE_BOTTLE = getType("experience_bottle"); + + EntityType EXPERIENCE_ORB = getType("experience_orb"); + + EntityType EYE_OF_ENDER = getType("eye_of_ender"); + + EntityType FALLING_BLOCK = getType("falling_block"); + + EntityType FIREBALL = getType("fireball"); + + EntityType FIREWORK_ROCKET = getType("firework_rocket"); + + EntityType FISHING_BOBBER = getType("fishing_bobber"); + + EntityType FOX = getType("fox"); + + EntityType FROG = getType("frog"); + + EntityType FURNACE_MINECART = getType("furnace_minecart"); + + EntityType GHAST = getType("ghast"); + + EntityType GIANT = getType("giant"); + + EntityType GLOW_ITEM_FRAME = getType("glow_item_frame"); + + EntityType GLOW_SQUID = getType("glow_squid"); + + EntityType GOAT = getType("goat"); + + EntityType GUARDIAN = getType("guardian"); + + EntityType HAPPY_GHAST = getType("happy_ghast"); + + EntityType HOGLIN = getType("hoglin"); + + EntityType HOPPER_MINECART = getType("hopper_minecart"); + + EntityType HORSE = getType("horse"); + + EntityType HUSK = getType("husk"); + + EntityType ILLUSIONER = getType("illusioner"); + + EntityType INTERACTION = getType("interaction"); + + EntityType IRON_GOLEM = getType("iron_golem"); + + EntityType ITEM = getType("item"); + + EntityType ITEM_DISPLAY = getType("item_display"); + + EntityType ITEM_FRAME = getType("item_frame"); + + EntityType JUNGLE_BOAT = getType("jungle_boat"); + + EntityType JUNGLE_CHEST_BOAT = getType("jungle_chest_boat"); + + EntityType LEASH_KNOT = getType("leash_knot"); + + EntityType LIGHTNING_BOLT = getType("lightning_bolt"); + + EntityType LINGERING_POTION = getType("lingering_potion"); + + EntityType LLAMA = getType("llama"); + + EntityType LLAMA_SPIT = getType("llama_spit"); + + EntityType MAGMA_CUBE = getType("magma_cube"); + + EntityType MANGROVE_BOAT = getType("mangrove_boat"); + + EntityType MANGROVE_CHEST_BOAT = getType("mangrove_chest_boat"); + + EntityType MANNEQUIN = getType("mannequin"); + + EntityType MARKER = getType("marker"); + + EntityType MINECART = getType("minecart"); + + EntityType MOOSHROOM = getType("mooshroom"); + + EntityType MULE = getType("mule"); + + EntityType NAUTILUS = getType("nautilus"); + + EntityType OAK_BOAT = getType("oak_boat"); + + EntityType OAK_CHEST_BOAT = getType("oak_chest_boat"); + + EntityType OCELOT = getType("ocelot"); + + EntityType OMINOUS_ITEM_SPAWNER = getType("ominous_item_spawner"); + + EntityType PAINTING = getType("painting"); + + EntityType PALE_OAK_BOAT = getType("pale_oak_boat"); + + EntityType PALE_OAK_CHEST_BOAT = getType("pale_oak_chest_boat"); + + EntityType PANDA = getType("panda"); + + EntityType PARCHED = getType("parched"); + + EntityType PARROT = getType("parrot"); + + EntityType PHANTOM = getType("phantom"); + + EntityType PIG = getType("pig"); + + EntityType PIGLIN = getType("piglin"); + + EntityType PIGLIN_BRUTE = getType("piglin_brute"); + + EntityType PILLAGER = getType("pillager"); + + EntityType PLAYER = getType("player"); + + EntityType POLAR_BEAR = getType("polar_bear"); + + EntityType PUFFERFISH = getType("pufferfish"); + + EntityType RABBIT = getType("rabbit"); + + EntityType RAVAGER = getType("ravager"); + + EntityType SALMON = getType("salmon"); + + EntityType SHEEP = getType("sheep"); + + EntityType SHULKER = getType("shulker"); + + EntityType SHULKER_BULLET = getType("shulker_bullet"); + + EntityType SILVERFISH = getType("silverfish"); + + EntityType SKELETON = getType("skeleton"); + + EntityType SKELETON_HORSE = getType("skeleton_horse"); + + EntityType SLIME = getType("slime"); + + EntityType SMALL_FIREBALL = getType("small_fireball"); + + EntityType SNIFFER = getType("sniffer"); + + EntityType SNOW_GOLEM = getType("snow_golem"); + + EntityType SNOWBALL = getType("snowball"); + + EntityType SPAWNER_MINECART = getType("spawner_minecart"); + + EntityType SPECTRAL_ARROW = getType("spectral_arrow"); + + EntityType SPIDER = getType("spider"); + + EntityType SPLASH_POTION = getType("splash_potion"); + + EntityType SPRUCE_BOAT = getType("spruce_boat"); + + EntityType SPRUCE_CHEST_BOAT = getType("spruce_chest_boat"); + + EntityType SQUID = getType("squid"); + + EntityType STRAY = getType("stray"); + + EntityType STRIDER = getType("strider"); + + EntityType TADPOLE = getType("tadpole"); + + EntityType TEXT_DISPLAY = getType("text_display"); + + EntityType TNT = getType("tnt"); + + EntityType TNT_MINECART = getType("tnt_minecart"); + + EntityType TRADER_LLAMA = getType("trader_llama"); + + EntityType TRIDENT = getType("trident"); + + EntityType TROPICAL_FISH = getType("tropical_fish"); + + EntityType TURTLE = getType("turtle"); + + EntityType VEX = getType("vex"); + + EntityType VILLAGER = getType("villager"); + + EntityType VINDICATOR = getType("vindicator"); + + EntityType WANDERING_TRADER = getType("wandering_trader"); + + EntityType WARDEN = getType("warden"); + + EntityType WIND_CHARGE = getType("wind_charge"); + + EntityType WITCH = getType("witch"); + + EntityType WITHER = getType("wither"); + + EntityType WITHER_SKELETON = getType("wither_skeleton"); + + EntityType WITHER_SKULL = getType("wither_skull"); + + EntityType WOLF = getType("wolf"); + + EntityType ZOGLIN = getType("zoglin"); + + EntityType ZOMBIE = getType("zombie"); + + EntityType ZOMBIE_HORSE = getType("zombie_horse"); + + EntityType ZOMBIE_NAUTILUS = getType("zombie_nautilus"); + + EntityType ZOMBIE_VILLAGER = getType("zombie_villager"); + + EntityType ZOMBIFIED_PIGLIN = getType("zombified_piglin"); // End generate - EntityType + /** * An unknown entity without an Entity Class */ - UNKNOWN(null, null, -1, false); - - private final String name; - private final Class clazz; - private final short typeId; - private final boolean independent, living; - private final NamespacedKey key; - - private static final Map NAME_MAP = new HashMap(); - private static final Map ID_MAP = new HashMap(); - - static { - for (EntityType type : values()) { - if (type.name != null) { - NAME_MAP.put(type.name.toLowerCase(Locale.ROOT), type); - } - if (type.typeId > 0) { - ID_MAP.put(type.typeId, type); - } - } - } - - private EntityType(/*@Nullable*/ String name, /*@Nullable*/ Class clazz, int typeId) { - this(name, clazz, typeId, true); - } + @Deprecated(since = "1.21.11", forRemoval = true) @org.jetbrains.annotations.ApiStatus.ScheduledForRemoval(inVersion = "1.22") // Paper - will be removed via asm-utils + EntityType UNKNOWN = InternalAPIBridge.get().constructLegacyUnknownEntityType(); - private EntityType(/*@Nullable*/ String name, /*@Nullable*/ Class clazz, int typeId, boolean independent) { - this.name = name; - this.clazz = clazz; - this.typeId = (short) typeId; - this.independent = independent; - this.living = clazz != null && LivingEntity.class.isAssignableFrom(clazz); - this.key = (name == null) ? null : NamespacedKey.minecraft(name); + @SuppressWarnings("unchecked") + private static EntityType getType(final @KeyPattern.Value String key) { + return (EntityType) Registry.ENTITY_TYPE.getOrThrow(Key.key(Key.MINECRAFT_NAMESPACE, key)); } /** @@ -249,23 +385,9 @@ private EntityType(/*@Nullable*/ String name, /*@Nullable*/ Class getEntityClass() { - return clazz; - } + @Nullable Class getEntityClass(); /** * Gets the entity type id. @@ -274,9 +396,7 @@ public Class getEntityClass() { * @deprecated Magic value */ @Deprecated(since = "1.6.2", forRemoval = true) - public short getTypeId() { - return typeId; - } + short getTypeId(); /** * Gets an entity type from its name. @@ -285,14 +405,13 @@ public short getTypeId() { * @return the matching entity type or null * @apiNote Internal Use Only */ - @org.jetbrains.annotations.ApiStatus.Internal // Paper + @ApiStatus.Internal @Contract("null -> null") - @Nullable - public static EntityType fromName(@Nullable String name) { + static @Nullable EntityType fromName(@Nullable String name) { if (name == null) { return null; } - return NAME_MAP.get(name.toLowerCase(Locale.ROOT)); + return Registry.ENTITY_TYPE.get(Key.key(Key.MINECRAFT_NAMESPACE, name.toLowerCase(Locale.ROOT))); } /** @@ -303,12 +422,12 @@ public static EntityType fromName(@Nullable String name) { * @deprecated Magic value */ @Deprecated(since = "1.6.2", forRemoval = true) - @Nullable - public static EntityType fromId(int id) { + static @Nullable EntityType fromId(int id) { if (id > Short.MAX_VALUE) { return null; } - return ID_MAP.get((short) id); + return null; + //return ID_MAP.get((short) id); } /** @@ -319,39 +438,30 @@ public static EntityType fromId(int id) { * * @return False if the entity type cannot be spawned */ - public boolean isSpawnable() { - return independent; - } + boolean isSpawnable(); - public boolean isAlive() { - return living; - } + boolean isAlive(); + /** + * @throws IllegalArgumentException if the entity does not have a translation key (is probably a custom entity) + */ @Override - @NotNull - @Deprecated(forRemoval = true) // Paper - public String getTranslationKey() { - return Bukkit.getUnsafe().getTranslationKey(this); + default String getTranslationKey() { + return this.translationKey(); } - // Paper start /** * @throws IllegalArgumentException if the entity does not have a translation key (is probably a custom entity) */ @Override - public @NotNull String translationKey() { - Preconditions.checkArgument(this != UNKNOWN, "UNKNOWN entities do not have translation keys"); - return org.bukkit.Bukkit.getUnsafe().getTranslationKey(this); - } + String translationKey(); /** * Checks if the entity has default attributes. * * @return true if it has default attributes */ - public boolean hasDefaultAttributes() { - return org.bukkit.Bukkit.getUnsafe().hasDefaultEntityAttributes(this.key); - } + boolean hasDefaultAttributes(); /** * Gets the default attributes for the entity. @@ -359,8 +469,31 @@ public boolean hasDefaultAttributes() { * @return an unmodifiable instance of Attributable for reading default attributes. * @throws IllegalArgumentException if the entity does not exist of have default attributes (use {@link #hasDefaultAttributes()} first) */ - public @NotNull org.bukkit.attribute.Attributable getDefaultAttributes() { - return org.bukkit.Bukkit.getUnsafe().getDefaultEntityAttributes(this.key); + Attributable getDefaultAttributes(); + + /** + * @param name of the entity type. + * @return the entity type with the given name. + * @deprecated only for backwards compatibility, use {@link Registry#get(NamespacedKey)} instead. + */ + @Deprecated(since = "1.21.11", forRemoval = true) @ApiStatus.ScheduledForRemoval(inVersion = "1.22") // Paper - will be removed via asm-utils + static EntityType valueOf(String name) { + if ("UNKNOWN".equals(name)) { + return EntityType.UNKNOWN; + } + + NamespacedKey key = NamespacedKey.fromString(name.toLowerCase(Locale.ROOT)); + EntityType entityType = key == null ? null : Bukkit.getUnsafe().get(RegistryKey.ENTITY_TYPE, key); + Preconditions.checkArgument(entityType != null, "No entity type found with the name %s", name); + return entityType; + } + + /** + * @return an array of all known entity types. + * @deprecated use {@link Registry#stream()}. + */ + @Deprecated(since = "1.21.11", forRemoval = true) @ApiStatus.ScheduledForRemoval(inVersion = "1.22") // Paper - will be removed via asm-utils + static EntityType[] values() { + return Registry.ENTITY_TYPE.stream().toArray(EntityType[]::new); } - // Paper end } diff --git a/paper-api/src/main/java/org/bukkit/entity/boat/AcaciaBoat.java b/paper-api/src/main/java/org/bukkit/entity/boat/AcaciaBoat.java index 889eba923d3f..2a6e1f5cf5ec 100644 --- a/paper-api/src/main/java/org/bukkit/entity/boat/AcaciaBoat.java +++ b/paper-api/src/main/java/org/bukkit/entity/boat/AcaciaBoat.java @@ -5,5 +5,6 @@ /** * Represents an acacia boat. */ +@Deprecated(since = "1.21.11", forRemoval = true) public interface AcaciaBoat extends Boat { } diff --git a/paper-api/src/main/java/org/bukkit/entity/boat/AcaciaChestBoat.java b/paper-api/src/main/java/org/bukkit/entity/boat/AcaciaChestBoat.java index 892d60a22bfd..c68b90018672 100644 --- a/paper-api/src/main/java/org/bukkit/entity/boat/AcaciaChestBoat.java +++ b/paper-api/src/main/java/org/bukkit/entity/boat/AcaciaChestBoat.java @@ -5,5 +5,6 @@ /** * Represents an acacia chest boat. */ +@Deprecated(since = "1.21.11", forRemoval = true) public interface AcaciaChestBoat extends ChestBoat { } diff --git a/paper-api/src/main/java/org/bukkit/entity/boat/BambooChestRaft.java b/paper-api/src/main/java/org/bukkit/entity/boat/BambooChestRaft.java index 34e03c0852a3..f39f8f54c50b 100644 --- a/paper-api/src/main/java/org/bukkit/entity/boat/BambooChestRaft.java +++ b/paper-api/src/main/java/org/bukkit/entity/boat/BambooChestRaft.java @@ -5,5 +5,6 @@ /** * Represents a bamboo chest raft. */ +@Deprecated(since = "1.21.11", forRemoval = true) public interface BambooChestRaft extends ChestBoat { } diff --git a/paper-api/src/main/java/org/bukkit/entity/boat/BambooRaft.java b/paper-api/src/main/java/org/bukkit/entity/boat/BambooRaft.java index 9e49f65eed63..ca0dd4c872a0 100644 --- a/paper-api/src/main/java/org/bukkit/entity/boat/BambooRaft.java +++ b/paper-api/src/main/java/org/bukkit/entity/boat/BambooRaft.java @@ -5,5 +5,6 @@ /** * Represents a bamboo raft. */ +@Deprecated(since = "1.21.11", forRemoval = true) public interface BambooRaft extends Boat { } diff --git a/paper-api/src/main/java/org/bukkit/entity/boat/BirchBoat.java b/paper-api/src/main/java/org/bukkit/entity/boat/BirchBoat.java index def3cb215aae..2c9160a2c029 100644 --- a/paper-api/src/main/java/org/bukkit/entity/boat/BirchBoat.java +++ b/paper-api/src/main/java/org/bukkit/entity/boat/BirchBoat.java @@ -5,5 +5,6 @@ /** * Represents a birch boat. */ +@Deprecated(since = "1.21.11", forRemoval = true) public interface BirchBoat extends Boat { } diff --git a/paper-api/src/main/java/org/bukkit/entity/boat/BirchChestBoat.java b/paper-api/src/main/java/org/bukkit/entity/boat/BirchChestBoat.java index 88e6b88c2cd0..766933992f43 100644 --- a/paper-api/src/main/java/org/bukkit/entity/boat/BirchChestBoat.java +++ b/paper-api/src/main/java/org/bukkit/entity/boat/BirchChestBoat.java @@ -5,5 +5,6 @@ /** * Represents a birch chest boat. */ +@Deprecated(since = "1.21.11", forRemoval = true) public interface BirchChestBoat extends ChestBoat { } diff --git a/paper-api/src/main/java/org/bukkit/entity/boat/CherryBoat.java b/paper-api/src/main/java/org/bukkit/entity/boat/CherryBoat.java index 91f8a20437a8..562c64bd98bd 100644 --- a/paper-api/src/main/java/org/bukkit/entity/boat/CherryBoat.java +++ b/paper-api/src/main/java/org/bukkit/entity/boat/CherryBoat.java @@ -5,5 +5,6 @@ /** * Represents a cherry boat. */ +@Deprecated(since = "1.21.11", forRemoval = true) public interface CherryBoat extends Boat { } diff --git a/paper-api/src/main/java/org/bukkit/entity/boat/CherryChestBoat.java b/paper-api/src/main/java/org/bukkit/entity/boat/CherryChestBoat.java index 0b68d971a0d6..10d09bb4e30c 100644 --- a/paper-api/src/main/java/org/bukkit/entity/boat/CherryChestBoat.java +++ b/paper-api/src/main/java/org/bukkit/entity/boat/CherryChestBoat.java @@ -5,5 +5,6 @@ /** * Represents a cherry chest boat. */ +@Deprecated(since = "1.21.11", forRemoval = true) public interface CherryChestBoat extends ChestBoat { } diff --git a/paper-api/src/main/java/org/bukkit/entity/boat/DarkOakBoat.java b/paper-api/src/main/java/org/bukkit/entity/boat/DarkOakBoat.java index c2493b3cd940..ba07ca0952f5 100644 --- a/paper-api/src/main/java/org/bukkit/entity/boat/DarkOakBoat.java +++ b/paper-api/src/main/java/org/bukkit/entity/boat/DarkOakBoat.java @@ -5,5 +5,6 @@ /** * Represents a dark oak boat. */ +@Deprecated(since = "1.21.11", forRemoval = true) public interface DarkOakBoat extends Boat { } diff --git a/paper-api/src/main/java/org/bukkit/entity/boat/DarkOakChestBoat.java b/paper-api/src/main/java/org/bukkit/entity/boat/DarkOakChestBoat.java index a18dfac694b8..7342a836a1a7 100644 --- a/paper-api/src/main/java/org/bukkit/entity/boat/DarkOakChestBoat.java +++ b/paper-api/src/main/java/org/bukkit/entity/boat/DarkOakChestBoat.java @@ -5,5 +5,6 @@ /** * Represents a dark oak chest boat. */ +@Deprecated(since = "1.21.11", forRemoval = true) public interface DarkOakChestBoat extends ChestBoat { } diff --git a/paper-api/src/main/java/org/bukkit/entity/boat/JungleBoat.java b/paper-api/src/main/java/org/bukkit/entity/boat/JungleBoat.java index 60f0e0d3fc9b..7bcfb504207b 100644 --- a/paper-api/src/main/java/org/bukkit/entity/boat/JungleBoat.java +++ b/paper-api/src/main/java/org/bukkit/entity/boat/JungleBoat.java @@ -5,5 +5,6 @@ /** * Represents a jungle boat. */ +@Deprecated(since = "1.21.11", forRemoval = true) public interface JungleBoat extends Boat { } diff --git a/paper-api/src/main/java/org/bukkit/entity/boat/JungleChestBoat.java b/paper-api/src/main/java/org/bukkit/entity/boat/JungleChestBoat.java index eda4aa1ba17b..b1c95ce78a10 100644 --- a/paper-api/src/main/java/org/bukkit/entity/boat/JungleChestBoat.java +++ b/paper-api/src/main/java/org/bukkit/entity/boat/JungleChestBoat.java @@ -5,5 +5,6 @@ /** * Represents a jungle chest boat. */ +@Deprecated(since = "1.21.11", forRemoval = true) public interface JungleChestBoat extends ChestBoat { } diff --git a/paper-api/src/main/java/org/bukkit/entity/boat/MangroveBoat.java b/paper-api/src/main/java/org/bukkit/entity/boat/MangroveBoat.java index 579697161dc8..05536b970248 100644 --- a/paper-api/src/main/java/org/bukkit/entity/boat/MangroveBoat.java +++ b/paper-api/src/main/java/org/bukkit/entity/boat/MangroveBoat.java @@ -5,5 +5,6 @@ /** * Represents a mangrove boat. */ +@Deprecated(since = "1.21.11", forRemoval = true) public interface MangroveBoat extends Boat { } diff --git a/paper-api/src/main/java/org/bukkit/entity/boat/MangroveChestBoat.java b/paper-api/src/main/java/org/bukkit/entity/boat/MangroveChestBoat.java index 957ba1dbec13..51298485b977 100644 --- a/paper-api/src/main/java/org/bukkit/entity/boat/MangroveChestBoat.java +++ b/paper-api/src/main/java/org/bukkit/entity/boat/MangroveChestBoat.java @@ -5,5 +5,6 @@ /** * Represents a mangrove chest boat. */ +@Deprecated(since = "1.21.11", forRemoval = true) public interface MangroveChestBoat extends ChestBoat { } diff --git a/paper-api/src/main/java/org/bukkit/entity/boat/OakBoat.java b/paper-api/src/main/java/org/bukkit/entity/boat/OakBoat.java index 48be7bcbf58b..b359f901be5a 100644 --- a/paper-api/src/main/java/org/bukkit/entity/boat/OakBoat.java +++ b/paper-api/src/main/java/org/bukkit/entity/boat/OakBoat.java @@ -5,5 +5,6 @@ /** * Represents an oak boat. */ +@Deprecated(since = "1.21.11", forRemoval = true) public interface OakBoat extends Boat { } diff --git a/paper-api/src/main/java/org/bukkit/entity/boat/OakChestBoat.java b/paper-api/src/main/java/org/bukkit/entity/boat/OakChestBoat.java index f432ec8bedf3..162a74371560 100644 --- a/paper-api/src/main/java/org/bukkit/entity/boat/OakChestBoat.java +++ b/paper-api/src/main/java/org/bukkit/entity/boat/OakChestBoat.java @@ -5,5 +5,6 @@ /** * Represents an oak chest boat. */ +@Deprecated(since = "1.21.11", forRemoval = true) public interface OakChestBoat extends ChestBoat { } diff --git a/paper-api/src/main/java/org/bukkit/entity/boat/PaleOakBoat.java b/paper-api/src/main/java/org/bukkit/entity/boat/PaleOakBoat.java index 8b927c0112d3..5e7f0b4aeba6 100644 --- a/paper-api/src/main/java/org/bukkit/entity/boat/PaleOakBoat.java +++ b/paper-api/src/main/java/org/bukkit/entity/boat/PaleOakBoat.java @@ -5,5 +5,6 @@ /** * Represents a pale oak boat. */ +@Deprecated(since = "1.21.11", forRemoval = true) public interface PaleOakBoat extends Boat { } diff --git a/paper-api/src/main/java/org/bukkit/entity/boat/PaleOakChestBoat.java b/paper-api/src/main/java/org/bukkit/entity/boat/PaleOakChestBoat.java index 97341eb0177a..0c55a4058ca9 100644 --- a/paper-api/src/main/java/org/bukkit/entity/boat/PaleOakChestBoat.java +++ b/paper-api/src/main/java/org/bukkit/entity/boat/PaleOakChestBoat.java @@ -5,5 +5,6 @@ /** * Represents a pale oak chest boat. */ +@Deprecated(since = "1.21.11", forRemoval = true) public interface PaleOakChestBoat extends ChestBoat { } diff --git a/paper-api/src/main/java/org/bukkit/entity/boat/SpruceBoat.java b/paper-api/src/main/java/org/bukkit/entity/boat/SpruceBoat.java index d9bf4480f5a0..10021fa5353c 100644 --- a/paper-api/src/main/java/org/bukkit/entity/boat/SpruceBoat.java +++ b/paper-api/src/main/java/org/bukkit/entity/boat/SpruceBoat.java @@ -5,5 +5,6 @@ /** * Represents a spruce boat. */ +@Deprecated(since = "1.21.11", forRemoval = true) public interface SpruceBoat extends Boat { } diff --git a/paper-api/src/main/java/org/bukkit/entity/boat/SpruceChestBoat.java b/paper-api/src/main/java/org/bukkit/entity/boat/SpruceChestBoat.java index fa8986b1e487..f43cfb9c0271 100644 --- a/paper-api/src/main/java/org/bukkit/entity/boat/SpruceChestBoat.java +++ b/paper-api/src/main/java/org/bukkit/entity/boat/SpruceChestBoat.java @@ -5,5 +5,6 @@ /** * Represents a spruce chest boat. */ +@Deprecated(since = "1.21.11", forRemoval = true) public interface SpruceChestBoat extends ChestBoat { } diff --git a/paper-api/src/main/java/org/bukkit/entity/boat/package-info.java b/paper-api/src/main/java/org/bukkit/entity/boat/package-info.java index 1167ee2bcaa8..6d655f246073 100644 --- a/paper-api/src/main/java/org/bukkit/entity/boat/package-info.java +++ b/paper-api/src/main/java/org/bukkit/entity/boat/package-info.java @@ -1,4 +1,5 @@ /** * Interfaces for various {@link org.bukkit.entity.Boat} types. */ +@Deprecated(since = "1.21.11", forRemoval = true) package org.bukkit.entity.boat; diff --git a/paper-api/src/main/java/org/bukkit/event/player/PlayerEggThrowEvent.java b/paper-api/src/main/java/org/bukkit/event/player/PlayerEggThrowEvent.java index 63181a864bb4..5fed59b92b55 100644 --- a/paper-api/src/main/java/org/bukkit/event/player/PlayerEggThrowEvent.java +++ b/paper-api/src/main/java/org/bukkit/event/player/PlayerEggThrowEvent.java @@ -64,7 +64,7 @@ public void setHatching(boolean hatching) { * @return The type of the mob being hatched by the egg */ @NotNull - public EntityType getHatchingType() { + public EntityType getHatchingType() { return this.hatchType; } @@ -73,7 +73,7 @@ public EntityType getHatchingType() { * * @param hatchType The type of the mob being hatched by the egg */ - public void setHatchingType(@NotNull EntityType hatchType) { + public void setHatchingType(@NotNull EntityType hatchType) { if (!hatchType.isSpawnable()) throw new IllegalArgumentException("Can't spawn that entity type from an egg!"); this.hatchType = hatchType; } diff --git a/paper-api/src/main/java/org/bukkit/inventory/meta/components/EquippableComponent.java b/paper-api/src/main/java/org/bukkit/inventory/meta/components/EquippableComponent.java index e462ae9f9c72..ccd00a30f7aa 100644 --- a/paper-api/src/main/java/org/bukkit/inventory/meta/components/EquippableComponent.java +++ b/paper-api/src/main/java/org/bukkit/inventory/meta/components/EquippableComponent.java @@ -83,7 +83,7 @@ public interface EquippableComponent extends ConfigurationSerializable { * @return the entities */ @Nullable - Collection getAllowedEntities(); + Collection> getAllowedEntities(); /** * Sets the entities which can equip this item. diff --git a/paper-api/src/test/java/org/bukkit/support/AbstractTestingBase.java b/paper-api/src/test/java/org/bukkit/support/AbstractTestingBase.java deleted file mode 100644 index 759e1ced833a..000000000000 --- a/paper-api/src/test/java/org/bukkit/support/AbstractTestingBase.java +++ /dev/null @@ -1,13 +0,0 @@ -package org.bukkit.support; - -/** - * If you are getting: java.lang.ExceptionInInitializerError - * - * extend this class to solve it. - */ -public abstract class AbstractTestingBase { - - static { - TestServer.setup(); - } -} diff --git a/paper-api/src/test/java/org/bukkit/support/TestServer.java b/paper-api/src/test/java/org/bukkit/support/TestServer.java deleted file mode 100644 index 494419922f11..000000000000 --- a/paper-api/src/test/java/org/bukkit/support/TestServer.java +++ /dev/null @@ -1,63 +0,0 @@ -package org.bukkit.support; - -import static org.mockito.Mockito.*; -import com.google.common.base.Preconditions; -import java.util.HashMap; -import java.util.Iterator; -import java.util.Locale; -import java.util.Map; -import java.util.logging.Logger; -import java.util.stream.Stream; -import org.bukkit.Bukkit; -import org.bukkit.Keyed; -import org.bukkit.NamespacedKey; -import org.bukkit.Registry; -import org.bukkit.Server; -import org.bukkit.UnsafeValues; -import org.bukkit.command.SimpleCommandMap; -import org.bukkit.plugin.PluginManager; -import org.bukkit.plugin.SimplePluginManager; -import org.jetbrains.annotations.NotNull; - -public final class TestServer { - - static { - Server instance = mock(withSettings().stubOnly()); - - Thread creatingThread = Thread.currentThread(); - when(instance.isPrimaryThread()).then(mock -> Thread.currentThread().equals(creatingThread)); - - // Paper - remove plugin manager for Paper Plugins - - Logger logger = Logger.getLogger(TestServer.class.getCanonicalName()); - when(instance.getLogger()).thenReturn(logger); - - when(instance.getName()).thenReturn(TestServer.class.getSimpleName()); - - when(instance.getVersion()).thenReturn("Version_" + TestServer.class.getPackage().getImplementationVersion()); - - when(instance.getBukkitVersion()).thenReturn("BukkitVersion_" + TestServer.class.getPackage().getImplementationVersion()); - - // Paper start - RegistryAccess - when(instance.getRegistry(any())).then(invocationOnMock -> { - return io.papermc.paper.registry.RegistryAccess.registryAccess().getRegistry(((Class)invocationOnMock.getArgument(0))); - }); - // Paper end - RegistryAccess - - UnsafeValues unsafeValues = mock(withSettings().stubOnly()); - when(instance.getUnsafe()).thenReturn(unsafeValues); - - // Paper start - testing changes - when(instance.getTag(anyString(), any(NamespacedKey.class), any())).thenAnswer(ignored -> new io.papermc.paper.testing.EmptyTag()); - when(instance.getScoreboardCriteria(anyString())).thenReturn(null); - // Paper end - testing changes - - Bukkit.setServer(instance); - } - - private TestServer() { - } - - public static void setup() { - } -} diff --git a/paper-generator/src/main/java/io/papermc/generator/Rewriters.java b/paper-generator/src/main/java/io/papermc/generator/Rewriters.java index 6a337d533bff..5435cadf5df0 100644 --- a/paper-generator/src/main/java/io/papermc/generator/Rewriters.java +++ b/paper-generator/src/main/java/io/papermc/generator/Rewriters.java @@ -111,7 +111,6 @@ public static void bootstrap(PatternSourceSetRewriter apiSourceSet, PatternSourc private static void bootstrapApi(PatternSourceSetRewriter sourceSet) { sourceSet .register("PotionType", PotionType.class, new EnumRegistryRewriter<>(Registries.POTION)) - .register("EntityType", EntityType.class, new EntityTypeRewriter()) .register("DisplaySlot", DisplaySlot.class, new EnumCloneRewriter<>(net.minecraft.world.scores.DisplaySlot.class) { @Override protected EnumValue.Builder rewriteEnumValue(net.minecraft.world.scores.DisplaySlot slot) { @@ -226,6 +225,7 @@ protected String rewriteFieldType(Holder.Reference generators) { generators.add(new GeneratedTagKeyType(entry, PAPER_REGISTRY_PACKAGE + ".keys.tags")); } }); - - // todo remove once entity type is a registry - generators.add(new GeneratedTagKeyType(RegistryEntries.byRegistryKey(Registries.ENTITY_TYPE), PAPER_REGISTRY_PACKAGE + ".keys.tags")); } public static void bootstrap(PatternSourceSetRewriter apiSourceSet, PatternSourceSetRewriter serverSourceSet) { diff --git a/paper-generator/src/main/java/io/papermc/generator/registry/RegistryEntries.java b/paper-generator/src/main/java/io/papermc/generator/registry/RegistryEntries.java index 0a9f1e9a68f7..e7cd60ab5df5 100644 --- a/paper-generator/src/main/java/io/papermc/generator/registry/RegistryEntries.java +++ b/paper-generator/src/main/java/io/papermc/generator/registry/RegistryEntries.java @@ -170,7 +170,8 @@ private static RegistryEntry inconsistentEntry(ResourceKey> DATA_DRIVEN = List.of( @@ -196,7 +197,6 @@ private static RegistryEntry inconsistentEntry(ResourceKey> API_ONLY = List.of( - entry(Registries.ENTITY_TYPE, net.minecraft.world.entity.EntityType.class, EntityType.class), entry(Registries.PARTICLE_TYPE, ParticleTypes.class, Particle.class), entry(Registries.POTION, Potions.class, PotionType.class), entry(Registries.MEMORY_MODULE_TYPE, MemoryModuleType.class, MemoryKey.class) diff --git a/paper-generator/src/main/java/io/papermc/generator/rewriter/types/simple/EntityTypeRewriter.java b/paper-generator/src/main/java/io/papermc/generator/rewriter/types/simple/EntityTypeRewriter.java index 3b8785d64dee..3dd46cc5428b 100644 --- a/paper-generator/src/main/java/io/papermc/generator/rewriter/types/simple/EntityTypeRewriter.java +++ b/paper-generator/src/main/java/io/papermc/generator/rewriter/types/simple/EntityTypeRewriter.java @@ -4,18 +4,12 @@ import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableMap; import io.papermc.generator.registry.RegistryEntries; -import io.papermc.generator.rewriter.types.registry.EnumRegistryRewriter; +import io.papermc.generator.rewriter.types.registry.RegistryFieldRewriter; import io.papermc.generator.types.goal.MobGoalNames; import io.papermc.typewriter.ClassNamed; -import io.papermc.typewriter.preset.model.EnumValue; import io.papermc.typewriter.util.ClassResolver; -import it.unimi.dsi.fastutil.objects.Object2IntMap; -import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap; import java.lang.reflect.ParameterizedType; -import java.util.ArrayList; -import java.util.List; import java.util.Map; -import net.minecraft.util.Util; import net.minecraft.core.Holder; import net.minecraft.core.registries.Registries; import net.minecraft.resources.ResourceKey; @@ -23,9 +17,7 @@ import net.minecraft.world.entity.EntityType; import net.minecraft.world.entity.Mob; -import static io.papermc.generator.utils.Formatting.quoted; - -public class EntityTypeRewriter extends EnumRegistryRewriter> { +public class EntityTypeRewriter extends RegistryFieldRewriter> { private static final Map>, Class> ENTITY_GENERIC_TYPES = RegistryEntries.byRegistryKey(Registries.ENTITY_TYPE).getFields(field -> { @@ -51,115 +43,18 @@ public class EntityTypeRewriter extends EnumRegistryRewriter> { .put("FurnaceMinecart", "PoweredMinecart") .buildOrThrow(); - @Deprecated - private static final Object2IntMap> LEGACY_ID = Util.make(new Object2IntOpenHashMap<>(), map -> { - map.put(EntityType.ITEM, 1); - map.put(EntityType.EXPERIENCE_ORB, 2); - map.put(EntityType.AREA_EFFECT_CLOUD, 3); - map.put(EntityType.ELDER_GUARDIAN, 4); - map.put(EntityType.WITHER_SKELETON, 5); - map.put(EntityType.STRAY, 6); - map.put(EntityType.EGG, 7); - map.put(EntityType.LEASH_KNOT, 8); - map.put(EntityType.PAINTING, 9); - map.put(EntityType.ARROW, 10); - map.put(EntityType.SNOWBALL, 11); - map.put(EntityType.FIREBALL, 12); - map.put(EntityType.SMALL_FIREBALL, 13); - map.put(EntityType.ENDER_PEARL, 14); - map.put(EntityType.EYE_OF_ENDER, 15); - map.put(EntityType.SPLASH_POTION, 16); - map.put(EntityType.EXPERIENCE_BOTTLE, 17); - map.put(EntityType.ITEM_FRAME, 18); - map.put(EntityType.WITHER_SKULL, 19); - map.put(EntityType.TNT, 20); - map.put(EntityType.FALLING_BLOCK, 21); - map.put(EntityType.FIREWORK_ROCKET, 22); - map.put(EntityType.HUSK, 23); - map.put(EntityType.SPECTRAL_ARROW, 24); - map.put(EntityType.SHULKER_BULLET, 25); - map.put(EntityType.DRAGON_FIREBALL, 26); - map.put(EntityType.ZOMBIE_VILLAGER, 27); - map.put(EntityType.SKELETON_HORSE, 28); - map.put(EntityType.ZOMBIE_HORSE, 29); - map.put(EntityType.ARMOR_STAND, 30); - map.put(EntityType.DONKEY, 31); - map.put(EntityType.MULE, 32); - map.put(EntityType.EVOKER_FANGS, 33); - map.put(EntityType.EVOKER, 34); - map.put(EntityType.VEX, 35); - map.put(EntityType.VINDICATOR, 36); - map.put(EntityType.ILLUSIONER, 37); - - map.put(EntityType.COMMAND_BLOCK_MINECART, 40); - map.put(EntityType.MINECART, 42); - map.put(EntityType.CHEST_MINECART, 43); - map.put(EntityType.FURNACE_MINECART, 44); - map.put(EntityType.TNT_MINECART, 45); - map.put(EntityType.HOPPER_MINECART, 46); - map.put(EntityType.SPAWNER_MINECART, 47); - - map.put(EntityType.CREEPER, 50); - map.put(EntityType.SKELETON, 51); - map.put(EntityType.SPIDER, 52); - map.put(EntityType.GIANT, 53); - map.put(EntityType.ZOMBIE, 54); - map.put(EntityType.SLIME, 55); - map.put(EntityType.GHAST, 56); - map.put(EntityType.ZOMBIFIED_PIGLIN, 57); - map.put(EntityType.ENDERMAN, 58); - map.put(EntityType.CAVE_SPIDER, 59); - map.put(EntityType.SILVERFISH, 60); - map.put(EntityType.BLAZE, 61); - map.put(EntityType.MAGMA_CUBE, 62); - map.put(EntityType.ENDER_DRAGON, 63); - map.put(EntityType.WITHER, 64); - map.put(EntityType.BAT, 65); - map.put(EntityType.WITCH, 66); - map.put(EntityType.ENDERMITE, 67); - map.put(EntityType.GUARDIAN, 68); - map.put(EntityType.SHULKER, 69); - - map.put(EntityType.PIG, 90); - map.put(EntityType.SHEEP, 91); - map.put(EntityType.COW, 92); - map.put(EntityType.CHICKEN, 93); - map.put(EntityType.SQUID, 94); - map.put(EntityType.WOLF, 95); - map.put(EntityType.MOOSHROOM, 96); - map.put(EntityType.SNOW_GOLEM, 97); - map.put(EntityType.OCELOT, 98); - map.put(EntityType.IRON_GOLEM, 99); - map.put(EntityType.HORSE, 100); - map.put(EntityType.RABBIT, 101); - map.put(EntityType.POLAR_BEAR, 102); - map.put(EntityType.LLAMA, 103); - map.put(EntityType.LLAMA_SPIT, 104); - map.put(EntityType.PARROT, 105); - - map.put(EntityType.VILLAGER, 120); - - map.put(EntityType.END_CRYSTAL, 200); - }); - private static final ClassResolver runtime = new ClassResolver(EntityTypeRewriter.class.getClassLoader()); public EntityTypeRewriter() { - super(Registries.ENTITY_TYPE, false); + super(Registries.ENTITY_TYPE, "getType"); } @Override - protected EnumValue.Builder rewriteEnumValue(Holder.Reference> reference) { - String path = reference.key().identifier().getPath(); - List arguments = new ArrayList<>(4); - arguments.add(quoted(path)); - arguments.add(toBukkitClass(reference).concat(".class")); - arguments.add(Integer.toString(LEGACY_ID.getOrDefault(reference.value(), -1))); - - if (!reference.value().canSummon()) { - arguments.add(Boolean.FALSE.toString()); - } - return super.rewriteEnumValue(reference).arguments(arguments); + protected String rewriteFieldType(Holder.Reference> reference) { + return "%s<%s>".formatted( + super.rewriteFieldType(reference), + toBukkitClass(reference) + ); } private String toBukkitClass(Holder.Reference> reference) { diff --git a/paper-server/src/main/java/io/papermc/paper/PaperServerInternalAPIBridge.java b/paper-server/src/main/java/io/papermc/paper/PaperServerInternalAPIBridge.java index 7435a9ebb62f..91e34a29e9d5 100644 --- a/paper-server/src/main/java/io/papermc/paper/PaperServerInternalAPIBridge.java +++ b/paper-server/src/main/java/io/papermc/paper/PaperServerInternalAPIBridge.java @@ -24,10 +24,12 @@ import org.bukkit.craftbukkit.block.CraftBiome; import org.bukkit.craftbukkit.damage.CraftDamageEffect; import org.bukkit.craftbukkit.damage.CraftDamageSource; +import org.bukkit.craftbukkit.entity.CraftEntityType; import org.bukkit.craftbukkit.entity.CraftLivingEntity; import org.bukkit.craftbukkit.entity.CraftMannequin; import org.bukkit.damage.DamageEffect; import org.bukkit.damage.DamageSource; +import org.bukkit.entity.EntityType; import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Pose; import org.jspecify.annotations.NullMarked; @@ -44,10 +46,12 @@ public DamageEffect getDamageEffect(final String key) { @Override public Biome constructLegacyCustomBiome() { - class Holder { - static final Biome LEGACY_CUSTOM = new CraftBiome.LegacyCustomBiomeImpl(); - } - return Holder.LEGACY_CUSTOM; + return CraftBiome.LegacyCustomImpl.INSTANCE; + } + + @Override + public EntityType constructLegacyUnknownEntityType() { + return CraftEntityType.LegacyUnknownImpl.INSTANCE; } @Override diff --git a/paper-server/src/main/java/io/papermc/paper/datacomponent/item/PaperEquippable.java b/paper-server/src/main/java/io/papermc/paper/datacomponent/item/PaperEquippable.java index aa10ee49b810..5a40f7beb11a 100644 --- a/paper-server/src/main/java/io/papermc/paper/datacomponent/item/PaperEquippable.java +++ b/paper-server/src/main/java/io/papermc/paper/datacomponent/item/PaperEquippable.java @@ -57,7 +57,7 @@ public Key equipSound() { } @Override - public @Nullable RegistryKeySet allowedEntities() { + public @Nullable RegistryKeySet> allowedEntities() { return this.impl.allowedEntities() .map((set) -> PaperRegistrySets.convertToApi(RegistryKey.ENTITY_TYPE, set)) .orElse(null); @@ -150,7 +150,7 @@ public Builder cameraOverlay(@Nullable final Key cameraOverlay) { } @Override - public Builder allowedEntities(final @Nullable RegistryKeySet allowedEntities) { + public Builder allowedEntities(final @Nullable RegistryKeySet> allowedEntities) { this.allowedEntities = Optional.ofNullable(allowedEntities) .map((set) -> PaperRegistrySets.convertToNms(Registries.ENTITY_TYPE, Conversions.global().lookup(), set)); return this; diff --git a/paper-server/src/main/java/io/papermc/paper/registry/PaperRegistries.java b/paper-server/src/main/java/io/papermc/paper/registry/PaperRegistries.java index 121babcfdda5..b916e6fce885 100644 --- a/paper-server/src/main/java/io/papermc/paper/registry/PaperRegistries.java +++ b/paper-server/src/main/java/io/papermc/paper/registry/PaperRegistries.java @@ -61,6 +61,7 @@ import org.bukkit.craftbukkit.entity.CraftCat; import org.bukkit.craftbukkit.entity.CraftChicken; import org.bukkit.craftbukkit.entity.CraftCow; +import org.bukkit.craftbukkit.entity.CraftEntityType; import org.bukkit.craftbukkit.entity.CraftFrog; import org.bukkit.craftbukkit.entity.CraftPig; import org.bukkit.craftbukkit.entity.CraftVillager; @@ -81,6 +82,7 @@ import org.bukkit.entity.Cat; import org.bukkit.entity.Chicken; import org.bukkit.entity.Cow; +import org.bukkit.entity.EntityType; import org.bukkit.entity.Frog; import org.bukkit.entity.Pig; import org.bukkit.entity.Villager; @@ -121,6 +123,7 @@ public final class PaperRegistries { start(Registries.SOUND_EVENT, RegistryKey.SOUND_EVENT).craft(Sound.class, CraftSound::new, true).create(PaperSoundEventRegistryEntry.PaperBuilder::new, RegistryEntryMeta.RegistryModificationApiSupport.NONE), start(Registries.DATA_COMPONENT_TYPE, RegistryKey.DATA_COMPONENT_TYPE).craft(DataComponentTypes.class, PaperDataComponentType::of).build(), start(Registries.GAME_RULE, RegistryKey.GAME_RULE).craft(GameRule.class, CraftGameRule::new).build(), + start(Registries.ENTITY_TYPE, RegistryKey.ENTITY_TYPE).craft(EntityType.class, CraftEntityType::new).serializationUpdater(FieldRename.ENTITY_TYPE_RENAME).build(), // data-driven start(Registries.BIOME, RegistryKey.BIOME).craft(Biome.class, CraftBiome::new).build().delayed(), @@ -144,7 +147,6 @@ public final class PaperRegistries { start(Registries.DIALOG, RegistryKey.DIALOG).craft(Dialog.class, PaperDialog::new, true).writable(PaperDialogRegistryEntry.PaperBuilder::new), // api-only - start(Registries.ENTITY_TYPE, RegistryKey.ENTITY_TYPE).apiOnly(PaperSimpleRegistry::entityType), start(Registries.PARTICLE_TYPE, RegistryKey.PARTICLE_TYPE).apiOnly(PaperSimpleRegistry::particleType), start(Registries.POTION, RegistryKey.POTION).apiOnly(PaperSimpleRegistry::potion), start(Registries.MEMORY_MODULE_TYPE, RegistryKey.MEMORY_MODULE_TYPE).apiOnly(() -> org.bukkit.Registry.MEMORY_MODULE_TYPE) diff --git a/paper-server/src/main/java/io/papermc/paper/registry/PaperSimpleRegistry.java b/paper-server/src/main/java/io/papermc/paper/registry/PaperSimpleRegistry.java index 7c3fdfb46efb..1e4a6bd9d494 100644 --- a/paper-server/src/main/java/io/papermc/paper/registry/PaperSimpleRegistry.java +++ b/paper-server/src/main/java/io/papermc/paper/registry/PaperSimpleRegistry.java @@ -10,17 +10,12 @@ import org.bukkit.Keyed; import org.bukkit.Particle; import org.bukkit.Registry; -import org.bukkit.entity.EntityType; import org.bukkit.potion.PotionType; import org.jspecify.annotations.NullMarked; @NullMarked public class PaperSimpleRegistry & Keyed, M> extends Registry.SimpleRegistry { - static Registry entityType() { - return new PaperSimpleRegistry<>(EntityType.class, entity -> entity != EntityType.UNKNOWN, BuiltInRegistries.ENTITY_TYPE); - } - static Registry particleType() { return new PaperSimpleRegistry<>(Particle.class, BuiltInRegistries.PARTICLE_TYPE); } diff --git a/paper-server/src/main/java/io/papermc/paper/world/flag/PaperFeatureFlagProviderImpl.java b/paper-server/src/main/java/io/papermc/paper/world/flag/PaperFeatureFlagProviderImpl.java index c0953bb67dcf..fa10df16ab3e 100644 --- a/paper-server/src/main/java/io/papermc/paper/world/flag/PaperFeatureFlagProviderImpl.java +++ b/paper-server/src/main/java/io/papermc/paper/world/flag/PaperFeatureFlagProviderImpl.java @@ -11,9 +11,7 @@ import org.bukkit.FeatureFlag; import org.bukkit.GameRule; import org.bukkit.craftbukkit.CraftGameRule; -import org.bukkit.craftbukkit.entity.CraftEntityType; import org.bukkit.craftbukkit.potion.CraftPotionType; -import org.bukkit.entity.EntityType; import org.bukkit.potion.PotionType; public class PaperFeatureFlagProviderImpl implements FeatureFlagProvider { @@ -44,10 +42,7 @@ public static Set fromNms(final FeatureFlagSet flagSet) { } static FeatureElement getFeatureElement(final FeatureDependant dependant) { - if (dependant instanceof final EntityType entityType) { - // TODO remove when EntityType is server-backed - return CraftEntityType.bukkitToMinecraft(entityType); - } else if (dependant instanceof final PotionType potionType) { + if (dependant instanceof final PotionType potionType) { return CraftPotionType.bukkitToMinecraft(potionType); } else if (dependant instanceof final GameRule gameRule) { return () -> CraftGameRule.bukkitToMinecraft(gameRule).requiredFeatures(); diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/CraftRegistry.java b/paper-server/src/main/java/org/bukkit/craftbukkit/CraftRegistry.java index 0d343556fbb6..de355e4239d8 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/CraftRegistry.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/CraftRegistry.java @@ -135,10 +135,6 @@ public static B get(RegistryKey bukkitKey, NamespacedKey na if (bukkit instanceof Registry.SimpleRegistry simple) { Class bClass = simple.getType(); - if (bClass == EntityType.class) { - return bukkit.get(FieldRename.ENTITY_TYPE_RENAME.apply(namespacedKey, apiVersion)); - } - if (bClass == Particle.class) { return bukkit.get(FieldRename.PARTICLE_TYPE_RENAME.apply(namespacedKey, apiVersion)); } diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/block/CraftBiome.java b/paper-server/src/main/java/org/bukkit/craftbukkit/block/CraftBiome.java index 14e6fb69e9af..c86148eb5f89 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/block/CraftBiome.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/block/CraftBiome.java @@ -8,6 +8,7 @@ import org.bukkit.block.Biome; import org.bukkit.craftbukkit.CraftRegistry; import org.jetbrains.annotations.ApiStatus; +import org.jetbrains.annotations.NotNull; import org.jspecify.annotations.NullMarked; import org.jspecify.annotations.Nullable; @@ -31,6 +32,11 @@ public CraftBiome(final Holder holder) { super(holder, count++); } + @Override + public @NotNull String translationKey() { + return "biome." + this.key().asString(); + } + /** * Implementation for the deprecated, API only, CUSTOM biome. * As per {@link #bukkitToMinecraftHolder(Biome)} it cannot be @@ -38,12 +44,14 @@ public CraftBiome(final Holder holder) { */ @Deprecated(forRemoval = true, since = "1.21.5") @ApiStatus.ScheduledForRemoval(inVersion = "1.22") - public static class LegacyCustomBiomeImpl implements Biome { + public static class LegacyCustomImpl implements Biome { + + public static final Biome INSTANCE = new LegacyCustomImpl(); + private static final NamespacedKey LEGACY_CUSTOM_KEY = NamespacedKey.minecraft("custom"); - private static final NamespacedKey LEGACY_CUSTOM_KEY = new NamespacedKey("minecraft", "custom"); private final int ordinal; - public LegacyCustomBiomeImpl() { + private LegacyCustomImpl() { this.ordinal = count++; } @@ -70,13 +78,18 @@ public int ordinal() { @Override public boolean equals(final Object object) { if (object == null || getClass() != object.getClass()) return false; - final LegacyCustomBiomeImpl that = (LegacyCustomBiomeImpl) object; - return ordinal == that.ordinal; + final LegacyCustomImpl that = (LegacyCustomImpl) object; + return this.ordinal == that.ordinal; + } + + @Override + public @NotNull String translationKey() { + throw new IllegalStateException("CUSTOM biome do not have translation key"); } @Override public int hashCode() { - return Objects.hashCode(ordinal); + return Objects.hashCode(this.ordinal); } @Override diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftEntityType.java b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftEntityType.java index d842c2c21570..c5c768a5fc2b 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftEntityType.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftEntityType.java @@ -1,58 +1,304 @@ package org.bukkit.craftbukkit.entity; import com.google.common.base.Preconditions; +import io.papermc.paper.attribute.UnmodifiableAttributeMap; import io.papermc.paper.registry.RegistryKey; +import io.papermc.paper.util.OldEnumHolderable; +import io.papermc.paper.world.flag.PaperFeatureDependent; +import it.unimi.dsi.fastutil.objects.Object2IntMap; +import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap; import java.util.Locale; +import java.util.Objects; +import java.util.Set; import net.minecraft.core.Holder; import net.minecraft.core.registries.Registries; +import net.minecraft.util.Util; +import net.minecraft.world.entity.ai.attributes.AttributeSupplier; +import net.minecraft.world.entity.ai.attributes.DefaultAttributes; +import org.bukkit.FeatureFlag; import org.bukkit.NamespacedKey; -import org.bukkit.Registry; +import org.bukkit.attribute.Attributable; import org.bukkit.craftbukkit.CraftRegistry; import org.bukkit.craftbukkit.legacy.FieldRename; import org.bukkit.craftbukkit.util.ApiVersion; -import org.bukkit.craftbukkit.util.CraftNamespacedKey; +import org.bukkit.entity.Entity; import org.bukkit.entity.EntityType; +import org.jetbrains.annotations.ApiStatus; +import org.jetbrains.annotations.Unmodifiable; +import org.jspecify.annotations.NullMarked; +import org.jspecify.annotations.Nullable; -public class CraftEntityType { +@NullMarked +public class CraftEntityType extends OldEnumHolderable, net.minecraft.world.entity.EntityType> implements EntityType, PaperFeatureDependent> { - public static EntityType minecraftToBukkit(net.minecraft.world.entity.EntityType minecraft) { - Preconditions.checkArgument(minecraft != null); + @Deprecated + private static final Object2IntMap> LEGACY_ID = Util.make(new Object2IntOpenHashMap<>(), map -> { + map.put(net.minecraft.world.entity.EntityType.ITEM, 1); + map.put(net.minecraft.world.entity.EntityType.EXPERIENCE_ORB, 2); + map.put(net.minecraft.world.entity.EntityType.AREA_EFFECT_CLOUD, 3); + map.put(net.minecraft.world.entity.EntityType.ELDER_GUARDIAN, 4); + map.put(net.minecraft.world.entity.EntityType.WITHER_SKELETON, 5); + map.put(net.minecraft.world.entity.EntityType.STRAY, 6); + map.put(net.minecraft.world.entity.EntityType.EGG, 7); + map.put(net.minecraft.world.entity.EntityType.LEASH_KNOT, 8); + map.put(net.minecraft.world.entity.EntityType.PAINTING, 9); + map.put(net.minecraft.world.entity.EntityType.ARROW, 10); + map.put(net.minecraft.world.entity.EntityType.SNOWBALL, 11); + map.put(net.minecraft.world.entity.EntityType.FIREBALL, 12); + map.put(net.minecraft.world.entity.EntityType.SMALL_FIREBALL, 13); + map.put(net.minecraft.world.entity.EntityType.ENDER_PEARL, 14); + map.put(net.minecraft.world.entity.EntityType.EYE_OF_ENDER, 15); + map.put(net.minecraft.world.entity.EntityType.SPLASH_POTION, 16); + map.put(net.minecraft.world.entity.EntityType.EXPERIENCE_BOTTLE, 17); + map.put(net.minecraft.world.entity.EntityType.ITEM_FRAME, 18); + map.put(net.minecraft.world.entity.EntityType.WITHER_SKULL, 19); + map.put(net.minecraft.world.entity.EntityType.TNT, 20); + map.put(net.minecraft.world.entity.EntityType.FALLING_BLOCK, 21); + map.put(net.minecraft.world.entity.EntityType.FIREWORK_ROCKET, 22); + map.put(net.minecraft.world.entity.EntityType.HUSK, 23); + map.put(net.minecraft.world.entity.EntityType.SPECTRAL_ARROW, 24); + map.put(net.minecraft.world.entity.EntityType.SHULKER_BULLET, 25); + map.put(net.minecraft.world.entity.EntityType.DRAGON_FIREBALL, 26); + map.put(net.minecraft.world.entity.EntityType.ZOMBIE_VILLAGER, 27); + map.put(net.minecraft.world.entity.EntityType.SKELETON_HORSE, 28); + map.put(net.minecraft.world.entity.EntityType.ZOMBIE_HORSE, 29); + map.put(net.minecraft.world.entity.EntityType.ARMOR_STAND, 30); + map.put(net.minecraft.world.entity.EntityType.DONKEY, 31); + map.put(net.minecraft.world.entity.EntityType.MULE, 32); + map.put(net.minecraft.world.entity.EntityType.EVOKER_FANGS, 33); + map.put(net.minecraft.world.entity.EntityType.EVOKER, 34); + map.put(net.minecraft.world.entity.EntityType.VEX, 35); + map.put(net.minecraft.world.entity.EntityType.VINDICATOR, 36); + map.put(net.minecraft.world.entity.EntityType.ILLUSIONER, 37); - net.minecraft.core.Registry> registry = CraftRegistry.getMinecraftRegistry(Registries.ENTITY_TYPE); - EntityType bukkit = Registry.ENTITY_TYPE.get(CraftNamespacedKey.fromMinecraft(registry.getResourceKey(minecraft).orElseThrow().identifier())); + map.put(net.minecraft.world.entity.EntityType.COMMAND_BLOCK_MINECART, 40); + map.put(net.minecraft.world.entity.EntityType.MINECART, 42); + map.put(net.minecraft.world.entity.EntityType.CHEST_MINECART, 43); + map.put(net.minecraft.world.entity.EntityType.FURNACE_MINECART, 44); + map.put(net.minecraft.world.entity.EntityType.TNT_MINECART, 45); + map.put(net.minecraft.world.entity.EntityType.HOPPER_MINECART, 46); + map.put(net.minecraft.world.entity.EntityType.SPAWNER_MINECART, 47); - Preconditions.checkArgument(bukkit != null); + map.put(net.minecraft.world.entity.EntityType.CREEPER, 50); + map.put(net.minecraft.world.entity.EntityType.SKELETON, 51); + map.put(net.minecraft.world.entity.EntityType.SPIDER, 52); + map.put(net.minecraft.world.entity.EntityType.GIANT, 53); + map.put(net.minecraft.world.entity.EntityType.ZOMBIE, 54); + map.put(net.minecraft.world.entity.EntityType.SLIME, 55); + map.put(net.minecraft.world.entity.EntityType.GHAST, 56); + map.put(net.minecraft.world.entity.EntityType.ZOMBIFIED_PIGLIN, 57); + map.put(net.minecraft.world.entity.EntityType.ENDERMAN, 58); + map.put(net.minecraft.world.entity.EntityType.CAVE_SPIDER, 59); + map.put(net.minecraft.world.entity.EntityType.SILVERFISH, 60); + map.put(net.minecraft.world.entity.EntityType.BLAZE, 61); + map.put(net.minecraft.world.entity.EntityType.MAGMA_CUBE, 62); + map.put(net.minecraft.world.entity.EntityType.ENDER_DRAGON, 63); + map.put(net.minecraft.world.entity.EntityType.WITHER, 64); + map.put(net.minecraft.world.entity.EntityType.BAT, 65); + map.put(net.minecraft.world.entity.EntityType.WITCH, 66); + map.put(net.minecraft.world.entity.EntityType.ENDERMITE, 67); + map.put(net.minecraft.world.entity.EntityType.GUARDIAN, 68); + map.put(net.minecraft.world.entity.EntityType.SHULKER, 69); + + map.put(net.minecraft.world.entity.EntityType.PIG, 90); + map.put(net.minecraft.world.entity.EntityType.SHEEP, 91); + map.put(net.minecraft.world.entity.EntityType.COW, 92); + map.put(net.minecraft.world.entity.EntityType.CHICKEN, 93); + map.put(net.minecraft.world.entity.EntityType.SQUID, 94); + map.put(net.minecraft.world.entity.EntityType.WOLF, 95); + map.put(net.minecraft.world.entity.EntityType.MOOSHROOM, 96); + map.put(net.minecraft.world.entity.EntityType.SNOW_GOLEM, 97); + map.put(net.minecraft.world.entity.EntityType.OCELOT, 98); + map.put(net.minecraft.world.entity.EntityType.IRON_GOLEM, 99); + map.put(net.minecraft.world.entity.EntityType.HORSE, 100); + map.put(net.minecraft.world.entity.EntityType.RABBIT, 101); + map.put(net.minecraft.world.entity.EntityType.POLAR_BEAR, 102); + map.put(net.minecraft.world.entity.EntityType.LLAMA, 103); + map.put(net.minecraft.world.entity.EntityType.LLAMA_SPIT, 104); + map.put(net.minecraft.world.entity.EntityType.PARROT, 105); + + map.put(net.minecraft.world.entity.EntityType.VILLAGER, 120); + + map.put(net.minecraft.world.entity.EntityType.END_CRYSTAL, 200); + }); + private static int count = 0; - return bukkit; + public CraftEntityType(final Holder> holder) { + super(holder, count++); } - private static final java.util.Map>> KEY_CACHE = java.util.Collections.synchronizedMap(new java.util.EnumMap<>(EntityType.class)); // Paper - public static net.minecraft.world.entity.EntityType bukkitToMinecraft(EntityType bukkit) { - Preconditions.checkArgument(bukkit != null); - return CraftRegistry.getMinecraftRegistry(Registries.ENTITY_TYPE) - .getOptional(KEY_CACHE.computeIfAbsent(bukkit, type -> net.minecraft.resources.ResourceKey.create(Registries.ENTITY_TYPE, CraftNamespacedKey.toMinecraft(type.getKey())))).orElseThrow(); + @Nullable + public String getName() { + return this.getKey().getKey(); } - public static Holder> bukkitToMinecraftHolder(EntityType bukkit) { - Preconditions.checkArgument(bukkit != null); + @Override + public Class getEntityClass() { + return null; + } + + @Override + @Deprecated(since = "1.6.2", forRemoval = true) + public short getTypeId() { + return (short) LEGACY_ID.getOrDefault(this.getHandle(), -1); + } + + @Override + public boolean isSpawnable() { + return this.getHandle().canSummon(); + } + + @Override + public boolean isAlive() { + return this.hasDefaultAttributes(); // should be roughly equivalent + } + + @Override + public String translationKey() { + return this.getHandle().getDescriptionId(); + } + + @Override + public boolean hasDefaultAttributes() { + return DefaultAttributes.hasSupplier(this.getHandle()); + } + + @Override + public Attributable getDefaultAttributes() { + Preconditions.checkArgument(this.hasDefaultAttributes(), this.getKey().asString() + " doesn't have default attributes"); + AttributeSupplier supplier = DefaultAttributes.getSupplier((net.minecraft.world.entity.EntityType) this.getHandle()); + return new UnmodifiableAttributeMap(supplier); + } + + /** + * Implementation for the deprecated, API only, CUSTOM entity type. + * As per {@link #bukkitToMinecraftHolder(EntityType)} it cannot be + * converted into an internal entity type and only serves backwards compatibility reasons. + */ + @Deprecated(forRemoval = true, since = "1.21.11") + @ApiStatus.ScheduledForRemoval(inVersion = "1.22") + public static class LegacyUnknownImpl implements EntityType { + + public static final EntityType INSTANCE = new LegacyUnknownImpl(); + + private final int ordinal; + + private LegacyUnknownImpl() { + this.ordinal = count++; + } + + @Override + public NamespacedKey getKey() { + return null; + } + + @Override + public int compareTo(final EntityType other) { + return this.ordinal - other.ordinal(); + } + + @Override + public String name() { + return "UNKNOWN"; + } + + @Override + public int ordinal() { + return this.ordinal; + } + + @Override + public boolean equals(final Object object) { + if (object == null || getClass() != object.getClass()) return false; + final LegacyUnknownImpl that = (LegacyUnknownImpl) object; + return ordinal == that.ordinal; + } + + @Override + public int hashCode() { + return Objects.hashCode(ordinal); + } + + @Override + public String toString() { + return "UNKNOWN"; + } + + @Override + public @Nullable String getName() { + return null; + } + + @Override + public @Nullable Class getEntityClass() { + return null; + } + + @Override + public short getTypeId() { + return -1; + } + + @Override + public boolean isSpawnable() { + return false; + } - net.minecraft.core.Registry> registry = CraftRegistry.getMinecraftRegistry(Registries.ENTITY_TYPE); + @Override + public boolean isAlive() { + return false; + } - if (registry.wrapAsHolder(CraftEntityType.bukkitToMinecraft(bukkit)) instanceof Holder.Reference> holder) { - return holder; + @Override + public String translationKey() { + throw new IllegalStateException("UNKNOWN entity type do not have translation key"); } - throw new IllegalArgumentException("No Reference holder found for " + bukkit - + ", this can happen if a plugin creates its own sound effect with out properly registering it."); + @Override + public boolean hasDefaultAttributes() { + return false; + } + + @Override + public Attributable getDefaultAttributes() { + throw new IllegalStateException(this.getKey().asString() + " doesn't have default attributes"); + } + + @Override + public @Unmodifiable Set requiredFeatures() { + throw new IllegalStateException("UNKNOWN entity type do not have required features"); + } + } + + public static EntityType minecraftToBukkit(net.minecraft.world.entity.EntityType minecraft) { + return CraftRegistry.minecraftToBukkit(minecraft, Registries.ENTITY_TYPE); + } + + public static net.minecraft.world.entity.@Nullable EntityType bukkitToMinecraft(EntityType bukkit) { + if (bukkit == EntityType.UNKNOWN) { + return null; + } + return CraftRegistry.bukkitToMinecraft(bukkit); + } + + public static EntityType minecraftHolderToBukkit(Holder> minecraft) { + return CraftRegistry.minecraftHolderToBukkit(minecraft, Registries.ENTITY_TYPE); + } + + public static @Nullable Holder> bukkitToMinecraftHolder(EntityType bukkit) { + if (bukkit == EntityType.UNKNOWN) { + return null; + } + return CraftRegistry.bukkitToMinecraftHolder(bukkit); } - public static String bukkitToString(EntityType bukkit) { + public static String bukkitToString(EntityType bukkit) { Preconditions.checkArgument(bukkit != null); return bukkit.getKey().toString(); } - public static EntityType stringToBukkit(String string) { + public static EntityType stringToBukkit(String string) { Preconditions.checkArgument(string != null); // We currently do not have any version-dependent remapping, so we can use current version diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java b/paper-server/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java index cd83ca2ace1d..3b6a47b03332 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java @@ -6,15 +6,6 @@ import com.google.common.collect.Lists; import com.mojang.authlib.GameProfile; import com.mojang.datafixers.util.Either; -import java.util.ArrayList; -import java.util.Collections; -import java.util.EnumMap; -import java.util.List; -import java.util.Map; -import java.util.Optional; -import java.util.Set; -import java.util.stream.Collectors; -import java.util.stream.Stream; import io.papermc.paper.adventure.PaperAdventure; import io.papermc.paper.block.bed.BedEnterProblem; import io.papermc.paper.connection.HorriblePlayerLoginEventHack; @@ -23,6 +14,14 @@ import io.papermc.paper.event.connection.PlayerConnectionValidateLoginEvent; import io.papermc.paper.event.entity.ItemTransportingEntityValidateTargetEvent; import io.papermc.paper.event.player.PlayerBedFailEnterEvent; +import java.util.ArrayList; +import java.util.Collections; +import java.util.EnumMap; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.stream.Collectors; +import java.util.stream.Stream; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; import net.minecraft.network.Connection; @@ -43,18 +42,17 @@ import net.minecraft.world.effect.MobEffectInstance; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.Leashable; +import net.minecraft.world.entity.LightningBolt; import net.minecraft.world.entity.Mob; import net.minecraft.world.entity.PathfinderMob; -import net.minecraft.world.entity.animal.fish.AbstractFish; -import net.minecraft.world.entity.animal.golem.AbstractGolem; import net.minecraft.world.entity.animal.Animal; -import net.minecraft.world.entity.animal.fish.WaterAnimal; +import net.minecraft.world.entity.animal.fish.AbstractFish; +import net.minecraft.world.entity.boss.enderdragon.EndCrystal; import net.minecraft.world.entity.item.ItemEntity; -import net.minecraft.world.entity.monster.Ghast; -import net.minecraft.world.entity.monster.Monster; -import net.minecraft.world.entity.monster.Slime; import net.minecraft.world.entity.monster.illager.SpellcasterIllager; import net.minecraft.world.entity.projectile.FireworkRocketEntity; +import net.minecraft.world.entity.projectile.arrow.Arrow; +import net.minecraft.world.entity.projectile.hurtingprojectile.Fireball; import net.minecraft.world.entity.raid.Raid; import net.minecraft.world.inventory.AbstractContainerMenu; import net.minecraft.world.inventory.CraftingContainer; @@ -1556,11 +1554,11 @@ public static BlockIgniteEvent callBlockIgniteEvent(Level world, BlockPos pos, B public static BlockIgniteEvent callBlockIgniteEvent(Level world, BlockPos pos, Entity igniter) { org.bukkit.entity.Entity bukkitIgniter = igniter.getBukkitEntity(); - IgniteCause cause = switch (bukkitIgniter.getType()) { - case END_CRYSTAL -> IgniteCause.ENDER_CRYSTAL; - case LIGHTNING_BOLT -> IgniteCause.LIGHTNING; - case SMALL_FIREBALL, FIREBALL -> IgniteCause.FIREBALL; - case ARROW -> IgniteCause.ARROW; + IgniteCause cause = switch (bukkitIgniter) { + case EndCrystal $ -> IgniteCause.ENDER_CRYSTAL; + case LightningBolt $ -> IgniteCause.LIGHTNING; + case Fireball $ -> IgniteCause.FIREBALL; + case Arrow $ -> IgniteCause.ARROW; default -> IgniteCause.FLINT_AND_STEEL; }; diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/components/CraftEquippableComponent.java b/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/components/CraftEquippableComponent.java index 9db372844211..6c5c09ec3cce 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/components/CraftEquippableComponent.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/components/CraftEquippableComponent.java @@ -1,17 +1,18 @@ package org.bukkit.craftbukkit.inventory.components; import com.google.common.base.Preconditions; +import io.papermc.paper.registry.RegistryKey; +import io.papermc.paper.registry.set.PaperRegistrySets; import java.util.Collection; import java.util.LinkedHashMap; import java.util.Map; import java.util.Optional; import java.util.stream.Collectors; -import net.minecraft.core.Holder; import net.minecraft.core.HolderSet; import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.core.registries.Registries; -import net.minecraft.resources.ResourceKey; import net.minecraft.resources.Identifier; +import net.minecraft.resources.ResourceKey; import net.minecraft.sounds.SoundEvents; import net.minecraft.world.item.equipment.EquipmentAssets; import net.minecraft.world.item.equipment.Equippable; @@ -151,8 +152,10 @@ public void setCameraOverlay(NamespacedKey key) { } @Override - public Collection getAllowedEntities() { - return this.handle.allowedEntities().map(HolderSet::stream).map((stream) -> stream.map(Holder::value).map(CraftEntityType::minecraftToBukkit).collect(Collectors.toList())).orElse(null); + public Collection> getAllowedEntities() { + return this.handle.allowedEntities() + .map((set) -> PaperRegistrySets.convertToApi(RegistryKey.ENTITY_TYPE, set).resolve(Registry.ENTITY_TYPE)) + .orElse(null); } @Override diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java b/paper-server/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java index cfa4c67e80a5..13d931c9cb2f 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java @@ -14,7 +14,7 @@ import com.mojang.serialization.JavaOps; import com.mojang.serialization.JsonOps; import io.papermc.paper.adventure.AdventureCodecs; -import io.papermc.paper.adventure.PaperAdventure; +import io.papermc.paper.entity.EntitySerializationFlag; import io.papermc.paper.registry.RegistryKey; import java.io.File; import java.io.IOException; @@ -28,7 +28,6 @@ import java.util.Set; import java.util.logging.Level; import java.util.stream.Stream; -import io.papermc.paper.entity.EntitySerializationFlag; import net.kyori.adventure.text.event.HoverEvent; import net.minecraft.SharedConstants; import net.minecraft.advancements.AdvancementHolder; @@ -61,7 +60,6 @@ import org.bukkit.Keyed; import org.bukkit.Material; import org.bukkit.NamespacedKey; -import org.bukkit.Registry; import org.bukkit.UnsafeValues; import org.bukkit.World; import org.bukkit.advancement.Advancement; @@ -431,12 +429,6 @@ public String getItemTranslationKey(Material material) { return material.getItemTranslationKey(); } - @Override - public String getTranslationKey(EntityType entityType) { - Preconditions.checkArgument(entityType.getName() != null, "Invalid name of EntityType %s for translation key", entityType); - return net.minecraft.world.entity.EntityType.byString(entityType.getName()).map(net.minecraft.world.entity.EntityType::getDescriptionId).orElseThrow(); - } - @Override public String getTranslationKey(ItemStack itemStack) { net.minecraft.world.item.ItemStack nmsItemStack = CraftItemStack.asNMSCopy(itemStack); @@ -805,18 +797,6 @@ public boolean isValidRepairItemStack(org.bukkit.inventory.ItemStack itemToBeRep return CraftItemStack.unwrap(itemToBeRepaired).isValidRepairItem(CraftItemStack.unwrap(repairMaterial)); } - @Override - public boolean hasDefaultEntityAttributes(NamespacedKey entityKey) { - return net.minecraft.world.entity.ai.attributes.DefaultAttributes.hasSupplier(net.minecraft.core.registries.BuiltInRegistries.ENTITY_TYPE.getValue(CraftNamespacedKey.toMinecraft(entityKey))); - } - - @Override - public org.bukkit.attribute.Attributable getDefaultEntityAttributes(NamespacedKey entityKey) { - Preconditions.checkArgument(hasDefaultEntityAttributes(entityKey), entityKey + " doesn't have default attributes"); - var supplier = net.minecraft.world.entity.ai.attributes.DefaultAttributes.getSupplier((net.minecraft.world.entity.EntityType) net.minecraft.core.registries.BuiltInRegistries.ENTITY_TYPE.getValue(CraftNamespacedKey.toMinecraft(entityKey))); - return new io.papermc.paper.attribute.UnmodifiableAttributeMap(supplier); - } - @Override public org.bukkit.NamespacedKey getBiomeKey(org.bukkit.RegionAccessor accessor, int x, int y, int z) { return accessor.getBiome(x, y, z).getKey(); diff --git a/paper-api/src/test/java/org/bukkit/scoreboard/CriteriaTest.java b/paper-server/src/test/java/org/bukkit/CriteriaTest.java similarity index 81% rename from paper-api/src/test/java/org/bukkit/scoreboard/CriteriaTest.java rename to paper-server/src/test/java/org/bukkit/CriteriaTest.java index 18a2c5a10752..c6881aaeaa04 100644 --- a/paper-api/src/test/java/org/bukkit/scoreboard/CriteriaTest.java +++ b/paper-server/src/test/java/org/bukkit/CriteriaTest.java @@ -1,14 +1,16 @@ -package org.bukkit.scoreboard; +package org.bukkit; -import static org.junit.jupiter.api.Assertions.*; -import static org.mockito.Mockito.*; -import org.bukkit.Material; -import org.bukkit.Statistic; import org.bukkit.entity.EntityType; -import org.bukkit.support.AbstractTestingBase; +import org.bukkit.scoreboard.Criteria; +import org.bukkit.support.environment.AllFeatures; import org.junit.jupiter.api.Test; -public class CriteriaTest extends AbstractTestingBase { +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +@AllFeatures +public class CriteriaTest { @Test public void testStatistic() { diff --git a/paper-server/src/test/java/org/bukkit/craftbukkit/entity/EntityTypesTest.java b/paper-server/src/test/java/org/bukkit/craftbukkit/entity/EntityTypesTest.java index 76573dbcf8e7..cc6e115038ed 100644 --- a/paper-server/src/test/java/org/bukkit/craftbukkit/entity/EntityTypesTest.java +++ b/paper-server/src/test/java/org/bukkit/craftbukkit/entity/EntityTypesTest.java @@ -10,6 +10,7 @@ import java.util.jar.JarFile; import java.util.stream.Stream; import java.util.zip.ZipEntry; +import org.bukkit.Registry; import org.bukkit.entity.AbstractArrow; import org.bukkit.entity.AbstractCow; import org.bukkit.entity.AbstractHorse; @@ -63,8 +64,10 @@ import org.bukkit.entity.Vehicle; import org.bukkit.entity.WaterMob; import org.bukkit.support.environment.AllFeatures; +import org.bukkit.support.test.RegistriesTest; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.EnumSource; @@ -180,11 +183,12 @@ public void testEntityClass(Class clazz) { assertNotNull(entityTypeData, String.format("Class %s does not have an entity type data, please add on to CraftEntityTypes or mark the class as excluded in EntityTypesTest, if the class does not have an entity type.", clazz)); } - @ParameterizedTest - @EnumSource(value = EntityType.class, names = "UNKNOWN", mode = EnumSource.Mode.EXCLUDE) - public void testEntityType(EntityType entityType) { - CraftEntityTypes.EntityTypeData entityTypeData = CraftEntityTypes.getEntityTypeData(entityType); - assertNotNull(entityTypeData, String.format("Entity type %s does not have an entity type data, please add on to CraftEntityTypes.", entityType)); + @Test + public void testEntityType() { + Registry.ENTITY_TYPE.forEach(type -> { + CraftEntityTypes.EntityTypeData entityTypeData = CraftEntityTypes.getEntityTypeData(type); + assertNotNull(entityTypeData, String.format("Entity type %s does not have an entity type data, please add on to CraftEntityTypes.", type)); + }); } @AfterAll diff --git a/paper-server/src/test/java/org/bukkit/entity/EntityTypesTest.java b/paper-server/src/test/java/org/bukkit/entity/EntityTypesTest.java deleted file mode 100644 index a4e2c42e9a5d..000000000000 --- a/paper-server/src/test/java/org/bukkit/entity/EntityTypesTest.java +++ /dev/null @@ -1,20 +0,0 @@ -package org.bukkit.entity; - -import static org.junit.jupiter.api.Assertions.*; - -import org.bukkit.support.environment.AllFeatures; -import org.junit.jupiter.api.Test; - -@AllFeatures -public class EntityTypesTest { - - @Test - public void testTranslationKey() { - for (org.bukkit.entity.EntityType entityType : org.bukkit.entity.EntityType.values()) { - // Currently EntityType#getTranslationKey has a validation for null name then for test skip this and check correct names. - if (entityType.getName() != null) { - assertNotNull(entityType.getTranslationKey(), "Nulllable translation key for " + entityType); - } - } - } -} diff --git a/paper-server/src/test/java/org/bukkit/support/provider/RegistriesArgumentProvider.java b/paper-server/src/test/java/org/bukkit/support/provider/RegistriesArgumentProvider.java index 00b949fc0982..a59c5c1908d7 100644 --- a/paper-server/src/test/java/org/bukkit/support/provider/RegistriesArgumentProvider.java +++ b/paper-server/src/test/java/org/bukkit/support/provider/RegistriesArgumentProvider.java @@ -13,12 +13,12 @@ import net.minecraft.resources.ResourceKey; import net.minecraft.sounds.SoundEvent; import net.minecraft.world.effect.MobEffect; -import net.minecraft.world.entity.animal.feline.CatVariant; import net.minecraft.world.entity.animal.chicken.ChickenVariant; import net.minecraft.world.entity.animal.cow.CowVariant; -import net.minecraft.world.entity.animal.pig.PigVariant; -import net.minecraft.world.entity.animal.nautilus.ZombieNautilusVariant; +import net.minecraft.world.entity.animal.feline.CatVariant; import net.minecraft.world.entity.animal.frog.FrogVariant; +import net.minecraft.world.entity.animal.nautilus.ZombieNautilusVariant; +import net.minecraft.world.entity.animal.pig.PigVariant; import net.minecraft.world.entity.animal.wolf.WolfSoundVariant; import net.minecraft.world.entity.animal.wolf.WolfVariant; import net.minecraft.world.entity.decoration.painting.PaintingVariant; @@ -56,6 +56,7 @@ import org.bukkit.craftbukkit.entity.CraftCat; import org.bukkit.craftbukkit.entity.CraftChicken; import org.bukkit.craftbukkit.entity.CraftCow; +import org.bukkit.craftbukkit.entity.CraftEntityType; import org.bukkit.craftbukkit.entity.CraftFrog; import org.bukkit.craftbukkit.entity.CraftPig; import org.bukkit.craftbukkit.entity.CraftVillager; @@ -74,6 +75,7 @@ import org.bukkit.entity.Cat; import org.bukkit.entity.Chicken; import org.bukkit.entity.Cow; +import org.bukkit.entity.EntityType; import org.bukkit.entity.Frog; import org.bukkit.entity.Pig; import org.bukkit.entity.Villager; @@ -149,6 +151,7 @@ public Object[] get() { register(Registries.ZOMBIE_NAUTILUS_VARIANT, ZombieNautilus.Variant.class, CraftZombieNautilus.CraftVariant.class, ZombieNautilusVariant.class); register(Registries.DIALOG, Dialog.class, PaperDialog.class, net.minecraft.server.dialog.Dialog.class); register(Registries.GAME_RULE, GameRule.class, GameRules.class, CraftGameRule.class, net.minecraft.world.level.gamerules.GameRule.class); + register(Registries.ENTITY_TYPE, EntityType.class, CraftEntityType.class, net.minecraft.world.entity.EntityType.class); } private static void register(ResourceKey> registryKey, Class api, Class impl, Class internal) { From 79f19ea78c6b6d12d98b693496191b1100c5ac52 Mon Sep 17 00:00:00 2001 From: Lulu13022002 <41980282+Lulu13022002@users.noreply.github.com> Date: Tue, 3 Mar 2026 16:26:03 +0100 Subject: [PATCH 2/6] prepare removal of spigot boats hack, migrate some methods to the new entity type --- .../main/java/org/bukkit/RegionAccessor.java | 170 +++++++----- paper-api/src/main/java/org/bukkit/World.java | 33 ++- .../java/org/bukkit/entity/EntityType.java | 174 +++++-------- .../org/bukkit/entity/boat/AcaciaBoat.java | 2 +- .../bukkit/entity/boat/AcaciaChestBoat.java | 2 +- .../bukkit/entity/boat/BambooChestRaft.java | 2 +- .../org/bukkit/entity/boat/BambooRaft.java | 2 +- .../org/bukkit/entity/boat/BirchBoat.java | 2 +- .../bukkit/entity/boat/BirchChestBoat.java | 2 +- .../org/bukkit/entity/boat/CherryBoat.java | 2 +- .../bukkit/entity/boat/CherryChestBoat.java | 2 +- .../org/bukkit/entity/boat/DarkOakBoat.java | 2 +- .../bukkit/entity/boat/DarkOakChestBoat.java | 2 +- .../org/bukkit/entity/boat/JungleBoat.java | 2 +- .../bukkit/entity/boat/JungleChestBoat.java | 2 +- .../org/bukkit/entity/boat/MangroveBoat.java | 2 +- .../bukkit/entity/boat/MangroveChestBoat.java | 2 +- .../java/org/bukkit/entity/boat/OakBoat.java | 2 +- .../org/bukkit/entity/boat/OakChestBoat.java | 2 +- .../org/bukkit/entity/boat/PaleOakBoat.java | 2 +- .../bukkit/entity/boat/PaleOakChestBoat.java | 2 +- .../org/bukkit/entity/boat/SpruceBoat.java | 2 +- .../bukkit/entity/boat/SpruceChestBoat.java | 2 +- .../org/bukkit/entity/boat/package-info.java | 2 +- .../java/org/bukkit/material/SpawnEgg.java | 3 +- .../types/simple/EntityTypeRewriter.java | 43 +-- .../craftbukkit/CraftRegionAccessor.java | 57 +++- .../org/bukkit/craftbukkit/CraftWorld.java | 24 +- .../bukkit/craftbukkit/entity/CraftBoat.java | 2 +- .../craftbukkit/entity/CraftChestBoat.java | 2 +- .../craftbukkit/entity/CraftEntityType.java | 244 ++++++++++-------- .../craftbukkit/entity/CraftEntityTypes.java | 94 ++----- .../entity/boat/CraftAcaciaBoat.java | 13 - .../entity/boat/CraftAcaciaChestBoat.java | 13 - .../entity/boat/CraftBambooChestRaft.java | 13 - .../entity/boat/CraftBambooRaft.java | 13 - .../entity/boat/CraftBirchBoat.java | 13 - .../entity/boat/CraftBirchChestBoat.java | 13 - .../entity/boat/CraftCherryBoat.java | 13 - .../entity/boat/CraftCherryChestBoat.java | 13 - .../entity/boat/CraftDarkOakBoat.java | 13 - .../entity/boat/CraftDarkOakChestBoat.java | 13 - .../entity/boat/CraftJungleBoat.java | 13 - .../entity/boat/CraftJungleChestBoat.java | 13 - .../entity/boat/CraftMangroveBoat.java | 13 - .../entity/boat/CraftMangroveChestBoat.java | 13 - .../craftbukkit/entity/boat/CraftOakBoat.java | 13 - .../entity/boat/CraftOakChestBoat.java | 13 - .../entity/boat/CraftPaleOakBoat.java | 13 - .../entity/boat/CraftPaleOakChestBoat.java | 13 - .../entity/boat/CraftSpruceBoat.java | 13 - .../entity/boat/CraftSpruceChestBoat.java | 13 - .../craftbukkit/legacy/FieldRename.java | 3 +- .../craftbukkit/entity/EntityTypesTest.java | 193 +------------- 54 files changed, 490 insertions(+), 854 deletions(-) delete mode 100644 paper-server/src/main/java/org/bukkit/craftbukkit/entity/boat/CraftAcaciaBoat.java delete mode 100644 paper-server/src/main/java/org/bukkit/craftbukkit/entity/boat/CraftAcaciaChestBoat.java delete mode 100644 paper-server/src/main/java/org/bukkit/craftbukkit/entity/boat/CraftBambooChestRaft.java delete mode 100644 paper-server/src/main/java/org/bukkit/craftbukkit/entity/boat/CraftBambooRaft.java delete mode 100644 paper-server/src/main/java/org/bukkit/craftbukkit/entity/boat/CraftBirchBoat.java delete mode 100644 paper-server/src/main/java/org/bukkit/craftbukkit/entity/boat/CraftBirchChestBoat.java delete mode 100644 paper-server/src/main/java/org/bukkit/craftbukkit/entity/boat/CraftCherryBoat.java delete mode 100644 paper-server/src/main/java/org/bukkit/craftbukkit/entity/boat/CraftCherryChestBoat.java delete mode 100644 paper-server/src/main/java/org/bukkit/craftbukkit/entity/boat/CraftDarkOakBoat.java delete mode 100644 paper-server/src/main/java/org/bukkit/craftbukkit/entity/boat/CraftDarkOakChestBoat.java delete mode 100644 paper-server/src/main/java/org/bukkit/craftbukkit/entity/boat/CraftJungleBoat.java delete mode 100644 paper-server/src/main/java/org/bukkit/craftbukkit/entity/boat/CraftJungleChestBoat.java delete mode 100644 paper-server/src/main/java/org/bukkit/craftbukkit/entity/boat/CraftMangroveBoat.java delete mode 100644 paper-server/src/main/java/org/bukkit/craftbukkit/entity/boat/CraftMangroveChestBoat.java delete mode 100644 paper-server/src/main/java/org/bukkit/craftbukkit/entity/boat/CraftOakBoat.java delete mode 100644 paper-server/src/main/java/org/bukkit/craftbukkit/entity/boat/CraftOakChestBoat.java delete mode 100644 paper-server/src/main/java/org/bukkit/craftbukkit/entity/boat/CraftPaleOakBoat.java delete mode 100644 paper-server/src/main/java/org/bukkit/craftbukkit/entity/boat/CraftPaleOakChestBoat.java delete mode 100644 paper-server/src/main/java/org/bukkit/craftbukkit/entity/boat/CraftSpruceBoat.java delete mode 100644 paper-server/src/main/java/org/bukkit/craftbukkit/entity/boat/CraftSpruceChestBoat.java diff --git a/paper-api/src/main/java/org/bukkit/RegionAccessor.java b/paper-api/src/main/java/org/bukkit/RegionAccessor.java index f86ed60687bb..ddcfd0f99a51 100644 --- a/paper-api/src/main/java/org/bukkit/RegionAccessor.java +++ b/paper-api/src/main/java/org/bukkit/RegionAccessor.java @@ -280,44 +280,6 @@ default void setType(int x, int y, int z, @NotNull Material material) { */ boolean generateTree(@NotNull Location location, @NotNull Random random, @NotNull TreeType type, @Nullable Predicate statePredicate); - /** - * Creates an entity at the given {@link Location} - * - * @param location The location to spawn the entity - * @param type The entity to spawn - * @return Resulting Entity of this method - */ - @NotNull - default Entity spawnEntity(@NotNull Location location, @NotNull EntityType type) { - return this.spawn(location, type.getEntityClass()); - } - - /** - * Creates a new entity at the given {@link Location}. - * - * @param loc the location at which the entity will be spawned. - * @param type the entity type that determines the entity to spawn. - * @param randomizeData whether or not the entity's data should be randomised - * before spawning. By default entities are randomised - * before spawning in regards to their equipment, age, - * attributes, etc. - * An example of this randomization would be the color of - * a sheep, random enchantments on the equipment of mobs - * or even a zombie becoming a chicken jockey. - * If set to false, the entity will not be randomised - * before spawning, meaning all their data will remain - * in their default state and not further modifications - * to the entity will be made. - * Notably only entities that extend the - * {@link org.bukkit.entity.Mob} interface provide - * randomization logic for their spawn. - * This parameter is hence useless for any other type - * of entity. - * @return the spawned entity instance. - */ - @NotNull - public Entity spawnEntity(@NotNull Location loc, @NotNull EntityType type, boolean randomizeData); - /** * Get a list of all entities in this RegionAccessor * @@ -371,22 +333,44 @@ default Entity spawnEntity(@NotNull Location location, @NotNull EntityType type) * @return an instance of the created {@link Entity} * @see #addEntity(Entity) * @see Entity#createSnapshot() + * @deprecated use {@link #createEntity(Location, EntityType)} */ @NotNull + @Deprecated(since = "1.21.11") T createEntity(@NotNull Location location, @NotNull Class clazz); + /** + * Creates an entity of a specific entity type at the given {@link Location} but + * does not spawn it in the world. + *

+ * Note: The created entity keeps a reference to the world it was + * created in, care should be taken that the entity does not outlive the + * world instance as this will lead to memory leaks. + * + * @param the class of the {@link Entity} to create + * @param location the {@link Location} to create the entity at + * @param type the entity type of the {@link Entity} to spawn + * @return an instance of the created {@link Entity} + * @see #addEntity(Entity) + * @see Entity#createSnapshot() + */ + @NotNull + T createEntity(@NotNull Location location, @NotNull EntityType type); + /** * Spawn an entity of a specific class at the given {@link Location} * * @param location the {@link Location} to spawn the entity at * @param clazz the class of the {@link Entity} to spawn - * @param the class of the {@link Entity} to spawn + * @param the class of the {@link Entity} to spawn * @return an instance of the spawned {@link Entity} * @throws IllegalArgumentException if either parameter is null or the * {@link Entity} requested cannot be spawned + * @deprecated use {@link #spawnEntity(Location, EntityType)} */ @NotNull - default T spawn(@NotNull Location location, @NotNull Class clazz) throws IllegalArgumentException { + @Deprecated(since = "1.21.11") + default E spawn(@NotNull Location location, @NotNull Class clazz) throws IllegalArgumentException { return this.spawn(location, clazz, null, CreatureSpawnEvent.SpawnReason.CUSTOM); } @@ -401,36 +385,38 @@ default T spawn(@NotNull Location location, @NotNull Class * @param location the {@link Location} to spawn the entity at * @param clazz the class of the {@link Entity} to spawn * @param function the function to be run before the entity is spawned. - * @param the class of the {@link Entity} to spawn + * @param the class of the {@link Entity} to spawn * @return an instance of the spawned {@link Entity} * @throws IllegalArgumentException if either parameter is null or the * {@link Entity} requested cannot be spawned + * @deprecated use {@link #spawnEntity(Location, EntityType, Consumer)} */ - // Paper start - default @NotNull T spawn(final @NotNull Location location, final @NotNull Class clazz, final @Nullable Consumer function) throws IllegalArgumentException { + @Deprecated(since = "1.21.11") + default @NotNull E spawn(final @NotNull Location location, final @NotNull Class clazz, final @Nullable Consumer function) throws IllegalArgumentException { return this.spawn(location, clazz, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.CUSTOM, function); } - default @NotNull T spawn(final @NotNull Location location, final @NotNull Class clazz, final org.bukkit.event.entity.CreatureSpawnEvent.@NotNull SpawnReason reason) throws IllegalArgumentException { + /** + * @deprecated use {@link #spawnEntity(Location, EntityType, CreatureSpawnEvent.SpawnReason)} + */ + @Deprecated(since = "1.21.11") + default @NotNull E spawn(final @NotNull Location location, final @NotNull Class clazz, final org.bukkit.event.entity.CreatureSpawnEvent.@NotNull SpawnReason reason) throws IllegalArgumentException { return this.spawn(location, clazz, reason, null); } - default @NotNull T spawn(final @NotNull Location location, final @NotNull Class clazz, final org.bukkit.event.entity.CreatureSpawnEvent.@NotNull SpawnReason reason, final @Nullable Consumer function) throws IllegalArgumentException { + /** + * @deprecated use {@link #spawnEntity(Location, EntityType, Consumer, CreatureSpawnEvent.SpawnReason)} + */ + @Deprecated(since = "1.21.11") + default @NotNull E spawn(final @NotNull Location location, final @NotNull Class clazz, final org.bukkit.event.entity.CreatureSpawnEvent.@NotNull SpawnReason reason, final @Nullable Consumer function) throws IllegalArgumentException { return this.spawn(location, clazz, function, reason); } - default @NotNull Entity spawnEntity(final @NotNull Location loc, final @NotNull EntityType type, final org.bukkit.event.entity.CreatureSpawnEvent.@NotNull SpawnReason reason) { - com.google.common.base.Preconditions.checkArgument(type.getEntityClass() != null, "%s is not a valid EntityType, must have an entity class", type); - return this.spawn(loc, type.getEntityClass(), reason, null); - } - - default @NotNull Entity spawnEntity(final @NotNull Location loc, final @NotNull EntityType type, final org.bukkit.event.entity.CreatureSpawnEvent.@NotNull SpawnReason reason, final @Nullable Consumer function) { - com.google.common.base.Preconditions.checkArgument(type.getEntityClass() != null, "%s is not a valid EntityType, must have an entity class", type); - return this.spawn(loc, type.getEntityClass(), reason, function); - } - - @NotNull T spawn(@NotNull Location location, @NotNull Class clazz, @Nullable Consumer function, org.bukkit.event.entity.CreatureSpawnEvent.@NotNull SpawnReason reason) throws IllegalArgumentException; - // Paper end + /** + * @deprecated use {@link #spawnEntity(Location, EntityType, CreatureSpawnEvent.SpawnReason, Consumer)} + */ + @Deprecated(since = "1.21.11") + @NotNull E spawn(@NotNull Location location, @NotNull Class clazz, @Nullable Consumer function, org.bukkit.event.entity.CreatureSpawnEvent.@NotNull SpawnReason reason) throws IllegalArgumentException; /** * Creates a new entity at the given {@link Location} with the supplied @@ -446,7 +432,7 @@ default T spawn(@NotNull Location location, @NotNull Class * * @param location the location at which the entity will be spawned. * @param clazz the class of the {@link Entity} that is to be spawned. - * @param the generic type of the entity that is being created. + * @param the generic type of the entity that is being created. * @param randomizeData whether or not the entity's data should be randomised * before spawning. By default entities are randomised * before spawning in regards to their equipment, age, @@ -466,9 +452,75 @@ default T spawn(@NotNull Location location, @NotNull Class * @param function the function to be run before the entity is spawned. * @return the spawned entity instance. * @throws IllegalArgumentException if either the world or clazz parameter are null. + * @deprecated use {@link #spawnEntity(Location, EntityType, boolean, Consumer)} */ @NotNull - public T spawn(@NotNull Location location, @NotNull Class clazz, boolean randomizeData, @Nullable Consumer function) throws IllegalArgumentException; + @Deprecated(since = "1.21.11") + E spawn(@NotNull Location location, @NotNull Class clazz, boolean randomizeData, @Nullable Consumer function); + + /** + * Creates an entity at the given {@link Location} + * + * @param location The location to spawn the entity + * @param type The entity to spawn + * @return Resulting Entity of this method + */ + default @NotNull E spawnEntity(@NotNull Location location, @NotNull EntityType type) { + return this.spawnEntity(location, type, true); + } + + /** + * Creates a new entity at the given {@link Location}. + * + * @param location the location at which the entity will be spawned. + * @param type the entity type that determines the entity to spawn. + * @param randomizeData whether or not the entity's data should be randomised + * before spawning. By default entities are randomised + * before spawning in regards to their equipment, age, + * attributes, etc. + * An example of this randomization would be the color of + * a sheep, random enchantments on the equipment of mobs + * or even a zombie becoming a chicken jockey. + * If set to false, the entity will not be randomised + * before spawning, meaning all their data will remain + * in their default state and not further modifications + * to the entity will be made. + * Notably only entities that extend the + * {@link org.bukkit.entity.Mob} interface provide + * randomization logic for their spawn. + * This parameter is hence useless for any other type + * of entity. + * @return the spawned entity instance. + */ + default @NotNull E spawnEntity(final @NotNull Location location, final @NotNull EntityType type, final boolean randomizeData) { + return this.spawnEntity(location, type, randomizeData, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.CUSTOM); + } + + default @NotNull E spawnEntity(final @NotNull Location location, final @NotNull EntityType type, final boolean randomizeData, final @Nullable Consumer function) { + return this.spawnEntity(location, type, randomizeData, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.CUSTOM, function); + } + + default @NotNull E spawnEntity(final @NotNull Location location, final @NotNull EntityType type, final boolean randomizeData, final CreatureSpawnEvent.@NotNull SpawnReason reason) { + return this.spawnEntity(location, type, randomizeData, reason, null); + } + + @NotNull E spawnEntity(@NotNull Location location, @NotNull EntityType type, boolean randomizeData, CreatureSpawnEvent.@NotNull SpawnReason reason, @Nullable Consumer function); + + default @NotNull E spawnEntity(final @NotNull Location location, final @NotNull EntityType type, final @Nullable Consumer function) { + return this.spawnEntity(location, type, true, function); + } + + default @NotNull E spawnEntity(final @NotNull Location location, final @NotNull EntityType type, final CreatureSpawnEvent.@NotNull SpawnReason reason) { + return this.spawnEntity(location, type, reason, null); + } + + default @NotNull E spawnEntity(final @NotNull Location location, final @NotNull EntityType type, final @Nullable Consumer function, final CreatureSpawnEvent.@NotNull SpawnReason reason) { + return this.spawnEntity(location, type, reason, function); + } + + default @NotNull E spawnEntity(final @NotNull Location location, final @NotNull EntityType type, final CreatureSpawnEvent.@NotNull SpawnReason reason, final @Nullable Consumer function) { + return this.spawnEntity(location, type, true, reason, function); + } /** * Gets the highest non-empty (impassable) coordinate at the given diff --git a/paper-api/src/main/java/org/bukkit/World.java b/paper-api/src/main/java/org/bukkit/World.java index b202bdb84bae..f045937fc88a 100644 --- a/paper-api/src/main/java/org/bukkit/World.java +++ b/paper-api/src/main/java/org/bukkit/World.java @@ -18,6 +18,7 @@ import org.bukkit.entity.AbstractArrow; import org.bukkit.entity.Arrow; import org.bukkit.entity.Entity; +import org.bukkit.entity.EntityType; import org.bukkit.entity.FallingBlock; import org.bukkit.entity.Item; import org.bukkit.entity.LightningStrike; @@ -720,6 +721,23 @@ default Item dropItemNaturally(@NotNull Location location, @NotNull ItemStack it @NotNull public Item dropItemNaturally(@NotNull Location location, @NotNull ItemStack item, @Nullable Consumer function); + /** + * Creates an arrow entity of the given class at the given {@link Location} + * + * @param type of arrow to spawn + * @param location Location to spawn the arrow + * @param direction Direction to shoot the arrow in + * @param speed Speed of the arrow. A recommend speed is 0.6 + * @param spread Spread of the arrow. A recommend spread is 12 + * @param clazz the Entity class for the arrow + * {@link org.bukkit.entity.SpectralArrow}, {@link org.bukkit.entity.Arrow}, {@link org.bukkit.entity.Trident} + * @return Arrow entity spawned as a result of this method + * @deprecated use {@link #spawnArrow(Location, EntityType, Vector, float, float)} + */ + @NotNull + @Deprecated(since = "1.21.11") + public E spawnArrow(@NotNull Location location, @NotNull Vector direction, float speed, float spread, @NotNull Class clazz); + /** * Creates an {@link Arrow} entity at the given {@link Location} * @@ -731,23 +749,22 @@ default Item dropItemNaturally(@NotNull Location location, @NotNull ItemStack it */ @NotNull default Arrow spawnArrow(@NotNull Location location, @NotNull Vector direction, float speed, float spread) { - return this.spawnArrow(location, direction, speed, spread, Arrow.class); + return this.spawnArrow(location, EntityType.ARROW, direction, speed, spread); } /** * Creates an arrow entity of the given class at the given {@link Location} * - * @param type of arrow to spawn + * @param type of arrow to spawn * @param location Location to spawn the arrow - * @param direction Direction to shoot the arrow in - * @param speed Speed of the arrow. A recommend speed is 0.6 - * @param spread Spread of the arrow. A recommend spread is 12 - * @param clazz the Entity class for the arrow - * {@link org.bukkit.entity.SpectralArrow},{@link org.bukkit.entity.Arrow},{@link org.bukkit.entity.TippedArrow} + * @param type the entity type for the arrow + * @param direction direction to shoot the arrow in + * @param speed speed of the arrow. A recommend speed is 0.6 + * @param spread spread of the arrow. A recommend spread is 12 * @return Arrow entity spawned as a result of this method */ @NotNull - public T spawnArrow(@NotNull Location location, @NotNull Vector direction, float speed, float spread, @NotNull Class clazz); + public E spawnArrow(@NotNull Location location, @NotNull EntityType type, @NotNull Vector direction, float speed, float spread); // todo in region accessor? /** * Creates a tree at the given {@link Location} diff --git a/paper-api/src/main/java/org/bukkit/entity/EntityType.java b/paper-api/src/main/java/org/bukkit/entity/EntityType.java index dfd27d40ae3f..7080126dda06 100644 --- a/paper-api/src/main/java/org/bukkit/entity/EntityType.java +++ b/paper-api/src/main/java/org/bukkit/entity/EntityType.java @@ -1,13 +1,10 @@ package org.bukkit.entity; -import com.google.common.base.Preconditions; import io.papermc.paper.InternalAPIBridge; -import io.papermc.paper.registry.RegistryKey; import io.papermc.paper.world.flag.FeatureDependant; import java.util.Locale; import net.kyori.adventure.key.Key; import net.kyori.adventure.key.KeyPattern; -import org.bukkit.Bukkit; import org.bukkit.Keyed; import org.bukkit.Location; import org.bukkit.NamespacedKey; @@ -15,26 +12,6 @@ import org.bukkit.Translatable; import org.bukkit.World; import org.bukkit.attribute.Attributable; -import org.bukkit.entity.boat.AcaciaBoat; -import org.bukkit.entity.boat.AcaciaChestBoat; -import org.bukkit.entity.boat.BambooChestRaft; -import org.bukkit.entity.boat.BambooRaft; -import org.bukkit.entity.boat.BirchBoat; -import org.bukkit.entity.boat.BirchChestBoat; -import org.bukkit.entity.boat.CherryBoat; -import org.bukkit.entity.boat.CherryChestBoat; -import org.bukkit.entity.boat.DarkOakBoat; -import org.bukkit.entity.boat.DarkOakChestBoat; -import org.bukkit.entity.boat.JungleBoat; -import org.bukkit.entity.boat.JungleChestBoat; -import org.bukkit.entity.boat.MangroveBoat; -import org.bukkit.entity.boat.MangroveChestBoat; -import org.bukkit.entity.boat.OakBoat; -import org.bukkit.entity.boat.OakChestBoat; -import org.bukkit.entity.boat.PaleOakBoat; -import org.bukkit.entity.boat.PaleOakChestBoat; -import org.bukkit.entity.boat.SpruceBoat; -import org.bukkit.entity.boat.SpruceChestBoat; import org.bukkit.entity.minecart.CommandMinecart; import org.bukkit.entity.minecart.ExplosiveMinecart; import org.bukkit.entity.minecart.HopperMinecart; @@ -52,9 +29,9 @@ public interface EntityType extends OldEnum>, Keyed, Translatable, net.kyori.adventure.translation.Translatable, FeatureDependant { // Start generate - EntityType - EntityType ACACIA_BOAT = getType("acacia_boat"); + EntityType ACACIA_BOAT = getType("acacia_boat"); - EntityType ACACIA_CHEST_BOAT = getType("acacia_chest_boat"); + EntityType ACACIA_CHEST_BOAT = getType("acacia_chest_boat"); EntityType ALLAY = getType("allay"); @@ -68,17 +45,17 @@ public interface EntityType extends OldEnum>, Ke EntityType AXOLOTL = getType("axolotl"); - EntityType BAMBOO_CHEST_RAFT = getType("bamboo_chest_raft"); + EntityType BAMBOO_CHEST_RAFT = getType("bamboo_chest_raft"); - EntityType BAMBOO_RAFT = getType("bamboo_raft"); + EntityType BAMBOO_RAFT = getType("bamboo_raft"); EntityType BAT = getType("bat"); EntityType BEE = getType("bee"); - EntityType BIRCH_BOAT = getType("birch_boat"); + EntityType BIRCH_BOAT = getType("birch_boat"); - EntityType BIRCH_CHEST_BOAT = getType("birch_chest_boat"); + EntityType BIRCH_CHEST_BOAT = getType("birch_chest_boat"); EntityType BLAZE = getType("blaze"); @@ -98,9 +75,9 @@ public interface EntityType extends OldEnum>, Ke EntityType CAVE_SPIDER = getType("cave_spider"); - EntityType CHERRY_BOAT = getType("cherry_boat"); + EntityType CHERRY_BOAT = getType("cherry_boat"); - EntityType CHERRY_CHEST_BOAT = getType("cherry_chest_boat"); + EntityType CHERRY_CHEST_BOAT = getType("cherry_chest_boat"); EntityType CHEST_MINECART = getType("chest_minecart"); @@ -118,9 +95,9 @@ public interface EntityType extends OldEnum>, Ke EntityType CREEPER = getType("creeper"); - EntityType DARK_OAK_BOAT = getType("dark_oak_boat"); + EntityType DARK_OAK_BOAT = getType("dark_oak_boat"); - EntityType DARK_OAK_CHEST_BOAT = getType("dark_oak_chest_boat"); + EntityType DARK_OAK_CHEST_BOAT = getType("dark_oak_chest_boat"); EntityType DOLPHIN = getType("dolphin"); @@ -156,7 +133,7 @@ public interface EntityType extends OldEnum>, Ke EntityType FALLING_BLOCK = getType("falling_block"); - EntityType FIREBALL = getType("fireball"); + EntityType FIREBALL = getType("fireball"); EntityType FIREWORK_ROCKET = getType("firework_rocket"); @@ -202,9 +179,9 @@ public interface EntityType extends OldEnum>, Ke EntityType ITEM_FRAME = getType("item_frame"); - EntityType JUNGLE_BOAT = getType("jungle_boat"); + EntityType JUNGLE_BOAT = getType("jungle_boat"); - EntityType JUNGLE_CHEST_BOAT = getType("jungle_chest_boat"); + EntityType JUNGLE_CHEST_BOAT = getType("jungle_chest_boat"); EntityType LEASH_KNOT = getType("leash_knot"); @@ -218,9 +195,9 @@ public interface EntityType extends OldEnum>, Ke EntityType MAGMA_CUBE = getType("magma_cube"); - EntityType MANGROVE_BOAT = getType("mangrove_boat"); + EntityType MANGROVE_BOAT = getType("mangrove_boat"); - EntityType MANGROVE_CHEST_BOAT = getType("mangrove_chest_boat"); + EntityType MANGROVE_CHEST_BOAT = getType("mangrove_chest_boat"); EntityType MANNEQUIN = getType("mannequin"); @@ -234,9 +211,9 @@ public interface EntityType extends OldEnum>, Ke EntityType NAUTILUS = getType("nautilus"); - EntityType OAK_BOAT = getType("oak_boat"); + EntityType OAK_BOAT = getType("oak_boat"); - EntityType OAK_CHEST_BOAT = getType("oak_chest_boat"); + EntityType OAK_CHEST_BOAT = getType("oak_chest_boat"); EntityType OCELOT = getType("ocelot"); @@ -244,9 +221,9 @@ public interface EntityType extends OldEnum>, Ke EntityType PAINTING = getType("painting"); - EntityType PALE_OAK_BOAT = getType("pale_oak_boat"); + EntityType PALE_OAK_BOAT = getType("pale_oak_boat"); - EntityType PALE_OAK_CHEST_BOAT = getType("pale_oak_chest_boat"); + EntityType PALE_OAK_CHEST_BOAT = getType("pale_oak_chest_boat"); EntityType PANDA = getType("panda"); @@ -306,9 +283,9 @@ public interface EntityType extends OldEnum>, Ke EntityType SPLASH_POTION = getType("splash_potion"); - EntityType SPRUCE_BOAT = getType("spruce_boat"); + EntityType SPRUCE_BOAT = getType("spruce_boat"); - EntityType SPRUCE_CHEST_BOAT = getType("spruce_chest_boat"); + EntityType SPRUCE_CHEST_BOAT = getType("spruce_chest_boat"); EntityType SQUID = getType("squid"); @@ -378,58 +355,6 @@ private static EntityType getType(final @KeyPattern.Value return (EntityType) Registry.ENTITY_TYPE.getOrThrow(Key.key(Key.MINECRAFT_NAMESPACE, key)); } - /** - * Gets the entity type name. - * - * @return the entity type's name - * @deprecated Magic value - */ - @Deprecated(since = "1.6.2") - @Nullable String getName(); - - @Nullable Class getEntityClass(); - - /** - * Gets the entity type id. - * - * @return the raw type id - * @deprecated Magic value - */ - @Deprecated(since = "1.6.2", forRemoval = true) - short getTypeId(); - - /** - * Gets an entity type from its name. - * - * @param name the entity type's name - * @return the matching entity type or null - * @apiNote Internal Use Only - */ - @ApiStatus.Internal - @Contract("null -> null") - static @Nullable EntityType fromName(@Nullable String name) { - if (name == null) { - return null; - } - return Registry.ENTITY_TYPE.get(Key.key(Key.MINECRAFT_NAMESPACE, name.toLowerCase(Locale.ROOT))); - } - - /** - * Gets an entity from its id. - * - * @param id the raw type id - * @return the matching entity type or null - * @deprecated Magic value - */ - @Deprecated(since = "1.6.2", forRemoval = true) - static @Nullable EntityType fromId(int id) { - if (id > Short.MAX_VALUE) { - return null; - } - return null; - //return ID_MAP.get((short) id); - } - /** * Some entities cannot be spawned using {@link * World#spawnEntity(Location, EntityType)} or {@link @@ -472,28 +397,49 @@ default String getTranslationKey() { Attributable getDefaultAttributes(); /** - * @param name of the entity type. - * @return the entity type with the given name. - * @deprecated only for backwards compatibility, use {@link Registry#get(NamespacedKey)} instead. + * Gets the entity type name. + * + * @return the entity type's name + * @deprecated use {@link #key()} instead */ - @Deprecated(since = "1.21.11", forRemoval = true) @ApiStatus.ScheduledForRemoval(inVersion = "1.22") // Paper - will be removed via asm-utils - static EntityType valueOf(String name) { - if ("UNKNOWN".equals(name)) { - return EntityType.UNKNOWN; - } + @Deprecated(since = "1.6.2", forRemoval = true) + @Nullable String getName(); - NamespacedKey key = NamespacedKey.fromString(name.toLowerCase(Locale.ROOT)); - EntityType entityType = key == null ? null : Bukkit.getUnsafe().get(RegistryKey.ENTITY_TYPE, key); - Preconditions.checkArgument(entityType != null, "No entity type found with the name %s", name); - return entityType; - } + /** + * Gets the entity type name. + * + * @return the entity type's name + * @deprecated no longer needed as the entity type hold the entity class as a generic + */ + @Deprecated(since = "1.21.11", forRemoval = true) + @Nullable Class getEntityClass(); + + /** + * Gets the entity type id. + * + * @return the raw type id + * @deprecated Magic value + */ + @Deprecated(since = "1.6.2", forRemoval = true) + short getTypeId(); /** - * @return an array of all known entity types. - * @deprecated use {@link Registry#stream()}. + * Gets an entity type from its name. + * + * @param name the entity type's name + * @return the matching entity type or null + * @deprecated only for backwards compatibility, use {@link Registry#get(Key)} instead. */ - @Deprecated(since = "1.21.11", forRemoval = true) @ApiStatus.ScheduledForRemoval(inVersion = "1.22") // Paper - will be removed via asm-utils - static EntityType[] values() { - return Registry.ENTITY_TYPE.stream().toArray(EntityType[]::new); + @Contract("null -> null") + @Deprecated(since = "1.21.11", forRemoval = true) + static @Nullable EntityType fromName(@Nullable String name) { + if (name == null) { + return null; + } + NamespacedKey key = NamespacedKey.fromString(name.toLowerCase(Locale.ROOT)); + if (key == null) { + return null; + } + return Registry.ENTITY_TYPE.get(key); } } diff --git a/paper-api/src/main/java/org/bukkit/entity/boat/AcaciaBoat.java b/paper-api/src/main/java/org/bukkit/entity/boat/AcaciaBoat.java index 2a6e1f5cf5ec..2b8d0c38c8cb 100644 --- a/paper-api/src/main/java/org/bukkit/entity/boat/AcaciaBoat.java +++ b/paper-api/src/main/java/org/bukkit/entity/boat/AcaciaBoat.java @@ -5,6 +5,6 @@ /** * Represents an acacia boat. */ -@Deprecated(since = "1.21.11", forRemoval = true) +@Deprecated(since = "1.21.11", forRemoval = true) @org.jetbrains.annotations.ApiStatus.ScheduledForRemoval(inVersion = "1.22") // Paper - will be removed via asm-utils public interface AcaciaBoat extends Boat { } diff --git a/paper-api/src/main/java/org/bukkit/entity/boat/AcaciaChestBoat.java b/paper-api/src/main/java/org/bukkit/entity/boat/AcaciaChestBoat.java index c68b90018672..52e9385b420b 100644 --- a/paper-api/src/main/java/org/bukkit/entity/boat/AcaciaChestBoat.java +++ b/paper-api/src/main/java/org/bukkit/entity/boat/AcaciaChestBoat.java @@ -5,6 +5,6 @@ /** * Represents an acacia chest boat. */ -@Deprecated(since = "1.21.11", forRemoval = true) +@Deprecated(since = "1.21.11", forRemoval = true) @org.jetbrains.annotations.ApiStatus.ScheduledForRemoval(inVersion = "1.22") // Paper - will be removed via asm-utils public interface AcaciaChestBoat extends ChestBoat { } diff --git a/paper-api/src/main/java/org/bukkit/entity/boat/BambooChestRaft.java b/paper-api/src/main/java/org/bukkit/entity/boat/BambooChestRaft.java index f39f8f54c50b..ed7d348ada89 100644 --- a/paper-api/src/main/java/org/bukkit/entity/boat/BambooChestRaft.java +++ b/paper-api/src/main/java/org/bukkit/entity/boat/BambooChestRaft.java @@ -5,6 +5,6 @@ /** * Represents a bamboo chest raft. */ -@Deprecated(since = "1.21.11", forRemoval = true) +@Deprecated(since = "1.21.11", forRemoval = true) @org.jetbrains.annotations.ApiStatus.ScheduledForRemoval(inVersion = "1.22") // Paper - will be removed via asm-utils public interface BambooChestRaft extends ChestBoat { } diff --git a/paper-api/src/main/java/org/bukkit/entity/boat/BambooRaft.java b/paper-api/src/main/java/org/bukkit/entity/boat/BambooRaft.java index ca0dd4c872a0..ee5593ed31f3 100644 --- a/paper-api/src/main/java/org/bukkit/entity/boat/BambooRaft.java +++ b/paper-api/src/main/java/org/bukkit/entity/boat/BambooRaft.java @@ -5,6 +5,6 @@ /** * Represents a bamboo raft. */ -@Deprecated(since = "1.21.11", forRemoval = true) +@Deprecated(since = "1.21.11", forRemoval = true) @org.jetbrains.annotations.ApiStatus.ScheduledForRemoval(inVersion = "1.22") // Paper - will be removed via asm-utils public interface BambooRaft extends Boat { } diff --git a/paper-api/src/main/java/org/bukkit/entity/boat/BirchBoat.java b/paper-api/src/main/java/org/bukkit/entity/boat/BirchBoat.java index 2c9160a2c029..b9dea268ea09 100644 --- a/paper-api/src/main/java/org/bukkit/entity/boat/BirchBoat.java +++ b/paper-api/src/main/java/org/bukkit/entity/boat/BirchBoat.java @@ -5,6 +5,6 @@ /** * Represents a birch boat. */ -@Deprecated(since = "1.21.11", forRemoval = true) +@Deprecated(since = "1.21.11", forRemoval = true) @org.jetbrains.annotations.ApiStatus.ScheduledForRemoval(inVersion = "1.22") // Paper - will be removed via asm-utils public interface BirchBoat extends Boat { } diff --git a/paper-api/src/main/java/org/bukkit/entity/boat/BirchChestBoat.java b/paper-api/src/main/java/org/bukkit/entity/boat/BirchChestBoat.java index 766933992f43..4e451de77aa0 100644 --- a/paper-api/src/main/java/org/bukkit/entity/boat/BirchChestBoat.java +++ b/paper-api/src/main/java/org/bukkit/entity/boat/BirchChestBoat.java @@ -5,6 +5,6 @@ /** * Represents a birch chest boat. */ -@Deprecated(since = "1.21.11", forRemoval = true) +@Deprecated(since = "1.21.11", forRemoval = true) @org.jetbrains.annotations.ApiStatus.ScheduledForRemoval(inVersion = "1.22") // Paper - will be removed via asm-utils public interface BirchChestBoat extends ChestBoat { } diff --git a/paper-api/src/main/java/org/bukkit/entity/boat/CherryBoat.java b/paper-api/src/main/java/org/bukkit/entity/boat/CherryBoat.java index 562c64bd98bd..057ee64ea5c0 100644 --- a/paper-api/src/main/java/org/bukkit/entity/boat/CherryBoat.java +++ b/paper-api/src/main/java/org/bukkit/entity/boat/CherryBoat.java @@ -5,6 +5,6 @@ /** * Represents a cherry boat. */ -@Deprecated(since = "1.21.11", forRemoval = true) +@Deprecated(since = "1.21.11", forRemoval = true) @org.jetbrains.annotations.ApiStatus.ScheduledForRemoval(inVersion = "1.22") // Paper - will be removed via asm-utils public interface CherryBoat extends Boat { } diff --git a/paper-api/src/main/java/org/bukkit/entity/boat/CherryChestBoat.java b/paper-api/src/main/java/org/bukkit/entity/boat/CherryChestBoat.java index 10d09bb4e30c..006acc13eebf 100644 --- a/paper-api/src/main/java/org/bukkit/entity/boat/CherryChestBoat.java +++ b/paper-api/src/main/java/org/bukkit/entity/boat/CherryChestBoat.java @@ -5,6 +5,6 @@ /** * Represents a cherry chest boat. */ -@Deprecated(since = "1.21.11", forRemoval = true) +@Deprecated(since = "1.21.11", forRemoval = true) @org.jetbrains.annotations.ApiStatus.ScheduledForRemoval(inVersion = "1.22") // Paper - will be removed via asm-utils public interface CherryChestBoat extends ChestBoat { } diff --git a/paper-api/src/main/java/org/bukkit/entity/boat/DarkOakBoat.java b/paper-api/src/main/java/org/bukkit/entity/boat/DarkOakBoat.java index ba07ca0952f5..0ab4db45e98d 100644 --- a/paper-api/src/main/java/org/bukkit/entity/boat/DarkOakBoat.java +++ b/paper-api/src/main/java/org/bukkit/entity/boat/DarkOakBoat.java @@ -5,6 +5,6 @@ /** * Represents a dark oak boat. */ -@Deprecated(since = "1.21.11", forRemoval = true) +@Deprecated(since = "1.21.11", forRemoval = true) @org.jetbrains.annotations.ApiStatus.ScheduledForRemoval(inVersion = "1.22") // Paper - will be removed via asm-utils public interface DarkOakBoat extends Boat { } diff --git a/paper-api/src/main/java/org/bukkit/entity/boat/DarkOakChestBoat.java b/paper-api/src/main/java/org/bukkit/entity/boat/DarkOakChestBoat.java index 7342a836a1a7..a2c1e5dba303 100644 --- a/paper-api/src/main/java/org/bukkit/entity/boat/DarkOakChestBoat.java +++ b/paper-api/src/main/java/org/bukkit/entity/boat/DarkOakChestBoat.java @@ -5,6 +5,6 @@ /** * Represents a dark oak chest boat. */ -@Deprecated(since = "1.21.11", forRemoval = true) +@Deprecated(since = "1.21.11", forRemoval = true) @org.jetbrains.annotations.ApiStatus.ScheduledForRemoval(inVersion = "1.22") // Paper - will be removed via asm-utils public interface DarkOakChestBoat extends ChestBoat { } diff --git a/paper-api/src/main/java/org/bukkit/entity/boat/JungleBoat.java b/paper-api/src/main/java/org/bukkit/entity/boat/JungleBoat.java index 7bcfb504207b..a36e71ea9e09 100644 --- a/paper-api/src/main/java/org/bukkit/entity/boat/JungleBoat.java +++ b/paper-api/src/main/java/org/bukkit/entity/boat/JungleBoat.java @@ -5,6 +5,6 @@ /** * Represents a jungle boat. */ -@Deprecated(since = "1.21.11", forRemoval = true) +@Deprecated(since = "1.21.11", forRemoval = true) @org.jetbrains.annotations.ApiStatus.ScheduledForRemoval(inVersion = "1.22") // Paper - will be removed via asm-utils public interface JungleBoat extends Boat { } diff --git a/paper-api/src/main/java/org/bukkit/entity/boat/JungleChestBoat.java b/paper-api/src/main/java/org/bukkit/entity/boat/JungleChestBoat.java index b1c95ce78a10..3f8081218ec2 100644 --- a/paper-api/src/main/java/org/bukkit/entity/boat/JungleChestBoat.java +++ b/paper-api/src/main/java/org/bukkit/entity/boat/JungleChestBoat.java @@ -5,6 +5,6 @@ /** * Represents a jungle chest boat. */ -@Deprecated(since = "1.21.11", forRemoval = true) +@Deprecated(since = "1.21.11", forRemoval = true) @org.jetbrains.annotations.ApiStatus.ScheduledForRemoval(inVersion = "1.22") // Paper - will be removed via asm-utils public interface JungleChestBoat extends ChestBoat { } diff --git a/paper-api/src/main/java/org/bukkit/entity/boat/MangroveBoat.java b/paper-api/src/main/java/org/bukkit/entity/boat/MangroveBoat.java index 05536b970248..807e15c89612 100644 --- a/paper-api/src/main/java/org/bukkit/entity/boat/MangroveBoat.java +++ b/paper-api/src/main/java/org/bukkit/entity/boat/MangroveBoat.java @@ -5,6 +5,6 @@ /** * Represents a mangrove boat. */ -@Deprecated(since = "1.21.11", forRemoval = true) +@Deprecated(since = "1.21.11", forRemoval = true) @org.jetbrains.annotations.ApiStatus.ScheduledForRemoval(inVersion = "1.22") // Paper - will be removed via asm-utils public interface MangroveBoat extends Boat { } diff --git a/paper-api/src/main/java/org/bukkit/entity/boat/MangroveChestBoat.java b/paper-api/src/main/java/org/bukkit/entity/boat/MangroveChestBoat.java index 51298485b977..31d49b773dce 100644 --- a/paper-api/src/main/java/org/bukkit/entity/boat/MangroveChestBoat.java +++ b/paper-api/src/main/java/org/bukkit/entity/boat/MangroveChestBoat.java @@ -5,6 +5,6 @@ /** * Represents a mangrove chest boat. */ -@Deprecated(since = "1.21.11", forRemoval = true) +@Deprecated(since = "1.21.11", forRemoval = true) @org.jetbrains.annotations.ApiStatus.ScheduledForRemoval(inVersion = "1.22") // Paper - will be removed via asm-utils public interface MangroveChestBoat extends ChestBoat { } diff --git a/paper-api/src/main/java/org/bukkit/entity/boat/OakBoat.java b/paper-api/src/main/java/org/bukkit/entity/boat/OakBoat.java index b359f901be5a..a547d4d14226 100644 --- a/paper-api/src/main/java/org/bukkit/entity/boat/OakBoat.java +++ b/paper-api/src/main/java/org/bukkit/entity/boat/OakBoat.java @@ -5,6 +5,6 @@ /** * Represents an oak boat. */ -@Deprecated(since = "1.21.11", forRemoval = true) +@Deprecated(since = "1.21.11", forRemoval = true) @org.jetbrains.annotations.ApiStatus.ScheduledForRemoval(inVersion = "1.22") // Paper - will be removed via asm-utils public interface OakBoat extends Boat { } diff --git a/paper-api/src/main/java/org/bukkit/entity/boat/OakChestBoat.java b/paper-api/src/main/java/org/bukkit/entity/boat/OakChestBoat.java index 162a74371560..4ecab57ce16b 100644 --- a/paper-api/src/main/java/org/bukkit/entity/boat/OakChestBoat.java +++ b/paper-api/src/main/java/org/bukkit/entity/boat/OakChestBoat.java @@ -5,6 +5,6 @@ /** * Represents an oak chest boat. */ -@Deprecated(since = "1.21.11", forRemoval = true) +@Deprecated(since = "1.21.11", forRemoval = true) @org.jetbrains.annotations.ApiStatus.ScheduledForRemoval(inVersion = "1.22") // Paper - will be removed via asm-utils public interface OakChestBoat extends ChestBoat { } diff --git a/paper-api/src/main/java/org/bukkit/entity/boat/PaleOakBoat.java b/paper-api/src/main/java/org/bukkit/entity/boat/PaleOakBoat.java index 5e7f0b4aeba6..fde96c6da2f0 100644 --- a/paper-api/src/main/java/org/bukkit/entity/boat/PaleOakBoat.java +++ b/paper-api/src/main/java/org/bukkit/entity/boat/PaleOakBoat.java @@ -5,6 +5,6 @@ /** * Represents a pale oak boat. */ -@Deprecated(since = "1.21.11", forRemoval = true) +@Deprecated(since = "1.21.11", forRemoval = true) @org.jetbrains.annotations.ApiStatus.ScheduledForRemoval(inVersion = "1.22") // Paper - will be removed via asm-utils public interface PaleOakBoat extends Boat { } diff --git a/paper-api/src/main/java/org/bukkit/entity/boat/PaleOakChestBoat.java b/paper-api/src/main/java/org/bukkit/entity/boat/PaleOakChestBoat.java index 0c55a4058ca9..f5862bd1ba7a 100644 --- a/paper-api/src/main/java/org/bukkit/entity/boat/PaleOakChestBoat.java +++ b/paper-api/src/main/java/org/bukkit/entity/boat/PaleOakChestBoat.java @@ -5,6 +5,6 @@ /** * Represents a pale oak chest boat. */ -@Deprecated(since = "1.21.11", forRemoval = true) +@Deprecated(since = "1.21.11", forRemoval = true) @org.jetbrains.annotations.ApiStatus.ScheduledForRemoval(inVersion = "1.22") // Paper - will be removed via asm-utils public interface PaleOakChestBoat extends ChestBoat { } diff --git a/paper-api/src/main/java/org/bukkit/entity/boat/SpruceBoat.java b/paper-api/src/main/java/org/bukkit/entity/boat/SpruceBoat.java index 10021fa5353c..1938bb392cf4 100644 --- a/paper-api/src/main/java/org/bukkit/entity/boat/SpruceBoat.java +++ b/paper-api/src/main/java/org/bukkit/entity/boat/SpruceBoat.java @@ -5,6 +5,6 @@ /** * Represents a spruce boat. */ -@Deprecated(since = "1.21.11", forRemoval = true) +@Deprecated(since = "1.21.11", forRemoval = true) @org.jetbrains.annotations.ApiStatus.ScheduledForRemoval(inVersion = "1.22") // Paper - will be removed via asm-utils public interface SpruceBoat extends Boat { } diff --git a/paper-api/src/main/java/org/bukkit/entity/boat/SpruceChestBoat.java b/paper-api/src/main/java/org/bukkit/entity/boat/SpruceChestBoat.java index f43cfb9c0271..f1ea2cd11583 100644 --- a/paper-api/src/main/java/org/bukkit/entity/boat/SpruceChestBoat.java +++ b/paper-api/src/main/java/org/bukkit/entity/boat/SpruceChestBoat.java @@ -5,6 +5,6 @@ /** * Represents a spruce chest boat. */ -@Deprecated(since = "1.21.11", forRemoval = true) +@Deprecated(since = "1.21.11", forRemoval = true) @org.jetbrains.annotations.ApiStatus.ScheduledForRemoval(inVersion = "1.22") // Paper - will be removed via asm-utils public interface SpruceChestBoat extends ChestBoat { } diff --git a/paper-api/src/main/java/org/bukkit/entity/boat/package-info.java b/paper-api/src/main/java/org/bukkit/entity/boat/package-info.java index 6d655f246073..b8170aadee36 100644 --- a/paper-api/src/main/java/org/bukkit/entity/boat/package-info.java +++ b/paper-api/src/main/java/org/bukkit/entity/boat/package-info.java @@ -1,5 +1,5 @@ /** * Interfaces for various {@link org.bukkit.entity.Boat} types. */ -@Deprecated(since = "1.21.11", forRemoval = true) +@Deprecated(since = "1.21.11", forRemoval = true) @org.jetbrains.annotations.ApiStatus.ScheduledForRemoval(inVersion = "1.22") // Paper - will be removed via asm-utils package org.bukkit.entity.boat; diff --git a/paper-api/src/main/java/org/bukkit/material/SpawnEgg.java b/paper-api/src/main/java/org/bukkit/material/SpawnEgg.java index 69011a06f0cd..ce98ef57dbb8 100644 --- a/paper-api/src/main/java/org/bukkit/material/SpawnEgg.java +++ b/paper-api/src/main/java/org/bukkit/material/SpawnEgg.java @@ -47,7 +47,8 @@ public SpawnEgg(EntityType type) { */ @Deprecated(since = "1.9") public EntityType getSpawnedType() { - return EntityType.fromId(getData()); + return EntityType.UNKNOWN; // todo asm-utils + //return EntityType.fromId(getData()); } /** diff --git a/paper-generator/src/main/java/io/papermc/generator/rewriter/types/simple/EntityTypeRewriter.java b/paper-generator/src/main/java/io/papermc/generator/rewriter/types/simple/EntityTypeRewriter.java index 3dd46cc5428b..7e263464e194 100644 --- a/paper-generator/src/main/java/io/papermc/generator/rewriter/types/simple/EntityTypeRewriter.java +++ b/paper-generator/src/main/java/io/papermc/generator/rewriter/types/simple/EntityTypeRewriter.java @@ -1,6 +1,5 @@ package io.papermc.generator.rewriter.types.simple; -import com.google.common.base.CaseFormat; import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableMap; import io.papermc.generator.registry.RegistryEntries; @@ -28,19 +27,32 @@ public class EntityTypeRewriter extends RegistryFieldRewriter> { }); private static final Map CLASS_RENAMES = ImmutableMap.builder() - .put("ExperienceBottle", "ThrownExpBottle") - .put("EyeOfEnder", "EnderSignal") + .put("ItemEntity", "Item") .put("EndCrystal", "EnderCrystal") - .put("FireworkRocket", "Firework") - .put("FishingBobber", "FishHook") - .put("LeashKnot", "LeashHitch") + .put("ThrownEgg", "Egg") + .put("ThrownEnderpearl", "EnderPearl") + .put("ThrownExperienceBottle", "ThrownExpBottle") + .put("ThrownLingeringPotion", "LingeringPotion") + .put("ThrownSplashPotion", "SplashPotion") + .put("ThrownTrident", "Trident") + .put("PrimedTnt", "TNTPrimed") + .put("EyeOfEnder", "EnderSignal") + .put("FallingBlockEntity", "FallingBlock") + .put("FireworkRocketEntity", "Firework") + .put("FishingHook", "FishHook") + .put("LeashFenceKnotEntity", "LeashHitch") .put("LightningBolt", "LightningStrike") - .put("Tnt", "TNTPrimed") + + .put("MinecartChest", "StorageMinecart") + .put("MinecartCommandBlock", "CommandMinecart") + .put("MinecartFurnace", "PoweredMinecart") + .put("MinecartHopper", "HopperMinecart") + .put("MinecartSpawner", "SpawnerMinecart") + .put("MinecartTNT", "ExplosiveMinecart") .put("Minecart", "RideableMinecart") - .put("ChestMinecart", "StorageMinecart") - .put("CommandBlockMinecart", "CommandMinecart") - .put("TntMinecart", "ExplosiveMinecart") - .put("FurnaceMinecart", "PoweredMinecart") + + .put("Raft", "Boat") + .put("ChestRaft", "ChestBoat") .buildOrThrow(); private static final ClassResolver runtime = new ClassResolver(EntityTypeRewriter.class.getClassLoader()); @@ -63,11 +75,12 @@ private String toBukkitClass(Holder.Reference> reference) { return this.importCollector.getShortName(MobGoalNames.BUKKIT_BRIDGE.get((Class) internalClass)); } - String className = CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.UPPER_CAMEL, reference.key().identifier().getPath()); // use the key instead of the internal class name since name match a bit more - ClassNamed resolvedClass = this.classNamedView.tryFindFirst(CLASS_RENAMES.getOrDefault(className, className)) - .orElseThrow(() -> new IllegalStateException("Could not find entity class for " + reference.key().identifier())) + String internalClassName = internalClass.getSimpleName(); + String className = CLASS_RENAMES.getOrDefault(internalClassName, internalClassName); + ClassNamed resolvedClass = this.classNamedView.tryFindFirst(className) + .orElseThrow(() -> new IllegalStateException("Could not find entity class for " + reference.key().identifier() + " (" + className + ")")) .resolve(runtime); Preconditions.checkArgument(org.bukkit.entity.Entity.class.isAssignableFrom(resolvedClass.knownClass()), "Generic type must be an entity"); - return this.importCollector.getShortName(this.classNamedView.findFirst(CLASS_RENAMES.getOrDefault(className, className)).resolve(runtime)); + return this.importCollector.getShortName(resolvedClass); } } diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/CraftRegionAccessor.java b/paper-server/src/main/java/org/bukkit/craftbukkit/CraftRegionAccessor.java index 21d594a39d09..200ea41ac761 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/CraftRegionAccessor.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/CraftRegionAccessor.java @@ -18,12 +18,10 @@ import net.minecraft.world.entity.EntitySpawnReason; import net.minecraft.world.entity.Mob; import net.minecraft.world.entity.SpawnGroupData; -import net.minecraft.world.level.Level; import net.minecraft.world.level.WorldGenLevel; import net.minecraft.world.level.block.ChorusFlowerBlock; import net.minecraft.world.level.chunk.ChunkGenerator; import net.minecraft.world.level.levelgen.feature.ConfiguredFeature; -import net.minecraft.world.level.portal.TeleportTransition; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.RegionAccessor; @@ -251,11 +249,6 @@ public boolean generateTree(WorldGenLevel access, ChunkGenerator chunkGenerator, return holder != null && holder.value().place(access, chunkGenerator, random, pos); } - @Override - public Entity spawnEntity(Location loc, EntityType type, boolean randomizeData) { - return this.spawn(loc, type.getEntityClass(), null, CreatureSpawnEvent.SpawnReason.CUSTOM, randomizeData); - } - @Override public List getEntities() { List list = new ArrayList<>(); @@ -351,20 +344,34 @@ public T createEntity(Location location, Class clazz) thro } @Override - public T spawn(Location location, Class clazz, Consumer function) throws IllegalArgumentException { - return this.spawn(location, clazz, function, CreatureSpawnEvent.SpawnReason.CUSTOM); + @SuppressWarnings("unchecked") + public T createEntity(Location location, EntityType type) throws IllegalArgumentException { + net.minecraft.world.entity.Entity entity = this.createEntity(location, type, true); + + if (!this.isNormalWorld()) { + entity.generation = true; + } + + return (T) entity.getBukkitEntity(); + } + + @Override + public E spawnEntity(Location location, EntityType type, boolean randomizeData, CreatureSpawnEvent.SpawnReason reason, Consumer function) throws IllegalArgumentException { + net.minecraft.world.entity.Entity entity = this.createEntity(location, type, randomizeData); + + return this.addEntity(entity, reason, function, randomizeData); } @Override - public T spawn(Location location, Class clazz, boolean randomizeData, Consumer function) throws IllegalArgumentException { - return this.spawn(location, clazz, function, CreatureSpawnEvent.SpawnReason.CUSTOM, randomizeData); + public E spawn(Location location, Class clazz, boolean randomizeData, Consumer function) throws IllegalArgumentException { + return this.spawn0(location, clazz, function, CreatureSpawnEvent.SpawnReason.CUSTOM, randomizeData); } - public T spawn(Location location, Class clazz, Consumer function, CreatureSpawnEvent.SpawnReason reason) throws IllegalArgumentException { - return this.spawn(location, clazz, function, reason, true); + public E spawn(Location location, Class clazz, Consumer function, CreatureSpawnEvent.SpawnReason reason) throws IllegalArgumentException { + return this.spawn0(location, clazz, function, reason, true); } - public T spawn(Location location, Class clazz, Consumer function, CreatureSpawnEvent.SpawnReason reason, boolean randomizeData) throws IllegalArgumentException { + protected E spawn0(Location location, Class clazz, Consumer function, CreatureSpawnEvent.SpawnReason reason, boolean randomizeData) throws IllegalArgumentException { net.minecraft.world.entity.Entity entity = this.createEntity(location, clazz, randomizeData); return this.addEntity(entity, reason, function, randomizeData); @@ -412,6 +419,28 @@ public T addEntity(net.minecraft.world.entity.Entity entity, public abstract void addEntityWithPassengers(net.minecraft.world.entity.Entity entity, CreatureSpawnEvent.SpawnReason reason); + public net.minecraft.world.entity.Entity createEntity(Location location, EntityType type, boolean randomizeData) throws IllegalArgumentException { + Preconditions.checkArgument(location != null, "Location cannot be null"); + Preconditions.checkArgument(type != null, "Entity type cannot be null"); + + CraftEntityTypes.EntityTypeData entityTypeData = CraftEntityTypes.getEntityTypeData(type); + if (entityTypeData.spawnFunction() == null) { + throw new IllegalArgumentException("Cannot spawn an entity for " + type.key().asString()); + } + + if (!this.isEnabled(entityTypeData.entityType())) { + throw new IllegalArgumentException("Cannot spawn an entity for " + type.key().asString() + " because it is not an enabled feature"); + } + + net.minecraft.world.entity.Entity entity = entityTypeData.spawnFunction().apply(new CraftEntityTypes.SpawnData(this.getHandle(), location, randomizeData, this.isNormalWorld())); + + if (entity != null) { + return entity; + } + + throw new IllegalArgumentException("Cannot spawn an entity for " + type.key().asString()); + } + @SuppressWarnings("unchecked") public net.minecraft.world.entity.Entity createEntity(Location location, Class clazz, boolean randomizeData) throws IllegalArgumentException { Preconditions.checkArgument(location != null, "Location cannot be null"); diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/CraftWorld.java b/paper-server/src/main/java/org/bukkit/craftbukkit/CraftWorld.java index ebc65e3338c6..caf026e81338 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/CraftWorld.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/CraftWorld.java @@ -109,6 +109,7 @@ import org.bukkit.craftbukkit.block.data.CraftBlockData; import org.bukkit.craftbukkit.boss.CraftDragonBattle; import org.bukkit.craftbukkit.entity.CraftEntity; +import org.bukkit.craftbukkit.entity.CraftEntityType; import org.bukkit.craftbukkit.entity.CraftPlayer; import org.bukkit.craftbukkit.event.CraftEventFactory; import org.bukkit.craftbukkit.generator.structure.CraftGeneratedStructure; @@ -687,6 +688,9 @@ public T spawnArrow(Location location, Vector directio } else { arrow = EntityType.ARROW.create(this.world, EntitySpawnReason.COMMAND); } + if (arrow == null) { + throw new UnsupportedOperationException("Entity type " + clazz.getName() + " is not valid for this world"); + } arrow.snapTo(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch()); arrow.shoot(direction.getX(), direction.getY(), direction.getZ(), speed, spread); @@ -694,6 +698,24 @@ public T spawnArrow(Location location, Vector directio return (T) arrow.getBukkitEntity(); } + @Override + public E spawnArrow(Location location, org.bukkit.entity.EntityType type, Vector direction, float speed, float spread) { + Preconditions.checkArgument(location != null, "Location cannot be null"); + Preconditions.checkArgument(direction != null, "Vector cannot be null"); + Preconditions.checkArgument(type != null, "Entity type for the arrow cannot be null"); + + EntityType typed = CraftEntityType.bukkitToMinecraft(type); + net.minecraft.world.entity.projectile.arrow.AbstractArrow arrow = typed.create(this.world, EntitySpawnReason.COMMAND); + if (arrow == null) { + throw new UnsupportedOperationException("Entity type " + type.key().asString() + " is not valid for this world"); + } + + arrow.snapTo(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch()); + arrow.shoot(direction.getX(), direction.getY(), direction.getZ(), speed, spread); + this.world.addFreshEntity(arrow); + return (E) arrow.getBukkitEntity(); + } + @Override public LightningStrike strikeLightning(Location loc) { return this.strikeLightning0(loc, false); @@ -892,7 +914,7 @@ public List getPopulators() { @Override public T spawn(@NotNull Location location, @NotNull Class clazz, @NotNull SpawnReason spawnReason, boolean randomizeData, @Nullable Consumer function) throws IllegalArgumentException { Preconditions.checkArgument(spawnReason != null, "Spawn reason cannot be null"); - return this.spawn(location, clazz, function, spawnReason, randomizeData); + return this.spawn0(location, clazz, function, spawnReason, randomizeData); } @Override diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftBoat.java b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftBoat.java index 02a4a8641050..80b5882337d2 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftBoat.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftBoat.java @@ -6,7 +6,7 @@ import org.bukkit.craftbukkit.CraftServer; import org.bukkit.entity.Boat; -public abstract class CraftBoat extends CraftVehicle implements Boat, io.papermc.paper.entity.PaperLeashable { // Paper - Leashable API +public class CraftBoat extends CraftVehicle implements Boat, io.papermc.paper.entity.PaperLeashable { // Paper - Leashable API public CraftBoat(CraftServer server, AbstractBoat entity) { super(server, entity); diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftChestBoat.java b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftChestBoat.java index b718a5fa75eb..be3c6705e6f8 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftChestBoat.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftChestBoat.java @@ -5,7 +5,7 @@ import org.bukkit.craftbukkit.inventory.CraftInventory; import org.bukkit.inventory.Inventory; -public abstract class CraftChestBoat extends CraftBoat implements org.bukkit.entity.ChestBoat, com.destroystokyo.paper.loottable.PaperLootableEntityInventory { // Paper +public class CraftChestBoat extends CraftBoat implements org.bukkit.entity.ChestBoat, com.destroystokyo.paper.loottable.PaperLootableEntityInventory { // Paper private final Inventory inventory; public CraftChestBoat(CraftServer server, AbstractChestBoat entity) { diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftEntityType.java b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftEntityType.java index c5c768a5fc2b..486ba39de5ef 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftEntityType.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftEntityType.java @@ -1,22 +1,22 @@ package org.bukkit.craftbukkit.entity; import com.google.common.base.Preconditions; +import com.google.common.collect.ImmutableBiMap; import io.papermc.paper.attribute.UnmodifiableAttributeMap; import io.papermc.paper.registry.RegistryKey; import io.papermc.paper.util.OldEnumHolderable; import io.papermc.paper.world.flag.PaperFeatureDependent; -import it.unimi.dsi.fastutil.objects.Object2IntMap; -import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap; import java.util.Locale; import java.util.Objects; import java.util.Set; import net.minecraft.core.Holder; import net.minecraft.core.registries.Registries; -import net.minecraft.util.Util; import net.minecraft.world.entity.ai.attributes.AttributeSupplier; import net.minecraft.world.entity.ai.attributes.DefaultAttributes; +import org.bukkit.Bukkit; import org.bukkit.FeatureFlag; import org.bukkit.NamespacedKey; +import org.bukkit.Registry; import org.bukkit.attribute.Attributable; import org.bukkit.craftbukkit.CraftRegistry; import org.bukkit.craftbukkit.legacy.FieldRename; @@ -31,96 +31,6 @@ @NullMarked public class CraftEntityType extends OldEnumHolderable, net.minecraft.world.entity.EntityType> implements EntityType, PaperFeatureDependent> { - @Deprecated - private static final Object2IntMap> LEGACY_ID = Util.make(new Object2IntOpenHashMap<>(), map -> { - map.put(net.minecraft.world.entity.EntityType.ITEM, 1); - map.put(net.minecraft.world.entity.EntityType.EXPERIENCE_ORB, 2); - map.put(net.minecraft.world.entity.EntityType.AREA_EFFECT_CLOUD, 3); - map.put(net.minecraft.world.entity.EntityType.ELDER_GUARDIAN, 4); - map.put(net.minecraft.world.entity.EntityType.WITHER_SKELETON, 5); - map.put(net.minecraft.world.entity.EntityType.STRAY, 6); - map.put(net.minecraft.world.entity.EntityType.EGG, 7); - map.put(net.minecraft.world.entity.EntityType.LEASH_KNOT, 8); - map.put(net.minecraft.world.entity.EntityType.PAINTING, 9); - map.put(net.minecraft.world.entity.EntityType.ARROW, 10); - map.put(net.minecraft.world.entity.EntityType.SNOWBALL, 11); - map.put(net.minecraft.world.entity.EntityType.FIREBALL, 12); - map.put(net.minecraft.world.entity.EntityType.SMALL_FIREBALL, 13); - map.put(net.minecraft.world.entity.EntityType.ENDER_PEARL, 14); - map.put(net.minecraft.world.entity.EntityType.EYE_OF_ENDER, 15); - map.put(net.minecraft.world.entity.EntityType.SPLASH_POTION, 16); - map.put(net.minecraft.world.entity.EntityType.EXPERIENCE_BOTTLE, 17); - map.put(net.minecraft.world.entity.EntityType.ITEM_FRAME, 18); - map.put(net.minecraft.world.entity.EntityType.WITHER_SKULL, 19); - map.put(net.minecraft.world.entity.EntityType.TNT, 20); - map.put(net.minecraft.world.entity.EntityType.FALLING_BLOCK, 21); - map.put(net.minecraft.world.entity.EntityType.FIREWORK_ROCKET, 22); - map.put(net.minecraft.world.entity.EntityType.HUSK, 23); - map.put(net.minecraft.world.entity.EntityType.SPECTRAL_ARROW, 24); - map.put(net.minecraft.world.entity.EntityType.SHULKER_BULLET, 25); - map.put(net.minecraft.world.entity.EntityType.DRAGON_FIREBALL, 26); - map.put(net.minecraft.world.entity.EntityType.ZOMBIE_VILLAGER, 27); - map.put(net.minecraft.world.entity.EntityType.SKELETON_HORSE, 28); - map.put(net.minecraft.world.entity.EntityType.ZOMBIE_HORSE, 29); - map.put(net.minecraft.world.entity.EntityType.ARMOR_STAND, 30); - map.put(net.minecraft.world.entity.EntityType.DONKEY, 31); - map.put(net.minecraft.world.entity.EntityType.MULE, 32); - map.put(net.minecraft.world.entity.EntityType.EVOKER_FANGS, 33); - map.put(net.minecraft.world.entity.EntityType.EVOKER, 34); - map.put(net.minecraft.world.entity.EntityType.VEX, 35); - map.put(net.minecraft.world.entity.EntityType.VINDICATOR, 36); - map.put(net.minecraft.world.entity.EntityType.ILLUSIONER, 37); - - map.put(net.minecraft.world.entity.EntityType.COMMAND_BLOCK_MINECART, 40); - map.put(net.minecraft.world.entity.EntityType.MINECART, 42); - map.put(net.minecraft.world.entity.EntityType.CHEST_MINECART, 43); - map.put(net.minecraft.world.entity.EntityType.FURNACE_MINECART, 44); - map.put(net.minecraft.world.entity.EntityType.TNT_MINECART, 45); - map.put(net.minecraft.world.entity.EntityType.HOPPER_MINECART, 46); - map.put(net.minecraft.world.entity.EntityType.SPAWNER_MINECART, 47); - - map.put(net.minecraft.world.entity.EntityType.CREEPER, 50); - map.put(net.minecraft.world.entity.EntityType.SKELETON, 51); - map.put(net.minecraft.world.entity.EntityType.SPIDER, 52); - map.put(net.minecraft.world.entity.EntityType.GIANT, 53); - map.put(net.minecraft.world.entity.EntityType.ZOMBIE, 54); - map.put(net.minecraft.world.entity.EntityType.SLIME, 55); - map.put(net.minecraft.world.entity.EntityType.GHAST, 56); - map.put(net.minecraft.world.entity.EntityType.ZOMBIFIED_PIGLIN, 57); - map.put(net.minecraft.world.entity.EntityType.ENDERMAN, 58); - map.put(net.minecraft.world.entity.EntityType.CAVE_SPIDER, 59); - map.put(net.minecraft.world.entity.EntityType.SILVERFISH, 60); - map.put(net.minecraft.world.entity.EntityType.BLAZE, 61); - map.put(net.minecraft.world.entity.EntityType.MAGMA_CUBE, 62); - map.put(net.minecraft.world.entity.EntityType.ENDER_DRAGON, 63); - map.put(net.minecraft.world.entity.EntityType.WITHER, 64); - map.put(net.minecraft.world.entity.EntityType.BAT, 65); - map.put(net.minecraft.world.entity.EntityType.WITCH, 66); - map.put(net.minecraft.world.entity.EntityType.ENDERMITE, 67); - map.put(net.minecraft.world.entity.EntityType.GUARDIAN, 68); - map.put(net.minecraft.world.entity.EntityType.SHULKER, 69); - - map.put(net.minecraft.world.entity.EntityType.PIG, 90); - map.put(net.minecraft.world.entity.EntityType.SHEEP, 91); - map.put(net.minecraft.world.entity.EntityType.COW, 92); - map.put(net.minecraft.world.entity.EntityType.CHICKEN, 93); - map.put(net.minecraft.world.entity.EntityType.SQUID, 94); - map.put(net.minecraft.world.entity.EntityType.WOLF, 95); - map.put(net.minecraft.world.entity.EntityType.MOOSHROOM, 96); - map.put(net.minecraft.world.entity.EntityType.SNOW_GOLEM, 97); - map.put(net.minecraft.world.entity.EntityType.OCELOT, 98); - map.put(net.minecraft.world.entity.EntityType.IRON_GOLEM, 99); - map.put(net.minecraft.world.entity.EntityType.HORSE, 100); - map.put(net.minecraft.world.entity.EntityType.RABBIT, 101); - map.put(net.minecraft.world.entity.EntityType.POLAR_BEAR, 102); - map.put(net.minecraft.world.entity.EntityType.LLAMA, 103); - map.put(net.minecraft.world.entity.EntityType.LLAMA_SPIT, 104); - map.put(net.minecraft.world.entity.EntityType.PARROT, 105); - - map.put(net.minecraft.world.entity.EntityType.VILLAGER, 120); - - map.put(net.minecraft.world.entity.EntityType.END_CRYSTAL, 200); - }); private static int count = 0; public CraftEntityType(final Holder> holder) { @@ -132,17 +42,6 @@ public String getName() { return this.getKey().getKey(); } - @Override - public Class getEntityClass() { - return null; - } - - @Override - @Deprecated(since = "1.6.2", forRemoval = true) - public short getTypeId() { - return (short) LEGACY_ID.getOrDefault(this.getHandle(), -1); - } - @Override public boolean isSpawnable() { return this.getHandle().canSummon(); @@ -171,7 +70,7 @@ public Attributable getDefaultAttributes() { } /** - * Implementation for the deprecated, API only, CUSTOM entity type. + * Implementation for the deprecated, API only, UNKNOWN entity type. * As per {@link #bukkitToMinecraftHolder(EntityType)} it cannot be * converted into an internal entity type and only serves backwards compatibility reasons. */ @@ -274,7 +173,7 @@ public static EntityType minecraftToBukkit(net.minecraft.world.entity.EntityT return CraftRegistry.minecraftToBukkit(minecraft, Registries.ENTITY_TYPE); } - public static net.minecraft.world.entity.@Nullable EntityType bukkitToMinecraft(EntityType bukkit) { + public static net.minecraft.world.entity.@Nullable EntityType bukkitToMinecraft(EntityType bukkit) { if (bukkit == EntityType.UNKNOWN) { return null; } @@ -310,4 +209,137 @@ public static EntityType stringToBukkit(String string) { // Now also convert from when keys where saved return CraftRegistry.get(RegistryKey.ENTITY_TYPE, key, ApiVersion.CURRENT); } + + @Override + public @Nullable Class getEntityClass() { // todo return old value for boats when api version is low + CraftEntityTypes.EntityTypeData data = CraftEntityTypes.getEntityTypeData(this); + if (data == null) { + return null; + } + return data.entityClass(); + } + + @Override + @Deprecated(since = "1.6.2", forRemoval = true) + public short getTypeId() { + return LegacyHolder.NUMERIC_IDS.getOrDefault(this, -1).shortValue(); + } + + @Deprecated // bytecode rewrites target this + public static EntityType valueOf(String name) { + if ("UNKNOWN".equals(name)) { + return EntityType.UNKNOWN; + } + + NamespacedKey key = NamespacedKey.fromString(name.toLowerCase(Locale.ROOT)); + EntityType entityType = key == null ? null : Bukkit.getUnsafe().get(RegistryKey.ENTITY_TYPE, key); + Preconditions.checkArgument(entityType != null, "No entity type found with the name %s", name); + return entityType; + } + + @Deprecated // bytecode rewrites target this + public static EntityType[] values() { + return Registry.ENTITY_TYPE.stream().toArray(EntityType[]::new); + } + + @Deprecated // bytecode rewrites target this + public static @Nullable EntityType fromId(int id) { + if (id > Short.MAX_VALUE) { + return null; + } + return LegacyHolder.NUMERIC_IDS.inverse().get(id); + } + + private static class LegacyHolder { + @Deprecated + private static final ImmutableBiMap, Integer> NUMERIC_IDS = ImmutableBiMap., Integer>builder() + .put(EntityType.ITEM, 1) + .put(EntityType.EXPERIENCE_ORB, 2) + .put(EntityType.AREA_EFFECT_CLOUD, 3) + .put(EntityType.ELDER_GUARDIAN, 4) + .put(EntityType.WITHER_SKELETON, 5) + .put(EntityType.STRAY, 6) + .put(EntityType.EGG, 7) + .put(EntityType.LEASH_KNOT, 8) + .put(EntityType.PAINTING, 9) + .put(EntityType.ARROW, 10) + .put(EntityType.SNOWBALL, 11) + .put(EntityType.FIREBALL, 12) + .put(EntityType.SMALL_FIREBALL, 13) + .put(EntityType.ENDER_PEARL, 14) + .put(EntityType.EYE_OF_ENDER, 15) + .put(EntityType.SPLASH_POTION, 16) + .put(EntityType.EXPERIENCE_BOTTLE, 17) + .put(EntityType.ITEM_FRAME, 18) + .put(EntityType.WITHER_SKULL, 19) + .put(EntityType.TNT, 20) + .put(EntityType.FALLING_BLOCK, 21) + .put(EntityType.FIREWORK_ROCKET, 22) + .put(EntityType.HUSK, 23) + .put(EntityType.SPECTRAL_ARROW, 24) + .put(EntityType.SHULKER_BULLET, 25) + .put(EntityType.DRAGON_FIREBALL, 26) + .put(EntityType.ZOMBIE_VILLAGER, 27) + .put(EntityType.SKELETON_HORSE, 28) + .put(EntityType.ZOMBIE_HORSE, 29) + .put(EntityType.ARMOR_STAND, 30) + .put(EntityType.DONKEY, 31) + .put(EntityType.MULE, 32) + .put(EntityType.EVOKER_FANGS, 33) + .put(EntityType.EVOKER, 34) + .put(EntityType.VEX, 35) + .put(EntityType.VINDICATOR, 36) + .put(EntityType.ILLUSIONER, 37) + + .put(EntityType.COMMAND_BLOCK_MINECART, 40) + .put(EntityType.MINECART, 42) + .put(EntityType.CHEST_MINECART, 43) + .put(EntityType.FURNACE_MINECART, 44) + .put(EntityType.TNT_MINECART, 45) + .put(EntityType.HOPPER_MINECART, 46) + .put(EntityType.SPAWNER_MINECART, 47) + + .put(EntityType.CREEPER, 50) + .put(EntityType.SKELETON, 51) + .put(EntityType.SPIDER, 52) + .put(EntityType.GIANT, 53) + .put(EntityType.ZOMBIE, 54) + .put(EntityType.SLIME, 55) + .put(EntityType.GHAST, 56) + .put(EntityType.ZOMBIFIED_PIGLIN, 57) + .put(EntityType.ENDERMAN, 58) + .put(EntityType.CAVE_SPIDER, 59) + .put(EntityType.SILVERFISH, 60) + .put(EntityType.BLAZE, 61) + .put(EntityType.MAGMA_CUBE, 62) + .put(EntityType.ENDER_DRAGON, 63) + .put(EntityType.WITHER, 64) + .put(EntityType.BAT, 65) + .put(EntityType.WITCH, 66) + .put(EntityType.ENDERMITE, 67) + .put(EntityType.GUARDIAN, 68) + .put(EntityType.SHULKER, 69) + + .put(EntityType.PIG, 90) + .put(EntityType.SHEEP, 91) + .put(EntityType.COW, 92) + .put(EntityType.CHICKEN, 93) + .put(EntityType.SQUID, 94) + .put(EntityType.WOLF, 95) + .put(EntityType.MOOSHROOM, 96) + .put(EntityType.SNOW_GOLEM, 97) + .put(EntityType.OCELOT, 98) + .put(EntityType.IRON_GOLEM, 99) + .put(EntityType.HORSE, 100) + .put(EntityType.RABBIT, 101) + .put(EntityType.POLAR_BEAR, 102) + .put(EntityType.LLAMA, 103) + .put(EntityType.LLAMA_SPIT, 104) + .put(EntityType.PARROT, 105) + + .put(EntityType.VILLAGER, 120) + + .put(EntityType.END_CRYSTAL, 200) + .buildOrThrow(); + } } diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftEntityTypes.java b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftEntityTypes.java index db1a81d06613..5507fff510a7 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftEntityTypes.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftEntityTypes.java @@ -16,9 +16,9 @@ import net.minecraft.world.entity.item.FallingBlockEntity; import net.minecraft.world.entity.item.ItemEntity; import net.minecraft.world.entity.item.PrimedTnt; -import net.minecraft.world.entity.projectile.hurtingprojectile.AbstractHurtingProjectile; import net.minecraft.world.entity.projectile.EyeOfEnder; import net.minecraft.world.entity.projectile.FireworkRocketEntity; +import net.minecraft.world.entity.projectile.hurtingprojectile.AbstractHurtingProjectile; import net.minecraft.world.entity.projectile.throwableitemprojectile.ThrownEgg; import net.minecraft.world.entity.projectile.throwableitemprojectile.ThrownLingeringPotion; import net.minecraft.world.entity.projectile.throwableitemprojectile.ThrownSplashPotion; @@ -36,26 +36,6 @@ import org.bukkit.block.BlockFace; import org.bukkit.craftbukkit.CraftServer; import org.bukkit.craftbukkit.block.CraftBlock; -import org.bukkit.craftbukkit.entity.boat.CraftAcaciaBoat; -import org.bukkit.craftbukkit.entity.boat.CraftAcaciaChestBoat; -import org.bukkit.craftbukkit.entity.boat.CraftBambooChestRaft; -import org.bukkit.craftbukkit.entity.boat.CraftBambooRaft; -import org.bukkit.craftbukkit.entity.boat.CraftBirchBoat; -import org.bukkit.craftbukkit.entity.boat.CraftBirchChestBoat; -import org.bukkit.craftbukkit.entity.boat.CraftCherryBoat; -import org.bukkit.craftbukkit.entity.boat.CraftCherryChestBoat; -import org.bukkit.craftbukkit.entity.boat.CraftDarkOakBoat; -import org.bukkit.craftbukkit.entity.boat.CraftDarkOakChestBoat; -import org.bukkit.craftbukkit.entity.boat.CraftJungleBoat; -import org.bukkit.craftbukkit.entity.boat.CraftJungleChestBoat; -import org.bukkit.craftbukkit.entity.boat.CraftMangroveBoat; -import org.bukkit.craftbukkit.entity.boat.CraftMangroveChestBoat; -import org.bukkit.craftbukkit.entity.boat.CraftOakBoat; -import org.bukkit.craftbukkit.entity.boat.CraftOakChestBoat; -import org.bukkit.craftbukkit.entity.boat.CraftPaleOakBoat; -import org.bukkit.craftbukkit.entity.boat.CraftPaleOakChestBoat; -import org.bukkit.craftbukkit.entity.boat.CraftSpruceBoat; -import org.bukkit.craftbukkit.entity.boat.CraftSpruceChestBoat; import org.bukkit.entity.Allay; import org.bukkit.entity.AreaEffectCloud; import org.bukkit.entity.Armadillo; @@ -66,6 +46,7 @@ import org.bukkit.entity.Bee; import org.bukkit.entity.Blaze; import org.bukkit.entity.BlockDisplay; +import org.bukkit.entity.Boat; import org.bukkit.entity.Bogged; import org.bukkit.entity.Breeze; import org.bukkit.entity.BreezeWindCharge; @@ -73,6 +54,7 @@ import org.bukkit.entity.CamelHusk; import org.bukkit.entity.Cat; import org.bukkit.entity.CaveSpider; +import org.bukkit.entity.ChestBoat; import org.bukkit.entity.Chicken; import org.bukkit.entity.Cod; import org.bukkit.entity.CopperGolem; @@ -189,26 +171,6 @@ import org.bukkit.entity.ZombieHorse; import org.bukkit.entity.ZombieNautilus; import org.bukkit.entity.ZombieVillager; -import org.bukkit.entity.boat.AcaciaBoat; -import org.bukkit.entity.boat.AcaciaChestBoat; -import org.bukkit.entity.boat.BambooChestRaft; -import org.bukkit.entity.boat.BambooRaft; -import org.bukkit.entity.boat.BirchBoat; -import org.bukkit.entity.boat.BirchChestBoat; -import org.bukkit.entity.boat.CherryBoat; -import org.bukkit.entity.boat.CherryChestBoat; -import org.bukkit.entity.boat.DarkOakBoat; -import org.bukkit.entity.boat.DarkOakChestBoat; -import org.bukkit.entity.boat.JungleBoat; -import org.bukkit.entity.boat.JungleChestBoat; -import org.bukkit.entity.boat.MangroveBoat; -import org.bukkit.entity.boat.MangroveChestBoat; -import org.bukkit.entity.boat.OakBoat; -import org.bukkit.entity.boat.OakChestBoat; -import org.bukkit.entity.boat.PaleOakBoat; -import org.bukkit.entity.boat.PaleOakChestBoat; -import org.bukkit.entity.boat.SpruceBoat; -import org.bukkit.entity.boat.SpruceChestBoat; import org.bukkit.entity.minecart.CommandMinecart; import org.bukkit.entity.minecart.ExplosiveMinecart; import org.bukkit.entity.minecart.HopperMinecart; @@ -415,26 +377,26 @@ Level minecraftWorld() { register(new EntityTypeData<>(EntityType.LLAMA_SPIT, LlamaSpit.class, CraftLlamaSpit::new, createAndMove(net.minecraft.world.entity.EntityType.LLAMA_SPIT))); register(new EntityTypeData<>(EntityType.OMINOUS_ITEM_SPAWNER, OminousItemSpawner.class, CraftOminousItemSpawner::new, createAndMove(net.minecraft.world.entity.EntityType.OMINOUS_ITEM_SPAWNER))); // Move (boats) - register(new EntityTypeData<>(EntityType.ACACIA_BOAT, AcaciaBoat.class, CraftAcaciaBoat::new, createAndMove(net.minecraft.world.entity.EntityType.ACACIA_BOAT))); - register(new EntityTypeData<>(EntityType.ACACIA_CHEST_BOAT, AcaciaChestBoat.class, CraftAcaciaChestBoat::new, createAndMove(net.minecraft.world.entity.EntityType.ACACIA_CHEST_BOAT))); - register(new EntityTypeData<>(EntityType.BAMBOO_RAFT, BambooRaft.class, CraftBambooRaft::new, createAndMove(net.minecraft.world.entity.EntityType.BAMBOO_RAFT))); - register(new EntityTypeData<>(EntityType.BAMBOO_CHEST_RAFT, BambooChestRaft.class, CraftBambooChestRaft::new, createAndMove(net.minecraft.world.entity.EntityType.BAMBOO_CHEST_RAFT))); - register(new EntityTypeData<>(EntityType.BIRCH_BOAT, BirchBoat.class, CraftBirchBoat::new, createAndMove(net.minecraft.world.entity.EntityType.BIRCH_BOAT))); - register(new EntityTypeData<>(EntityType.BIRCH_CHEST_BOAT, BirchChestBoat.class, CraftBirchChestBoat::new, createAndMove(net.minecraft.world.entity.EntityType.BIRCH_CHEST_BOAT))); - register(new EntityTypeData<>(EntityType.CHERRY_BOAT, CherryBoat.class, CraftCherryBoat::new, createAndMove(net.minecraft.world.entity.EntityType.CHERRY_BOAT))); - register(new EntityTypeData<>(EntityType.CHERRY_CHEST_BOAT, CherryChestBoat.class, CraftCherryChestBoat::new, createAndMove(net.minecraft.world.entity.EntityType.CHERRY_CHEST_BOAT))); - register(new EntityTypeData<>(EntityType.DARK_OAK_BOAT, DarkOakBoat.class, CraftDarkOakBoat::new, createAndMove(net.minecraft.world.entity.EntityType.DARK_OAK_BOAT))); - register(new EntityTypeData<>(EntityType.DARK_OAK_CHEST_BOAT, DarkOakChestBoat.class, CraftDarkOakChestBoat::new, createAndMove(net.minecraft.world.entity.EntityType.DARK_OAK_CHEST_BOAT))); - register(new EntityTypeData<>(EntityType.JUNGLE_BOAT, JungleBoat.class, CraftJungleBoat::new, createAndMove(net.minecraft.world.entity.EntityType.JUNGLE_BOAT))); - register(new EntityTypeData<>(EntityType.JUNGLE_CHEST_BOAT, JungleChestBoat.class, CraftJungleChestBoat::new, createAndMove(net.minecraft.world.entity.EntityType.JUNGLE_CHEST_BOAT))); - register(new EntityTypeData<>(EntityType.MANGROVE_BOAT, MangroveBoat.class, CraftMangroveBoat::new, createAndMove(net.minecraft.world.entity.EntityType.MANGROVE_BOAT))); - register(new EntityTypeData<>(EntityType.MANGROVE_CHEST_BOAT, MangroveChestBoat.class, CraftMangroveChestBoat::new, createAndMove(net.minecraft.world.entity.EntityType.MANGROVE_CHEST_BOAT))); - register(new EntityTypeData<>(EntityType.OAK_BOAT, OakBoat.class, CraftOakBoat::new, createAndMove(net.minecraft.world.entity.EntityType.OAK_BOAT))); - register(new EntityTypeData<>(EntityType.OAK_CHEST_BOAT, OakChestBoat.class, CraftOakChestBoat::new, createAndMove(net.minecraft.world.entity.EntityType.OAK_CHEST_BOAT))); - register(new EntityTypeData<>(EntityType.PALE_OAK_BOAT, PaleOakBoat.class, CraftPaleOakBoat::new, createAndMove(net.minecraft.world.entity.EntityType.PALE_OAK_BOAT))); - register(new EntityTypeData<>(EntityType.PALE_OAK_CHEST_BOAT, PaleOakChestBoat.class, CraftPaleOakChestBoat::new, createAndMove(net.minecraft.world.entity.EntityType.PALE_OAK_CHEST_BOAT))); - register(new EntityTypeData<>(EntityType.SPRUCE_BOAT, SpruceBoat.class, CraftSpruceBoat::new, createAndMove(net.minecraft.world.entity.EntityType.SPRUCE_BOAT))); - register(new EntityTypeData<>(EntityType.SPRUCE_CHEST_BOAT, SpruceChestBoat.class, CraftSpruceChestBoat::new, createAndMove(net.minecraft.world.entity.EntityType.SPRUCE_CHEST_BOAT))); + register(new EntityTypeData<>(EntityType.ACACIA_BOAT, Boat.class, CraftBoat::new, createAndMove(net.minecraft.world.entity.EntityType.ACACIA_BOAT))); + register(new EntityTypeData<>(EntityType.ACACIA_CHEST_BOAT, ChestBoat.class, CraftChestBoat::new, createAndMove(net.minecraft.world.entity.EntityType.ACACIA_CHEST_BOAT))); + register(new EntityTypeData<>(EntityType.BAMBOO_RAFT, Boat.class, CraftBoat::new, createAndMove(net.minecraft.world.entity.EntityType.BAMBOO_RAFT))); + register(new EntityTypeData<>(EntityType.BAMBOO_CHEST_RAFT, ChestBoat.class, CraftChestBoat::new, createAndMove(net.minecraft.world.entity.EntityType.BAMBOO_CHEST_RAFT))); + register(new EntityTypeData<>(EntityType.BIRCH_BOAT, Boat.class, CraftBoat::new, createAndMove(net.minecraft.world.entity.EntityType.BIRCH_BOAT))); + register(new EntityTypeData<>(EntityType.BIRCH_CHEST_BOAT, ChestBoat.class, CraftChestBoat::new, createAndMove(net.minecraft.world.entity.EntityType.BIRCH_CHEST_BOAT))); + register(new EntityTypeData<>(EntityType.CHERRY_BOAT, Boat.class, CraftBoat::new, createAndMove(net.minecraft.world.entity.EntityType.CHERRY_BOAT))); + register(new EntityTypeData<>(EntityType.CHERRY_CHEST_BOAT, ChestBoat.class, CraftChestBoat::new, createAndMove(net.minecraft.world.entity.EntityType.CHERRY_CHEST_BOAT))); + register(new EntityTypeData<>(EntityType.DARK_OAK_BOAT, Boat.class, CraftBoat::new, createAndMove(net.minecraft.world.entity.EntityType.DARK_OAK_BOAT))); + register(new EntityTypeData<>(EntityType.DARK_OAK_CHEST_BOAT, ChestBoat.class, CraftChestBoat::new, createAndMove(net.minecraft.world.entity.EntityType.DARK_OAK_CHEST_BOAT))); + register(new EntityTypeData<>(EntityType.JUNGLE_BOAT, Boat.class, CraftBoat::new, createAndMove(net.minecraft.world.entity.EntityType.JUNGLE_BOAT))); + register(new EntityTypeData<>(EntityType.JUNGLE_CHEST_BOAT, ChestBoat.class, CraftChestBoat::new, createAndMove(net.minecraft.world.entity.EntityType.JUNGLE_CHEST_BOAT))); + register(new EntityTypeData<>(EntityType.MANGROVE_BOAT, Boat.class, CraftBoat::new, createAndMove(net.minecraft.world.entity.EntityType.MANGROVE_BOAT))); + register(new EntityTypeData<>(EntityType.MANGROVE_CHEST_BOAT, ChestBoat.class, CraftChestBoat::new, createAndMove(net.minecraft.world.entity.EntityType.MANGROVE_CHEST_BOAT))); + register(new EntityTypeData<>(EntityType.OAK_BOAT, Boat.class, CraftBoat::new, createAndMove(net.minecraft.world.entity.EntityType.OAK_BOAT))); + register(new EntityTypeData<>(EntityType.OAK_CHEST_BOAT, ChestBoat.class, CraftChestBoat::new, createAndMove(net.minecraft.world.entity.EntityType.OAK_CHEST_BOAT))); + register(new EntityTypeData<>(EntityType.PALE_OAK_BOAT, Boat.class, CraftBoat::new, createAndMove(net.minecraft.world.entity.EntityType.PALE_OAK_BOAT))); + register(new EntityTypeData<>(EntityType.PALE_OAK_CHEST_BOAT, ChestBoat.class, CraftChestBoat::new, createAndMove(net.minecraft.world.entity.EntityType.PALE_OAK_CHEST_BOAT))); + register(new EntityTypeData<>(EntityType.SPRUCE_BOAT, Boat.class, CraftBoat::new, createAndMove(net.minecraft.world.entity.EntityType.SPRUCE_BOAT))); + register(new EntityTypeData<>(EntityType.SPRUCE_CHEST_BOAT, ChestBoat.class, CraftChestBoat::new, createAndMove(net.minecraft.world.entity.EntityType.SPRUCE_CHEST_BOAT))); // Set pos register(new EntityTypeData<>(EntityType.MARKER, Marker.class, CraftMarker::new, createAndSetPos(net.minecraft.world.entity.EntityType.MARKER))); @@ -496,12 +458,7 @@ Level minecraftWorld() { } private static void register(EntityTypeData typeData) { - EntityTypeData other = CraftEntityTypes.CLASS_TYPE_DATA.put(typeData.entityClass(), typeData); - if (other != null) { - Bukkit.getLogger().warning(String.format("Found multiple entity type data for class %s, replacing '%s' with new value '%s'", typeData.entityClass().getName(), other, typeData)); - } - - other = CraftEntityTypes.ENTITY_TYPE_DATA.put(typeData.entityType(), typeData); + EntityTypeData other = CraftEntityTypes.ENTITY_TYPE_DATA.put(typeData.entityType(), typeData); if (other != null) { Bukkit.getLogger().warning(String.format("Found multiple entity type data for entity type %s, replacing '%s' with new value '%s'", typeData.entityType().getKey(), other, typeData)); } @@ -603,10 +560,11 @@ private static Function combine(Function before, BiConsumer EntityTypeData getEntityTypeData(EntityType entityType) { + public static EntityTypeData getEntityTypeData(EntityType entityType) { return (EntityTypeData) CraftEntityTypes.ENTITY_TYPE_DATA.get(entityType); } + @Deprecated public static EntityTypeData getEntityTypeData(Class entityClass) { return (EntityTypeData) CraftEntityTypes.CLASS_TYPE_DATA.get(entityClass); } diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/boat/CraftAcaciaBoat.java b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/boat/CraftAcaciaBoat.java deleted file mode 100644 index 5ffa0cb44a69..000000000000 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/boat/CraftAcaciaBoat.java +++ /dev/null @@ -1,13 +0,0 @@ -package org.bukkit.craftbukkit.entity.boat; - -import net.minecraft.world.entity.vehicle.boat.AbstractBoat; -import org.bukkit.craftbukkit.CraftServer; -import org.bukkit.craftbukkit.entity.CraftBoat; -import org.bukkit.entity.boat.AcaciaBoat; - -public class CraftAcaciaBoat extends CraftBoat implements AcaciaBoat { - - public CraftAcaciaBoat(CraftServer server, AbstractBoat entity) { - super(server, entity); - } -} diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/boat/CraftAcaciaChestBoat.java b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/boat/CraftAcaciaChestBoat.java deleted file mode 100644 index 0eb78998950e..000000000000 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/boat/CraftAcaciaChestBoat.java +++ /dev/null @@ -1,13 +0,0 @@ -package org.bukkit.craftbukkit.entity.boat; - -import net.minecraft.world.entity.vehicle.boat.AbstractChestBoat; -import org.bukkit.craftbukkit.CraftServer; -import org.bukkit.craftbukkit.entity.CraftChestBoat; -import org.bukkit.entity.boat.AcaciaChestBoat; - -public class CraftAcaciaChestBoat extends CraftChestBoat implements AcaciaChestBoat { - - public CraftAcaciaChestBoat(CraftServer server, AbstractChestBoat entity) { - super(server, entity); - } -} diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/boat/CraftBambooChestRaft.java b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/boat/CraftBambooChestRaft.java deleted file mode 100644 index 20a32fb30e03..000000000000 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/boat/CraftBambooChestRaft.java +++ /dev/null @@ -1,13 +0,0 @@ -package org.bukkit.craftbukkit.entity.boat; - -import net.minecraft.world.entity.vehicle.boat.AbstractChestBoat; -import org.bukkit.craftbukkit.CraftServer; -import org.bukkit.craftbukkit.entity.CraftChestBoat; -import org.bukkit.entity.boat.BambooChestRaft; - -public class CraftBambooChestRaft extends CraftChestBoat implements BambooChestRaft { - - public CraftBambooChestRaft(CraftServer server, AbstractChestBoat entity) { - super(server, entity); - } -} diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/boat/CraftBambooRaft.java b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/boat/CraftBambooRaft.java deleted file mode 100644 index de041ab79e85..000000000000 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/boat/CraftBambooRaft.java +++ /dev/null @@ -1,13 +0,0 @@ -package org.bukkit.craftbukkit.entity.boat; - -import net.minecraft.world.entity.vehicle.boat.AbstractBoat; -import org.bukkit.craftbukkit.CraftServer; -import org.bukkit.craftbukkit.entity.CraftBoat; -import org.bukkit.entity.boat.BambooRaft; - -public class CraftBambooRaft extends CraftBoat implements BambooRaft { - - public CraftBambooRaft(CraftServer server, AbstractBoat entity) { - super(server, entity); - } -} diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/boat/CraftBirchBoat.java b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/boat/CraftBirchBoat.java deleted file mode 100644 index 6d71b6d16ada..000000000000 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/boat/CraftBirchBoat.java +++ /dev/null @@ -1,13 +0,0 @@ -package org.bukkit.craftbukkit.entity.boat; - -import net.minecraft.world.entity.vehicle.boat.AbstractBoat; -import org.bukkit.craftbukkit.CraftServer; -import org.bukkit.craftbukkit.entity.CraftBoat; -import org.bukkit.entity.boat.BirchBoat; - -public class CraftBirchBoat extends CraftBoat implements BirchBoat { - - public CraftBirchBoat(CraftServer server, AbstractBoat entity) { - super(server, entity); - } -} diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/boat/CraftBirchChestBoat.java b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/boat/CraftBirchChestBoat.java deleted file mode 100644 index 91221cae40de..000000000000 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/boat/CraftBirchChestBoat.java +++ /dev/null @@ -1,13 +0,0 @@ -package org.bukkit.craftbukkit.entity.boat; - -import net.minecraft.world.entity.vehicle.boat.AbstractChestBoat; -import org.bukkit.craftbukkit.CraftServer; -import org.bukkit.craftbukkit.entity.CraftChestBoat; -import org.bukkit.entity.boat.BirchChestBoat; - -public class CraftBirchChestBoat extends CraftChestBoat implements BirchChestBoat { - - public CraftBirchChestBoat(CraftServer server, AbstractChestBoat entity) { - super(server, entity); - } -} diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/boat/CraftCherryBoat.java b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/boat/CraftCherryBoat.java deleted file mode 100644 index 08989c870d0c..000000000000 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/boat/CraftCherryBoat.java +++ /dev/null @@ -1,13 +0,0 @@ -package org.bukkit.craftbukkit.entity.boat; - -import net.minecraft.world.entity.vehicle.boat.AbstractBoat; -import org.bukkit.craftbukkit.CraftServer; -import org.bukkit.craftbukkit.entity.CraftBoat; -import org.bukkit.entity.boat.CherryBoat; - -public class CraftCherryBoat extends CraftBoat implements CherryBoat { - - public CraftCherryBoat(CraftServer server, AbstractBoat entity) { - super(server, entity); - } -} diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/boat/CraftCherryChestBoat.java b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/boat/CraftCherryChestBoat.java deleted file mode 100644 index a4fe6736abda..000000000000 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/boat/CraftCherryChestBoat.java +++ /dev/null @@ -1,13 +0,0 @@ -package org.bukkit.craftbukkit.entity.boat; - -import net.minecraft.world.entity.vehicle.boat.AbstractChestBoat; -import org.bukkit.craftbukkit.CraftServer; -import org.bukkit.craftbukkit.entity.CraftChestBoat; -import org.bukkit.entity.boat.CherryChestBoat; - -public class CraftCherryChestBoat extends CraftChestBoat implements CherryChestBoat { - - public CraftCherryChestBoat(CraftServer server, AbstractChestBoat entity) { - super(server, entity); - } -} diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/boat/CraftDarkOakBoat.java b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/boat/CraftDarkOakBoat.java deleted file mode 100644 index fad036eb8454..000000000000 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/boat/CraftDarkOakBoat.java +++ /dev/null @@ -1,13 +0,0 @@ -package org.bukkit.craftbukkit.entity.boat; - -import net.minecraft.world.entity.vehicle.boat.AbstractBoat; -import org.bukkit.craftbukkit.CraftServer; -import org.bukkit.craftbukkit.entity.CraftBoat; -import org.bukkit.entity.boat.DarkOakBoat; - -public class CraftDarkOakBoat extends CraftBoat implements DarkOakBoat { - - public CraftDarkOakBoat(CraftServer server, AbstractBoat entity) { - super(server, entity); - } -} diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/boat/CraftDarkOakChestBoat.java b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/boat/CraftDarkOakChestBoat.java deleted file mode 100644 index 14e7e6fce308..000000000000 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/boat/CraftDarkOakChestBoat.java +++ /dev/null @@ -1,13 +0,0 @@ -package org.bukkit.craftbukkit.entity.boat; - -import net.minecraft.world.entity.vehicle.boat.AbstractChestBoat; -import org.bukkit.craftbukkit.CraftServer; -import org.bukkit.craftbukkit.entity.CraftChestBoat; -import org.bukkit.entity.boat.DarkOakChestBoat; - -public class CraftDarkOakChestBoat extends CraftChestBoat implements DarkOakChestBoat { - - public CraftDarkOakChestBoat(CraftServer server, AbstractChestBoat entity) { - super(server, entity); - } -} diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/boat/CraftJungleBoat.java b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/boat/CraftJungleBoat.java deleted file mode 100644 index 0fd049f60206..000000000000 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/boat/CraftJungleBoat.java +++ /dev/null @@ -1,13 +0,0 @@ -package org.bukkit.craftbukkit.entity.boat; - -import net.minecraft.world.entity.vehicle.boat.AbstractBoat; -import org.bukkit.craftbukkit.CraftServer; -import org.bukkit.craftbukkit.entity.CraftBoat; -import org.bukkit.entity.boat.JungleBoat; - -public class CraftJungleBoat extends CraftBoat implements JungleBoat { - - public CraftJungleBoat(CraftServer server, AbstractBoat entity) { - super(server, entity); - } -} diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/boat/CraftJungleChestBoat.java b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/boat/CraftJungleChestBoat.java deleted file mode 100644 index 86e106945235..000000000000 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/boat/CraftJungleChestBoat.java +++ /dev/null @@ -1,13 +0,0 @@ -package org.bukkit.craftbukkit.entity.boat; - -import net.minecraft.world.entity.vehicle.boat.AbstractChestBoat; -import org.bukkit.craftbukkit.CraftServer; -import org.bukkit.craftbukkit.entity.CraftChestBoat; -import org.bukkit.entity.boat.JungleChestBoat; - -public class CraftJungleChestBoat extends CraftChestBoat implements JungleChestBoat { - - public CraftJungleChestBoat(CraftServer server, AbstractChestBoat entity) { - super(server, entity); - } -} diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/boat/CraftMangroveBoat.java b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/boat/CraftMangroveBoat.java deleted file mode 100644 index ca184c73053b..000000000000 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/boat/CraftMangroveBoat.java +++ /dev/null @@ -1,13 +0,0 @@ -package org.bukkit.craftbukkit.entity.boat; - -import net.minecraft.world.entity.vehicle.boat.AbstractBoat; -import org.bukkit.craftbukkit.CraftServer; -import org.bukkit.craftbukkit.entity.CraftBoat; -import org.bukkit.entity.boat.MangroveBoat; - -public class CraftMangroveBoat extends CraftBoat implements MangroveBoat { - - public CraftMangroveBoat(CraftServer server, AbstractBoat entity) { - super(server, entity); - } -} diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/boat/CraftMangroveChestBoat.java b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/boat/CraftMangroveChestBoat.java deleted file mode 100644 index 95978027fe8c..000000000000 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/boat/CraftMangroveChestBoat.java +++ /dev/null @@ -1,13 +0,0 @@ -package org.bukkit.craftbukkit.entity.boat; - -import net.minecraft.world.entity.vehicle.boat.AbstractChestBoat; -import org.bukkit.craftbukkit.CraftServer; -import org.bukkit.craftbukkit.entity.CraftChestBoat; -import org.bukkit.entity.boat.MangroveChestBoat; - -public class CraftMangroveChestBoat extends CraftChestBoat implements MangroveChestBoat { - - public CraftMangroveChestBoat(CraftServer server, AbstractChestBoat entity) { - super(server, entity); - } -} diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/boat/CraftOakBoat.java b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/boat/CraftOakBoat.java deleted file mode 100644 index 98fb6c02c7bd..000000000000 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/boat/CraftOakBoat.java +++ /dev/null @@ -1,13 +0,0 @@ -package org.bukkit.craftbukkit.entity.boat; - -import net.minecraft.world.entity.vehicle.boat.AbstractBoat; -import org.bukkit.craftbukkit.CraftServer; -import org.bukkit.craftbukkit.entity.CraftBoat; -import org.bukkit.entity.boat.OakBoat; - -public class CraftOakBoat extends CraftBoat implements OakBoat { - - public CraftOakBoat(CraftServer server, AbstractBoat entity) { - super(server, entity); - } -} diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/boat/CraftOakChestBoat.java b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/boat/CraftOakChestBoat.java deleted file mode 100644 index b7d78ee954ef..000000000000 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/boat/CraftOakChestBoat.java +++ /dev/null @@ -1,13 +0,0 @@ -package org.bukkit.craftbukkit.entity.boat; - -import net.minecraft.world.entity.vehicle.boat.AbstractChestBoat; -import org.bukkit.craftbukkit.CraftServer; -import org.bukkit.craftbukkit.entity.CraftChestBoat; -import org.bukkit.entity.boat.OakChestBoat; - -public class CraftOakChestBoat extends CraftChestBoat implements OakChestBoat { - - public CraftOakChestBoat(CraftServer server, AbstractChestBoat entity) { - super(server, entity); - } -} diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/boat/CraftPaleOakBoat.java b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/boat/CraftPaleOakBoat.java deleted file mode 100644 index 88f82dd5d822..000000000000 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/boat/CraftPaleOakBoat.java +++ /dev/null @@ -1,13 +0,0 @@ -package org.bukkit.craftbukkit.entity.boat; - -import net.minecraft.world.entity.vehicle.boat.AbstractBoat; -import org.bukkit.craftbukkit.CraftServer; -import org.bukkit.craftbukkit.entity.CraftBoat; -import org.bukkit.entity.boat.PaleOakBoat; - -public class CraftPaleOakBoat extends CraftBoat implements PaleOakBoat { - - public CraftPaleOakBoat(CraftServer server, AbstractBoat entity) { - super(server, entity); - } -} diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/boat/CraftPaleOakChestBoat.java b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/boat/CraftPaleOakChestBoat.java deleted file mode 100644 index eef9cada0367..000000000000 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/boat/CraftPaleOakChestBoat.java +++ /dev/null @@ -1,13 +0,0 @@ -package org.bukkit.craftbukkit.entity.boat; - -import net.minecraft.world.entity.vehicle.boat.AbstractChestBoat; -import org.bukkit.craftbukkit.CraftServer; -import org.bukkit.craftbukkit.entity.CraftChestBoat; -import org.bukkit.entity.boat.PaleOakChestBoat; - -public class CraftPaleOakChestBoat extends CraftChestBoat implements PaleOakChestBoat { - - public CraftPaleOakChestBoat(CraftServer server, AbstractChestBoat entity) { - super(server, entity); - } -} diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/boat/CraftSpruceBoat.java b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/boat/CraftSpruceBoat.java deleted file mode 100644 index 8cff0a245483..000000000000 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/boat/CraftSpruceBoat.java +++ /dev/null @@ -1,13 +0,0 @@ -package org.bukkit.craftbukkit.entity.boat; - -import net.minecraft.world.entity.vehicle.boat.AbstractBoat; -import org.bukkit.craftbukkit.CraftServer; -import org.bukkit.craftbukkit.entity.CraftBoat; -import org.bukkit.entity.boat.SpruceBoat; - -public class CraftSpruceBoat extends CraftBoat implements SpruceBoat { - - public CraftSpruceBoat(CraftServer server, AbstractBoat entity) { - super(server, entity); - } -} diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/boat/CraftSpruceChestBoat.java b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/boat/CraftSpruceChestBoat.java deleted file mode 100644 index a01ac047c83c..000000000000 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/boat/CraftSpruceChestBoat.java +++ /dev/null @@ -1,13 +0,0 @@ -package org.bukkit.craftbukkit.entity.boat; - -import net.minecraft.world.entity.vehicle.boat.AbstractChestBoat; -import org.bukkit.craftbukkit.CraftServer; -import org.bukkit.craftbukkit.entity.CraftChestBoat; -import org.bukkit.entity.boat.SpruceChestBoat; - -public class CraftSpruceChestBoat extends CraftChestBoat implements SpruceChestBoat { - - public CraftSpruceChestBoat(CraftServer server, AbstractChestBoat entity) { - super(server, entity); - } -} diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/legacy/FieldRename.java b/paper-server/src/main/java/org/bukkit/craftbukkit/legacy/FieldRename.java index 42dfc8f15ae1..1e480c16f9c5 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/legacy/FieldRename.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/legacy/FieldRename.java @@ -7,6 +7,7 @@ import org.bukkit.attribute.Attribute; import org.bukkit.block.Biome; import org.bukkit.block.banner.PatternType; +import org.bukkit.craftbukkit.entity.CraftEntityType; import org.bukkit.craftbukkit.legacy.fieldrename.FieldRenameData; import org.bukkit.craftbukkit.legacy.reroute.DoNotReroute; import org.bukkit.craftbukkit.legacy.reroute.InjectPluginVersion; @@ -216,7 +217,7 @@ public static String convertEntityTypeName(ApiVersion version, String from) { @RerouteStatic("org/bukkit/entity/EntityType") public static EntityType valueOf_EntityType(String name) { // We don't have version-specific changes, so just use current, and don't inject a version - return EntityType.valueOf(FieldRename.convertEntityTypeName(ApiVersion.CURRENT, name)); + return CraftEntityType.valueOf(FieldRename.convertEntityTypeName(ApiVersion.CURRENT, name)); } @RerouteMethodName("fromName") diff --git a/paper-server/src/test/java/org/bukkit/craftbukkit/entity/EntityTypesTest.java b/paper-server/src/test/java/org/bukkit/craftbukkit/entity/EntityTypesTest.java index cc6e115038ed..816f6154d169 100644 --- a/paper-server/src/test/java/org/bukkit/craftbukkit/entity/EntityTypesTest.java +++ b/paper-server/src/test/java/org/bukkit/craftbukkit/entity/EntityTypesTest.java @@ -1,200 +1,25 @@ package org.bukkit.craftbukkit.entity; -import static org.junit.jupiter.api.Assertions.*; -import java.io.File; -import java.io.IOException; -import java.net.URI; -import java.net.URISyntaxException; -import java.util.Arrays; -import java.util.List; -import java.util.jar.JarFile; import java.util.stream.Stream; -import java.util.zip.ZipEntry; import org.bukkit.Registry; -import org.bukkit.entity.AbstractArrow; -import org.bukkit.entity.AbstractCow; -import org.bukkit.entity.AbstractHorse; -import org.bukkit.entity.AbstractNautilus; -import org.bukkit.entity.AbstractSkeleton; -import org.bukkit.entity.AbstractVillager; -import org.bukkit.entity.AbstractWindCharge; -import org.bukkit.entity.Ageable; -import org.bukkit.entity.Ambient; -import org.bukkit.entity.Animals; -import org.bukkit.entity.Boat; -import org.bukkit.entity.Boss; -import org.bukkit.entity.Breedable; -import org.bukkit.entity.ChestBoat; -import org.bukkit.entity.ChestedHorse; -import org.bukkit.entity.ComplexEntityPart; -import org.bukkit.entity.ComplexLivingEntity; -import org.bukkit.entity.Creature; -import org.bukkit.entity.Damageable; -import org.bukkit.entity.Display; -import org.bukkit.entity.EnderDragonPart; -import org.bukkit.entity.Enemy; -import org.bukkit.entity.Entity; import org.bukkit.entity.EntityType; -import org.bukkit.entity.Explosive; -import org.bukkit.entity.Fireball; -import org.bukkit.entity.Fish; -import org.bukkit.entity.Flying; -import org.bukkit.entity.Golem; -import org.bukkit.entity.Hanging; -import org.bukkit.entity.HumanEntity; -import org.bukkit.entity.Illager; -import org.bukkit.entity.LingeringPotion; -import org.bukkit.entity.LivingEntity; -import org.bukkit.entity.Minecart; -import org.bukkit.entity.Mob; -import org.bukkit.entity.Monster; -import org.bukkit.entity.NPC; -import org.bukkit.entity.PiglinAbstract; -import org.bukkit.entity.Projectile; -import org.bukkit.entity.Raider; -import org.bukkit.entity.Sittable; -import org.bukkit.entity.SizedFireball; -import org.bukkit.entity.Spellcaster; -import org.bukkit.entity.SplashPotion; -import org.bukkit.entity.Steerable; -import org.bukkit.entity.Tameable; -import org.bukkit.entity.ThrowableProjectile; -import org.bukkit.entity.ThrownPotion; -import org.bukkit.entity.TippedArrow; -import org.bukkit.entity.Vehicle; -import org.bukkit.entity.WaterMob; -import org.bukkit.support.environment.AllFeatures; -import org.bukkit.support.test.RegistriesTest; -import org.junit.jupiter.api.AfterAll; -import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.Test; +import org.bukkit.support.environment.VanillaFeature; import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.Arguments; -import org.junit.jupiter.params.provider.EnumSource; import org.junit.jupiter.params.provider.MethodSource; -@AllFeatures -public class EntityTypesTest { - - private static final URI BUKKIT_CLASSES; - // Entity classes, which do not have any entity type / entity type data - private static final List> EXCLUDE = Arrays.asList( - AbstractArrow.class, - AbstractCow.class, - AbstractHorse.class, - AbstractSkeleton.class, - AbstractVillager.class, - AbstractWindCharge.class, - Ageable.class, - Ambient.class, - Animals.class, - Boat.class, - Boss.class, - Breedable.class, - ChestBoat.class, - ChestedHorse.class, - ComplexEntityPart.class, - ComplexLivingEntity.class, - Creature.class, - Damageable.class, - Display.class, - EnderDragonPart.class, - Enemy.class, - Entity.class, - Explosive.class, - Fireball.class, - Fish.class, - Flying.class, - Golem.class, - Hanging.class, - HumanEntity.class, - Illager.class, - LivingEntity.class, - Minecart.class, - Mob.class, - Monster.class, - NPC.class, - PiglinAbstract.class, - Projectile.class, - Raider.class, - Sittable.class, - SizedFireball.class, - Spellcaster.class, - Steerable.class, - Tameable.class, - ThrowableProjectile.class, - ThrownPotion.class, - TippedArrow.class, - Vehicle.class, - WaterMob.class, - AbstractNautilus.class - ); - - static { - try { - BUKKIT_CLASSES = Entity.class.getProtectionDomain().getCodeSource().getLocation().toURI(); - } catch (URISyntaxException e) { - throw new RuntimeException(e); - } - } - - private static JarFile jarFile = null; - - public static Stream excludedData() { - return EntityTypesTest.EXCLUDE.stream().map(Arguments::arguments); - } - - public static Stream data() { - return EntityTypesTest.jarFile - .stream() - .map(ZipEntry::getName) - .filter(name -> name.endsWith(".class")) - .filter(name -> name.startsWith("org/bukkit/entity")) - .map(name -> name.substring(0, name.length() - ".class".length())) - .map(name -> name.replace('/', '.')) - .map(name -> { - try { - return Class.forName(name); - } catch (ClassNotFoundException e) { - throw new RuntimeException(e); - } - }) - .filter(Entity.class::isAssignableFrom) - .filter(clazz -> !EntityTypesTest.EXCLUDE.contains(clazz)) - .map(Arguments::arguments); - } +import static org.junit.jupiter.api.Assertions.assertNotNull; - @BeforeAll - public static void beforeAll() throws IOException { - EntityTypesTest.jarFile = new JarFile(new File(EntityTypesTest.BUKKIT_CLASSES)); - } +@VanillaFeature +public class EntityTypesTest { - @ParameterizedTest - @MethodSource("excludedData") - public void testExcludedClass(Class clazz) { - CraftEntityTypes.EntityTypeData entityTypeData = CraftEntityTypes.getEntityTypeData(clazz); - assertNull(entityTypeData, String.format("Class %s is marked as excluded, because it does not have an entity type data, but we found one entity type data, something is not adding up.", clazz)); + public static Stream> data() { + return Registry.ENTITY_TYPE.stream(); } @ParameterizedTest @MethodSource("data") - public void testEntityClass(Class clazz) { - CraftEntityTypes.EntityTypeData entityTypeData = CraftEntityTypes.getEntityTypeData(clazz); - assertNotNull(entityTypeData, String.format("Class %s does not have an entity type data, please add on to CraftEntityTypes or mark the class as excluded in EntityTypesTest, if the class does not have an entity type.", clazz)); - } - - @Test - public void testEntityType() { - Registry.ENTITY_TYPE.forEach(type -> { - CraftEntityTypes.EntityTypeData entityTypeData = CraftEntityTypes.getEntityTypeData(type); - assertNotNull(entityTypeData, String.format("Entity type %s does not have an entity type data, please add on to CraftEntityTypes.", type)); - }); - } - - @AfterAll - public static void clear() throws IOException { - if (EntityTypesTest.jarFile != null) { - EntityTypesTest.jarFile.close(); - } + public void testEntityType(EntityType type) { + CraftEntityTypes.EntityTypeData entityTypeData = CraftEntityTypes.getEntityTypeData(type); + assertNotNull(entityTypeData, String.format("Entity type %s does not have an entity type data, please add one to CraftEntityTypes.", type.key().asString())); } } From 0a9fe06736f9bb5239f17aeefd79ec99fe39c3df Mon Sep 17 00:00:00 2001 From: Lulu13022002 <41980282+Lulu13022002@users.noreply.github.com> Date: Tue, 3 Mar 2026 16:26:04 +0100 Subject: [PATCH 3/6] reimplement raft --- .../src/main/java/org/bukkit/entity/ChestRaft.java | 7 +++++++ .../src/main/java/org/bukkit/entity/EntityType.java | 11 ++++++++--- paper-api/src/main/java/org/bukkit/entity/Raft.java | 7 +++++++ .../java/org/bukkit/entity/boat/BambooChestRaft.java | 4 ++-- .../main/java/org/bukkit/entity/boat/BambooRaft.java | 4 ++-- .../rewriter/types/simple/EntityTypeRewriter.java | 3 --- .../org/bukkit/craftbukkit/CraftRegionAccessor.java | 4 +--- .../org/bukkit/craftbukkit/entity/CraftChestRaft.java | 11 +++++++++++ .../bukkit/craftbukkit/entity/CraftEntityType.java | 4 +++- .../bukkit/craftbukkit/entity/CraftEntityTypes.java | 6 ++++-- .../java/org/bukkit/craftbukkit/entity/CraftRaft.java | 11 +++++++++++ .../papermc/paper}/entity/EntityTypesTest.java | 7 ++++--- 12 files changed, 60 insertions(+), 19 deletions(-) create mode 100644 paper-api/src/main/java/org/bukkit/entity/ChestRaft.java create mode 100644 paper-api/src/main/java/org/bukkit/entity/Raft.java create mode 100644 paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftChestRaft.java create mode 100644 paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftRaft.java rename paper-server/src/test/java/{org/bukkit/craftbukkit => io/papermc/paper}/entity/EntityTypesTest.java (83%) diff --git a/paper-api/src/main/java/org/bukkit/entity/ChestRaft.java b/paper-api/src/main/java/org/bukkit/entity/ChestRaft.java new file mode 100644 index 000000000000..8645f0ad6102 --- /dev/null +++ b/paper-api/src/main/java/org/bukkit/entity/ChestRaft.java @@ -0,0 +1,7 @@ +package org.bukkit.entity; + +/** + * Represents a chest raft. + */ +public interface ChestRaft extends ChestBoat { +} diff --git a/paper-api/src/main/java/org/bukkit/entity/EntityType.java b/paper-api/src/main/java/org/bukkit/entity/EntityType.java index 7080126dda06..5b20f479d4eb 100644 --- a/paper-api/src/main/java/org/bukkit/entity/EntityType.java +++ b/paper-api/src/main/java/org/bukkit/entity/EntityType.java @@ -20,7 +20,6 @@ import org.bukkit.entity.minecart.SpawnerMinecart; import org.bukkit.entity.minecart.StorageMinecart; import org.bukkit.util.OldEnum; -import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.Contract; import org.jspecify.annotations.NullMarked; import org.jspecify.annotations.Nullable; @@ -45,9 +44,9 @@ public interface EntityType extends OldEnum>, Ke EntityType AXOLOTL = getType("axolotl"); - EntityType BAMBOO_CHEST_RAFT = getType("bamboo_chest_raft"); + EntityType BAMBOO_CHEST_RAFT = getType("bamboo_chest_raft"); - EntityType BAMBOO_RAFT = getType("bamboo_raft"); + EntityType BAMBOO_RAFT = getType("bamboo_raft"); EntityType BAT = getType("bat"); @@ -365,6 +364,12 @@ private static EntityType getType(final @KeyPattern.Value */ boolean isSpawnable(); + /** + * Equivalent to check if {@link #getEntityClass()} extends of {@link LivingEntity} + * + * @deprecated do not rely on a concrete implementation + */ + @Deprecated(since = "1.21.11") boolean isAlive(); /** diff --git a/paper-api/src/main/java/org/bukkit/entity/Raft.java b/paper-api/src/main/java/org/bukkit/entity/Raft.java new file mode 100644 index 000000000000..fe872d558c58 --- /dev/null +++ b/paper-api/src/main/java/org/bukkit/entity/Raft.java @@ -0,0 +1,7 @@ +package org.bukkit.entity; + +/** + * Represents a raft. + */ +public interface Raft extends Boat { +} diff --git a/paper-api/src/main/java/org/bukkit/entity/boat/BambooChestRaft.java b/paper-api/src/main/java/org/bukkit/entity/boat/BambooChestRaft.java index ed7d348ada89..999606832ef2 100644 --- a/paper-api/src/main/java/org/bukkit/entity/boat/BambooChestRaft.java +++ b/paper-api/src/main/java/org/bukkit/entity/boat/BambooChestRaft.java @@ -1,10 +1,10 @@ package org.bukkit.entity.boat; -import org.bukkit.entity.ChestBoat; +import org.bukkit.entity.ChestRaft; /** * Represents a bamboo chest raft. */ @Deprecated(since = "1.21.11", forRemoval = true) @org.jetbrains.annotations.ApiStatus.ScheduledForRemoval(inVersion = "1.22") // Paper - will be removed via asm-utils -public interface BambooChestRaft extends ChestBoat { +public interface BambooChestRaft extends ChestRaft { } diff --git a/paper-api/src/main/java/org/bukkit/entity/boat/BambooRaft.java b/paper-api/src/main/java/org/bukkit/entity/boat/BambooRaft.java index ee5593ed31f3..c3a4d0747957 100644 --- a/paper-api/src/main/java/org/bukkit/entity/boat/BambooRaft.java +++ b/paper-api/src/main/java/org/bukkit/entity/boat/BambooRaft.java @@ -1,10 +1,10 @@ package org.bukkit.entity.boat; -import org.bukkit.entity.Boat; +import org.bukkit.entity.Raft; /** * Represents a bamboo raft. */ @Deprecated(since = "1.21.11", forRemoval = true) @org.jetbrains.annotations.ApiStatus.ScheduledForRemoval(inVersion = "1.22") // Paper - will be removed via asm-utils -public interface BambooRaft extends Boat { +public interface BambooRaft extends Raft { } diff --git a/paper-generator/src/main/java/io/papermc/generator/rewriter/types/simple/EntityTypeRewriter.java b/paper-generator/src/main/java/io/papermc/generator/rewriter/types/simple/EntityTypeRewriter.java index 7e263464e194..59b5e144835e 100644 --- a/paper-generator/src/main/java/io/papermc/generator/rewriter/types/simple/EntityTypeRewriter.java +++ b/paper-generator/src/main/java/io/papermc/generator/rewriter/types/simple/EntityTypeRewriter.java @@ -50,9 +50,6 @@ public class EntityTypeRewriter extends RegistryFieldRewriter> { .put("MinecartSpawner", "SpawnerMinecart") .put("MinecartTNT", "ExplosiveMinecart") .put("Minecart", "RideableMinecart") - - .put("Raft", "Boat") - .put("ChestRaft", "ChestBoat") .buildOrThrow(); private static final ClassResolver runtime = new ClassResolver(EntityTypeRewriter.class.getClassLoader()); diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/CraftRegionAccessor.java b/paper-server/src/main/java/org/bukkit/craftbukkit/CraftRegionAccessor.java index 200ea41ac761..31ba4f6fdba9 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/CraftRegionAccessor.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/CraftRegionAccessor.java @@ -471,9 +471,7 @@ public net.minecraft.world.entity.Entity createEntity(Location location, Class entity = this.getEntityClass(); + return entity != null && LivingEntity.class.isAssignableFrom(entity); } @Override diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftEntityTypes.java b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftEntityTypes.java index 5507fff510a7..374cdfe0eaf9 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftEntityTypes.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftEntityTypes.java @@ -55,6 +55,7 @@ import org.bukkit.entity.Cat; import org.bukkit.entity.CaveSpider; import org.bukkit.entity.ChestBoat; +import org.bukkit.entity.ChestRaft; import org.bukkit.entity.Chicken; import org.bukkit.entity.Cod; import org.bukkit.entity.CopperGolem; @@ -128,6 +129,7 @@ import org.bukkit.entity.PolarBear; import org.bukkit.entity.PufferFish; import org.bukkit.entity.Rabbit; +import org.bukkit.entity.Raft; import org.bukkit.entity.Ravager; import org.bukkit.entity.Salmon; import org.bukkit.entity.Sheep; @@ -379,8 +381,6 @@ Level minecraftWorld() { // Move (boats) register(new EntityTypeData<>(EntityType.ACACIA_BOAT, Boat.class, CraftBoat::new, createAndMove(net.minecraft.world.entity.EntityType.ACACIA_BOAT))); register(new EntityTypeData<>(EntityType.ACACIA_CHEST_BOAT, ChestBoat.class, CraftChestBoat::new, createAndMove(net.minecraft.world.entity.EntityType.ACACIA_CHEST_BOAT))); - register(new EntityTypeData<>(EntityType.BAMBOO_RAFT, Boat.class, CraftBoat::new, createAndMove(net.minecraft.world.entity.EntityType.BAMBOO_RAFT))); - register(new EntityTypeData<>(EntityType.BAMBOO_CHEST_RAFT, ChestBoat.class, CraftChestBoat::new, createAndMove(net.minecraft.world.entity.EntityType.BAMBOO_CHEST_RAFT))); register(new EntityTypeData<>(EntityType.BIRCH_BOAT, Boat.class, CraftBoat::new, createAndMove(net.minecraft.world.entity.EntityType.BIRCH_BOAT))); register(new EntityTypeData<>(EntityType.BIRCH_CHEST_BOAT, ChestBoat.class, CraftChestBoat::new, createAndMove(net.minecraft.world.entity.EntityType.BIRCH_CHEST_BOAT))); register(new EntityTypeData<>(EntityType.CHERRY_BOAT, Boat.class, CraftBoat::new, createAndMove(net.minecraft.world.entity.EntityType.CHERRY_BOAT))); @@ -397,6 +397,8 @@ Level minecraftWorld() { register(new EntityTypeData<>(EntityType.PALE_OAK_CHEST_BOAT, ChestBoat.class, CraftChestBoat::new, createAndMove(net.minecraft.world.entity.EntityType.PALE_OAK_CHEST_BOAT))); register(new EntityTypeData<>(EntityType.SPRUCE_BOAT, Boat.class, CraftBoat::new, createAndMove(net.minecraft.world.entity.EntityType.SPRUCE_BOAT))); register(new EntityTypeData<>(EntityType.SPRUCE_CHEST_BOAT, ChestBoat.class, CraftChestBoat::new, createAndMove(net.minecraft.world.entity.EntityType.SPRUCE_CHEST_BOAT))); + register(new EntityTypeData<>(EntityType.BAMBOO_RAFT, Raft.class, CraftRaft::new, createAndMove(net.minecraft.world.entity.EntityType.BAMBOO_RAFT))); + register(new EntityTypeData<>(EntityType.BAMBOO_CHEST_RAFT, ChestRaft.class, CraftChestRaft::new, createAndMove(net.minecraft.world.entity.EntityType.BAMBOO_CHEST_RAFT))); // Set pos register(new EntityTypeData<>(EntityType.MARKER, Marker.class, CraftMarker::new, createAndSetPos(net.minecraft.world.entity.EntityType.MARKER))); diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftRaft.java b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftRaft.java new file mode 100644 index 000000000000..b83ac13afdaf --- /dev/null +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftRaft.java @@ -0,0 +1,11 @@ +package org.bukkit.craftbukkit.entity; + +import org.bukkit.craftbukkit.CraftServer; +import org.bukkit.entity.Raft; + +public class CraftRaft extends CraftBoat implements Raft { + + public CraftRaft(final CraftServer server, final net.minecraft.world.entity.vehicle.boat.Raft entity) { + super(server, entity); + } +} diff --git a/paper-server/src/test/java/org/bukkit/craftbukkit/entity/EntityTypesTest.java b/paper-server/src/test/java/io/papermc/paper/entity/EntityTypesTest.java similarity index 83% rename from paper-server/src/test/java/org/bukkit/craftbukkit/entity/EntityTypesTest.java rename to paper-server/src/test/java/io/papermc/paper/entity/EntityTypesTest.java index 816f6154d169..f147cb498cf9 100644 --- a/paper-server/src/test/java/org/bukkit/craftbukkit/entity/EntityTypesTest.java +++ b/paper-server/src/test/java/io/papermc/paper/entity/EntityTypesTest.java @@ -1,15 +1,16 @@ -package org.bukkit.craftbukkit.entity; +package io.papermc.paper.entity; import java.util.stream.Stream; import org.bukkit.Registry; +import org.bukkit.craftbukkit.entity.CraftEntityTypes; import org.bukkit.entity.EntityType; -import org.bukkit.support.environment.VanillaFeature; +import org.bukkit.support.environment.AllFeatures; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.MethodSource; import static org.junit.jupiter.api.Assertions.assertNotNull; -@VanillaFeature +@AllFeatures public class EntityTypesTest { public static Stream> data() { From de06934f294843552c76d33d7073f7b43d44303c Mon Sep 17 00:00:00 2001 From: Lulu13022002 <41980282+Lulu13022002@users.noreply.github.com> Date: Tue, 3 Mar 2026 16:26:04 +0100 Subject: [PATCH 4/6] bytecode rewriting for enum > interface unknown and boats are not handled yet --- .../java/co/aikar/timings/TimingHistory.java | 2 +- .../io/papermc/paper/tag/EntitySetTag.java | 2 +- .../java/org/bukkit/entity/EntityType.java | 11 ++- paper-server/build.gradle.kts | 2 +- .../PaperClassloaderBytecodeModifier.java | 12 ---- .../PaperSimplePluginClassLoader.java | 1 + .../bytecode/ClassToInterfaceRules.java | 49 +++++++++++++ .../ClassloaderBytecodeModifier.java | 2 +- .../PaperClassloaderBytecodeModifier.java | 18 +++++ .../paper/util/LegacyEnumHolderable.java | 68 +++++++++++++++++++ .../craftbukkit/entity/CraftEntityType.java | 9 +-- .../bukkit/craftbukkit/util/ApiVersion.java | 2 + .../bukkit/craftbukkit/util/Commodore.java | 7 +- ...nt.classloader.ClassloaderBytecodeModifier | 1 - ...oader.bytecode.ClassloaderBytecodeModifier | 1 + settings.gradle.kts | 1 + test-plugin/build.gradle.kts | 3 +- 17 files changed, 159 insertions(+), 32 deletions(-) delete mode 100644 paper-server/src/main/java/io/papermc/paper/plugin/entrypoint/classloader/PaperClassloaderBytecodeModifier.java create mode 100644 paper-server/src/main/java/io/papermc/paper/plugin/entrypoint/classloader/bytecode/ClassToInterfaceRules.java rename paper-server/src/main/java/io/papermc/paper/plugin/entrypoint/classloader/{ => bytecode}/ClassloaderBytecodeModifier.java (89%) create mode 100644 paper-server/src/main/java/io/papermc/paper/plugin/entrypoint/classloader/bytecode/PaperClassloaderBytecodeModifier.java create mode 100644 paper-server/src/main/java/io/papermc/paper/util/LegacyEnumHolderable.java delete mode 100644 paper-server/src/main/resources/META-INF/services/io.papermc.paper.plugin.entrypoint.classloader.ClassloaderBytecodeModifier create mode 100644 paper-server/src/main/resources/META-INF/services/io.papermc.paper.plugin.entrypoint.classloader.bytecode.ClassloaderBytecodeModifier diff --git a/paper-api/src/main/java/co/aikar/timings/TimingHistory.java b/paper-api/src/main/java/co/aikar/timings/TimingHistory.java index 142971be15c5..6f8e403413da 100644 --- a/paper-api/src/main/java/co/aikar/timings/TimingHistory.java +++ b/paper-api/src/main/java/co/aikar/timings/TimingHistory.java @@ -154,7 +154,7 @@ public Object apply(RegionData input) { public JSONPair apply(Map.Entry, Counter> entry) { entityTypeSet.add(entry.getKey()); return pair( - String.valueOf(entry.getKey().ordinal()), + entry.getKey().key().asString(), // todo check format entry.getValue().count() ); } diff --git a/paper-api/src/main/java/io/papermc/paper/tag/EntitySetTag.java b/paper-api/src/main/java/io/papermc/paper/tag/EntitySetTag.java index efd8faaec6c0..beadd69fe139 100644 --- a/paper-api/src/main/java/io/papermc/paper/tag/EntitySetTag.java +++ b/paper-api/src/main/java/io/papermc/paper/tag/EntitySetTag.java @@ -36,6 +36,6 @@ protected Set getAllPossibleValues() { @NotNull @Override protected String getName(@NotNull EntityType value) { - return value.name(); + return value.key().value().toUpperCase(); // should be close enough } } diff --git a/paper-api/src/main/java/org/bukkit/entity/EntityType.java b/paper-api/src/main/java/org/bukkit/entity/EntityType.java index 5b20f479d4eb..77eabc710e07 100644 --- a/paper-api/src/main/java/org/bukkit/entity/EntityType.java +++ b/paper-api/src/main/java/org/bukkit/entity/EntityType.java @@ -19,13 +19,12 @@ import org.bukkit.entity.minecart.RideableMinecart; import org.bukkit.entity.minecart.SpawnerMinecart; import org.bukkit.entity.minecart.StorageMinecart; -import org.bukkit.util.OldEnum; import org.jetbrains.annotations.Contract; import org.jspecify.annotations.NullMarked; import org.jspecify.annotations.Nullable; @NullMarked -public interface EntityType extends OldEnum>, Keyed, Translatable, net.kyori.adventure.translation.Translatable, FeatureDependant { +public interface EntityType extends Keyed, Translatable, net.kyori.adventure.translation.Translatable, FeatureDependant { // Start generate - EntityType EntityType ACACIA_BOAT = getType("acacia_boat"); @@ -355,12 +354,10 @@ private static EntityType getType(final @KeyPattern.Value } /** - * Some entities cannot be spawned using {@link - * World#spawnEntity(Location, EntityType)} or {@link - * World#spawn(Location, Class)}, usually because they require additional - * information in order to spawn. + * Some entities cannot be spawned using {@link World#spawnEntity(Location, EntityType)}, + * usually because they require additional information in order to spawn. * - * @return False if the entity type cannot be spawned + * @return {@code false} if the entity type cannot be spawned */ boolean isSpawnable(); diff --git a/paper-server/build.gradle.kts b/paper-server/build.gradle.kts index 4b842350add1..5407a9ff4f80 100644 --- a/paper-server/build.gradle.kts +++ b/paper-server/build.gradle.kts @@ -176,7 +176,7 @@ dependencies { implementation("net.neoforged:AutoRenamingTool:2.0.3") // Remap plugins // Remap reflection - val reflectionRewriterVersion = "0.0.3" + val reflectionRewriterVersion = "0.0.4-SNAPSHOT" implementation("io.papermc:reflection-rewriter:$reflectionRewriterVersion") implementation("io.papermc:reflection-rewriter-runtime:$reflectionRewriterVersion") implementation("io.papermc:reflection-rewriter-proxy-generator:$reflectionRewriterVersion") diff --git a/paper-server/src/main/java/io/papermc/paper/plugin/entrypoint/classloader/PaperClassloaderBytecodeModifier.java b/paper-server/src/main/java/io/papermc/paper/plugin/entrypoint/classloader/PaperClassloaderBytecodeModifier.java deleted file mode 100644 index 0e734c07dbe8..000000000000 --- a/paper-server/src/main/java/io/papermc/paper/plugin/entrypoint/classloader/PaperClassloaderBytecodeModifier.java +++ /dev/null @@ -1,12 +0,0 @@ -package io.papermc.paper.plugin.entrypoint.classloader; - -import io.papermc.paper.plugin.configuration.PluginMeta; - -// Stub, implement in future. -public class PaperClassloaderBytecodeModifier implements ClassloaderBytecodeModifier { - - @Override - public byte[] modify(PluginMeta configuration, byte[] bytecode) { - return io.papermc.paper.pluginremap.reflect.ReflectionRemapper.processClass(bytecode); - } -} diff --git a/paper-server/src/main/java/io/papermc/paper/plugin/entrypoint/classloader/PaperSimplePluginClassLoader.java b/paper-server/src/main/java/io/papermc/paper/plugin/entrypoint/classloader/PaperSimplePluginClassLoader.java index d97f63347cda..ace9315f6007 100644 --- a/paper-server/src/main/java/io/papermc/paper/plugin/entrypoint/classloader/PaperSimplePluginClassLoader.java +++ b/paper-server/src/main/java/io/papermc/paper/plugin/entrypoint/classloader/PaperSimplePluginClassLoader.java @@ -1,6 +1,7 @@ package io.papermc.paper.plugin.entrypoint.classloader; import io.papermc.paper.plugin.configuration.PluginMeta; +import io.papermc.paper.plugin.entrypoint.classloader.bytecode.ClassloaderBytecodeModifier; import io.papermc.paper.plugin.util.NamespaceChecker; import org.jetbrains.annotations.ApiStatus; diff --git a/paper-server/src/main/java/io/papermc/paper/plugin/entrypoint/classloader/bytecode/ClassToInterfaceRules.java b/paper-server/src/main/java/io/papermc/paper/plugin/entrypoint/classloader/bytecode/ClassToInterfaceRules.java new file mode 100644 index 000000000000..9bbd029f1704 --- /dev/null +++ b/paper-server/src/main/java/io/papermc/paper/plugin/entrypoint/classloader/bytecode/ClassToInterfaceRules.java @@ -0,0 +1,49 @@ +package io.papermc.paper.plugin.entrypoint.classloader.bytecode; + +import io.papermc.asm.ClassInfoProvider; +import io.papermc.asm.RewriteRuleVisitorFactory; +import io.papermc.asm.rules.classes.EnumToInterfaceRule; +import java.lang.constant.ClassDesc; +import java.util.Map; +import java.util.stream.Collectors; +import org.bukkit.craftbukkit.entity.CraftEntityType; +import org.bukkit.entity.EntityType; +import org.objectweb.asm.ClassReader; +import org.objectweb.asm.ClassVisitor; +import org.objectweb.asm.ClassWriter; +import org.objectweb.asm.Opcodes; + +public final class ClassToInterfaceRules { + + private static final RewriteRuleVisitorFactory VISITOR_FACTORY = RewriteRuleVisitorFactory.create( + Opcodes.ASM9, + chain -> { + Map enums = enums().entrySet().stream().collect(Collectors.toMap( + entry -> entry.getKey().describeConstable().orElseThrow(), + entry -> entry.getValue().describeConstable().orElseThrow() + )); + chain.then(new EnumToInterfaceRule(enums)); + }, + ClassInfoProvider.basic() + ); + + private ClassToInterfaceRules() { + } + + public static ClassVisitor visitor(final ClassVisitor parent) { + return VISITOR_FACTORY.createVisitor(parent); + } + + public static byte[] processClass(final byte[] bytes) { + final ClassReader classReader = new ClassReader(bytes); + final ClassWriter classWriter = new ClassWriter(classReader, ClassWriter.COMPUTE_MAXS); + classReader.accept(visitor(classWriter), 0); + return classWriter.toByteArray(); + } + + private static Map, Class> enums() { + return Map.of( + EntityType.class, CraftEntityType.class + ); + } +} diff --git a/paper-server/src/main/java/io/papermc/paper/plugin/entrypoint/classloader/ClassloaderBytecodeModifier.java b/paper-server/src/main/java/io/papermc/paper/plugin/entrypoint/classloader/bytecode/ClassloaderBytecodeModifier.java similarity index 89% rename from paper-server/src/main/java/io/papermc/paper/plugin/entrypoint/classloader/ClassloaderBytecodeModifier.java rename to paper-server/src/main/java/io/papermc/paper/plugin/entrypoint/classloader/bytecode/ClassloaderBytecodeModifier.java index 93b5196a960f..fcbc60462b71 100644 --- a/paper-server/src/main/java/io/papermc/paper/plugin/entrypoint/classloader/ClassloaderBytecodeModifier.java +++ b/paper-server/src/main/java/io/papermc/paper/plugin/entrypoint/classloader/bytecode/ClassloaderBytecodeModifier.java @@ -1,4 +1,4 @@ -package io.papermc.paper.plugin.entrypoint.classloader; +package io.papermc.paper.plugin.entrypoint.classloader.bytecode; import io.papermc.paper.plugin.configuration.PluginMeta; import net.kyori.adventure.util.Services; diff --git a/paper-server/src/main/java/io/papermc/paper/plugin/entrypoint/classloader/bytecode/PaperClassloaderBytecodeModifier.java b/paper-server/src/main/java/io/papermc/paper/plugin/entrypoint/classloader/bytecode/PaperClassloaderBytecodeModifier.java new file mode 100644 index 000000000000..d877267cd0ad --- /dev/null +++ b/paper-server/src/main/java/io/papermc/paper/plugin/entrypoint/classloader/bytecode/PaperClassloaderBytecodeModifier.java @@ -0,0 +1,18 @@ +package io.papermc.paper.plugin.entrypoint.classloader.bytecode; + +import io.papermc.paper.plugin.configuration.PluginMeta; +import org.bukkit.craftbukkit.util.ApiVersion; + +public class PaperClassloaderBytecodeModifier implements ClassloaderBytecodeModifier { + + @Override + public byte[] modify(PluginMeta configuration, byte[] bytecode) { + bytecode = io.papermc.paper.pluginremap.reflect.ReflectionRemapper.processClass(bytecode); + + ApiVersion version = ApiVersion.getOrCreateVersion(configuration.getAPIVersion()); + if (version.isOlderThanOrSameAs(ApiVersion.CLASS_TO_INTERFACE)) { + bytecode = ClassToInterfaceRules.processClass(bytecode); + } + return bytecode; + } +} diff --git a/paper-server/src/main/java/io/papermc/paper/util/LegacyEnumHolderable.java b/paper-server/src/main/java/io/papermc/paper/util/LegacyEnumHolderable.java new file mode 100644 index 000000000000..a3c99c86e1a2 --- /dev/null +++ b/paper-server/src/main/java/io/papermc/paper/util/LegacyEnumHolderable.java @@ -0,0 +1,68 @@ +package io.papermc.paper.util; + +import com.google.common.base.Preconditions; +import io.papermc.asm.rules.classes.LegacyEnum; +import io.papermc.paper.registry.HolderableBase; +import java.util.Locale; +import java.util.regex.Pattern; +import net.minecraft.core.Holder; +import org.bukkit.Keyed; +import org.bukkit.NamespacedKey; +import org.jspecify.annotations.NullMarked; +import org.jspecify.annotations.Nullable; + +@NullMarked +public abstract class LegacyEnumHolderable> extends HolderableBase implements Holderable, LegacyEnum, Keyed { + + private final int ordinal; + private final @Nullable String name; + + protected LegacyEnumHolderable(final Holder holder, final int ordinal) { + super(holder); + this.ordinal = ordinal; + if (holder instanceof final Holder.Reference reference) { + // For backwards compatibility, minecraft values will still return the uppercase name without the namespace, + // in case plugins use, for example, the name as a key in a config file to receive registry item specific values. + // Custom registry items will return the key with namespace. For a plugin this should look like a new registry item + // (which can always be added in new minecraft versions and the plugin should therefore handle it accordingly). + if (NamespacedKey.MINECRAFT.equals(reference.key().identifier().getNamespace())) { + this.name = formatKeyAsField(reference.key().identifier().getPath()); + } else { + this.name = reference.key().identifier().toString(); + } + } else { + this.name = null; + } + } + + @Override + @Deprecated + public int compareTo(final I other) { + this.checkIsReference(); + return this.ordinal - other.ordinal(); + } + + @Override + @Deprecated + public String name() { + this.checkIsReference(); + return this.name; + } + + @Override + @Deprecated + public int ordinal() { + this.checkIsReference(); + return this.ordinal; + } + + private void checkIsReference() { + Preconditions.checkState(this.holder.kind() == Holder.Kind.REFERENCE, "Cannot call method for this registry item, because it is not registered."); + } + + private static final Pattern ILLEGAL_FIELD_CHARACTERS = Pattern.compile("[.-/]"); + + public static String formatKeyAsField(String path) { + return ILLEGAL_FIELD_CHARACTERS.matcher(path.toUpperCase(Locale.ENGLISH)).replaceAll("_"); + } +} diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftEntityType.java b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftEntityType.java index 6e0377874c4e..f5e3e6235593 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftEntityType.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftEntityType.java @@ -4,7 +4,7 @@ import com.google.common.collect.ImmutableBiMap; import io.papermc.paper.attribute.UnmodifiableAttributeMap; import io.papermc.paper.registry.RegistryKey; -import io.papermc.paper.util.OldEnumHolderable; +import io.papermc.paper.util.LegacyEnumHolderable; import io.papermc.paper.world.flag.PaperFeatureDependent; import java.util.Locale; import java.util.Objects; @@ -30,7 +30,7 @@ import org.jspecify.annotations.Nullable; @NullMarked -public class CraftEntityType extends OldEnumHolderable, net.minecraft.world.entity.EntityType> implements EntityType, PaperFeatureDependent> { +public class CraftEntityType extends LegacyEnumHolderable, CraftEntityType> implements EntityType, PaperFeatureDependent> { private static int count = 0; @@ -78,7 +78,7 @@ public Attributable getDefaultAttributes() { */ @Deprecated(forRemoval = true, since = "1.21.11") @ApiStatus.ScheduledForRemoval(inVersion = "1.22") - public static class LegacyUnknownImpl implements EntityType { + public static class LegacyUnknownImpl implements EntityType { // todo legacy enum but getKey needs to be overridden, no vanilla holder public static final EntityType INSTANCE = new LegacyUnknownImpl(); @@ -93,6 +93,7 @@ public NamespacedKey getKey() { return null; } + /* @Override public int compareTo(final EntityType other) { return this.ordinal - other.ordinal(); @@ -106,7 +107,7 @@ public String name() { @Override public int ordinal() { return this.ordinal; - } + }*/ @Override public boolean equals(final Object object) { diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/util/ApiVersion.java b/paper-server/src/main/java/org/bukkit/craftbukkit/util/ApiVersion.java index 4a1b8038a144..c00769339c74 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/util/ApiVersion.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/util/ApiVersion.java @@ -11,6 +11,7 @@ public final class ApiVersion implements Comparable, Serializable { public static final ApiVersion FLATTENING; public static final ApiVersion FIELD_NAME_PARITY; public static final ApiVersion ABSTRACT_COW; + public static final ApiVersion CLASS_TO_INTERFACE; public static final ApiVersion NONE; private static final Map versions; @@ -21,6 +22,7 @@ public final class ApiVersion implements Comparable, Serializable { FLATTENING = getOrCreateVersion("1.13"); FIELD_NAME_PARITY = getOrCreateVersion("1.20.5"); ABSTRACT_COW = getOrCreateVersion("1.21.5"); + CLASS_TO_INTERFACE = getOrCreateVersion("1.21.11"); NONE = getOrCreateVersion("none"); } diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/util/Commodore.java b/paper-server/src/main/java/org/bukkit/craftbukkit/util/Commodore.java index cfba954cc65c..d83bb566cb55 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/util/Commodore.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/util/Commodore.java @@ -1,15 +1,13 @@ package org.bukkit.craftbukkit.util; import com.google.common.base.Predicates; -import com.google.common.collect.HashMultimap; -import com.google.common.collect.Multimap; import com.google.common.io.ByteStreams; +import io.papermc.paper.plugin.entrypoint.classloader.bytecode.ClassToInterfaceRules; import java.io.File; import java.io.FileOutputStream; import java.io.InputStream; import java.util.ArrayList; import java.util.Arrays; -import java.util.Collection; import java.util.Collections; import java.util.Enumeration; import java.util.HashMap; @@ -228,6 +226,9 @@ public byte[] convert(byte[] b, final String pluginName, final ApiVersion plugin ClassVisitor visitor = cw; + if (pluginVersion.isOlderThanOrSameAs(ApiVersion.CLASS_TO_INTERFACE)) { + visitor = ClassToInterfaceRules.visitor(visitor); + } visitor = io.papermc.paper.pluginremap.reflect.ReflectionRemapper.visitor(visitor); // Paper Map renames = new HashMap<>(RENAMES); diff --git a/paper-server/src/main/resources/META-INF/services/io.papermc.paper.plugin.entrypoint.classloader.ClassloaderBytecodeModifier b/paper-server/src/main/resources/META-INF/services/io.papermc.paper.plugin.entrypoint.classloader.ClassloaderBytecodeModifier deleted file mode 100644 index 20dbe2775951..000000000000 --- a/paper-server/src/main/resources/META-INF/services/io.papermc.paper.plugin.entrypoint.classloader.ClassloaderBytecodeModifier +++ /dev/null @@ -1 +0,0 @@ -io.papermc.paper.plugin.entrypoint.classloader.PaperClassloaderBytecodeModifier diff --git a/paper-server/src/main/resources/META-INF/services/io.papermc.paper.plugin.entrypoint.classloader.bytecode.ClassloaderBytecodeModifier b/paper-server/src/main/resources/META-INF/services/io.papermc.paper.plugin.entrypoint.classloader.bytecode.ClassloaderBytecodeModifier new file mode 100644 index 000000000000..4a5548399719 --- /dev/null +++ b/paper-server/src/main/resources/META-INF/services/io.papermc.paper.plugin.entrypoint.classloader.bytecode.ClassloaderBytecodeModifier @@ -0,0 +1 @@ +io.papermc.paper.plugin.entrypoint.classloader.bytecode.PaperClassloaderBytecodeModifier diff --git a/settings.gradle.kts b/settings.gradle.kts index 9289c95a7301..bd3e72bac7bc 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -9,6 +9,7 @@ plugins { id("org.gradle.toolchains.foojay-resolver-convention") version "1.0.0" } +includeBuild("../asm-utils") if (!file(".git").exists()) { val errorText = """ diff --git a/test-plugin/build.gradle.kts b/test-plugin/build.gradle.kts index 3dd4b5f5cad5..a175db3b965a 100644 --- a/test-plugin/build.gradle.kts +++ b/test-plugin/build.gradle.kts @@ -1,7 +1,8 @@ version = "1.0.0-SNAPSHOT" dependencies { - compileOnly(project(":paper-api")) + //compileOnly(project(":paper-api")) + compileOnly("io.papermc.paper:paper-api:1.21.11-R0.1-SNAPSHOT") } tasks.processResources { From 0ddbd3d16837d4d1f55ed0873ae369846a04f1cc Mon Sep 17 00:00:00 2001 From: Lulu13022002 <41980282+Lulu13022002@users.noreply.github.com> Date: Tue, 3 Mar 2026 18:13:47 +0100 Subject: [PATCH 5/6] respect limited region --- .../main/java/org/bukkit/RegionAccessor.java | 8 ++++---- .../craftbukkit/CraftRegionAccessor.java | 8 ++++---- .../generator/CraftLimitedRegion.java | 18 ++++++++++++++++-- 3 files changed, 24 insertions(+), 10 deletions(-) diff --git a/paper-api/src/main/java/org/bukkit/RegionAccessor.java b/paper-api/src/main/java/org/bukkit/RegionAccessor.java index ddcfd0f99a51..4f01885bc175 100644 --- a/paper-api/src/main/java/org/bukkit/RegionAccessor.java +++ b/paper-api/src/main/java/org/bukkit/RegionAccessor.java @@ -327,7 +327,7 @@ default void setType(int x, int y, int z, @NotNull Material material) { * created in, care should be taken that the entity does not outlive the * world instance as this will lead to memory leaks. * - * @param the class of the {@link Entity} to create + * @param the class of the {@link Entity} to create * @param location the {@link Location} to create the entity at * @param clazz the class of the {@link Entity} to spawn * @return an instance of the created {@link Entity} @@ -337,7 +337,7 @@ default void setType(int x, int y, int z, @NotNull Material material) { */ @NotNull @Deprecated(since = "1.21.11") - T createEntity(@NotNull Location location, @NotNull Class clazz); + E createEntity(@NotNull Location location, @NotNull Class clazz); /** * Creates an entity of a specific entity type at the given {@link Location} but @@ -347,7 +347,7 @@ default void setType(int x, int y, int z, @NotNull Material material) { * created in, care should be taken that the entity does not outlive the * world instance as this will lead to memory leaks. * - * @param the class of the {@link Entity} to create + * @param the class of the {@link Entity} to create * @param location the {@link Location} to create the entity at * @param type the entity type of the {@link Entity} to spawn * @return an instance of the created {@link Entity} @@ -355,7 +355,7 @@ default void setType(int x, int y, int z, @NotNull Material material) { * @see Entity#createSnapshot() */ @NotNull - T createEntity(@NotNull Location location, @NotNull EntityType type); + E createEntity(@NotNull Location location, @NotNull EntityType type); /** * Spawn an entity of a specific class at the given {@link Location} diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/CraftRegionAccessor.java b/paper-server/src/main/java/org/bukkit/craftbukkit/CraftRegionAccessor.java index 31ba4f6fdba9..ad24aaab0fee 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/CraftRegionAccessor.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/CraftRegionAccessor.java @@ -333,26 +333,26 @@ public Collection getEntitiesByClasses(Class... classes) { @Override @SuppressWarnings("unchecked") - public T createEntity(Location location, Class clazz) throws IllegalArgumentException { + public E createEntity(Location location, Class clazz) throws IllegalArgumentException { net.minecraft.world.entity.Entity entity = this.createEntity(location, clazz, true); if (!this.isNormalWorld()) { entity.generation = true; } - return (T) entity.getBukkitEntity(); + return (E) entity.getBukkitEntity(); } @Override @SuppressWarnings("unchecked") - public T createEntity(Location location, EntityType type) throws IllegalArgumentException { + public E createEntity(Location location, EntityType type) throws IllegalArgumentException { net.minecraft.world.entity.Entity entity = this.createEntity(location, type, true); if (!this.isNormalWorld()) { entity.generation = true; } - return (T) entity.getBukkitEntity(); + return (E) entity.getBukkitEntity(); } @Override diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/generator/CraftLimitedRegion.java b/paper-server/src/main/java/org/bukkit/craftbukkit/generator/CraftLimitedRegion.java index eb39073213ff..43530ce8a709 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/generator/CraftLimitedRegion.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/generator/CraftLimitedRegion.java @@ -1,13 +1,13 @@ package org.bukkit.craftbukkit.generator; import com.google.common.base.Preconditions; +import com.mojang.logging.LogUtils; import java.lang.ref.WeakReference; import java.util.ArrayList; import java.util.Collection; import java.util.List; import java.util.Random; import java.util.function.Consumer; -import com.mojang.logging.LogUtils; import net.minecraft.core.BlockPos; import net.minecraft.core.Holder; import net.minecraft.nbt.CompoundTag; @@ -33,6 +33,8 @@ import org.bukkit.event.entity.CreatureSpawnEvent; import org.bukkit.generator.LimitedRegion; import org.bukkit.util.BoundingBox; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import org.slf4j.Logger; public class CraftLimitedRegion extends CraftRegionAccessor implements LimitedRegion { @@ -255,7 +257,19 @@ public Collection getNMSEntities() { } @Override - public T spawn(Location location, Class clazz, Consumer function, CreatureSpawnEvent.SpawnReason reason) throws IllegalArgumentException { + public E spawnEntity(Location location, org.bukkit.entity.EntityType type, boolean randomizeData, CreatureSpawnEvent.SpawnReason reason, Consumer function) throws IllegalArgumentException { + Preconditions.checkArgument(this.isInRegion(location), "Coordinates %s, %s, %s are not in the region", location.getBlockX(), location.getBlockY(), location.getBlockZ()); + return super.spawnEntity(location, type, randomizeData, reason, function); + } + + @Override + public E spawn(@NotNull Location location, @NotNull Class clazz, boolean randomizeData, @Nullable Consumer function) { + Preconditions.checkArgument(this.isInRegion(location), "Coordinates %s, %s, %s are not in the region", location.getBlockX(), location.getBlockY(), location.getBlockZ()); + return super.spawn(location, clazz, randomizeData, function); + } + + @Override + public E spawn(Location location, Class clazz, Consumer function, CreatureSpawnEvent.SpawnReason reason) throws IllegalArgumentException { Preconditions.checkArgument(this.isInRegion(location), "Coordinates %s, %s, %s are not in the region", location.getBlockX(), location.getBlockY(), location.getBlockZ()); return super.spawn(location, clazz, function, reason); } From 899639f696d7491d7bbe4ec1f75ad4c9381e3ca6 Mon Sep 17 00:00:00 2001 From: Lulu13022002 <41980282+Lulu13022002@users.noreply.github.com> Date: Thu, 5 Mar 2026 13:15:25 +0100 Subject: [PATCH 6/6] handle unknown type a bit --- .../io/papermc/paper/tag/EntitySetTag.java | 3 ++- .../java/org/bukkit/entity/EntityType.java | 4 ++- .../java/org/bukkit/material/SpawnEgg.java | 3 ++- ...terfaceRules.java => EntityTypeRules.java} | 11 ++++++-- .../PaperClassloaderBytecodeModifier.java | 2 +- .../craftbukkit/CraftRegionAccessor.java | 1 - .../block/CraftCreatureSpawner.java | 2 +- .../block/CraftTrialSpawnerConfiguration.java | 2 +- .../craftbukkit/entity/CraftEntityType.java | 25 ++++++++++--------- .../entity/CraftMinecartMobSpawner.java | 2 +- .../generator/CraftLimitedRegion.java | 12 ++------- .../inventory/CraftItemFactory.java | 2 +- .../bukkit/craftbukkit/util/Commodore.java | 4 +-- 13 files changed, 38 insertions(+), 35 deletions(-) rename paper-server/src/main/java/io/papermc/paper/plugin/entrypoint/classloader/bytecode/{ClassToInterfaceRules.java => EntityTypeRules.java} (78%) diff --git a/paper-api/src/main/java/io/papermc/paper/tag/EntitySetTag.java b/paper-api/src/main/java/io/papermc/paper/tag/EntitySetTag.java index beadd69fe139..9fe470622fd5 100644 --- a/paper-api/src/main/java/io/papermc/paper/tag/EntitySetTag.java +++ b/paper-api/src/main/java/io/papermc/paper/tag/EntitySetTag.java @@ -1,6 +1,7 @@ package io.papermc.paper.tag; import java.util.Collection; +import java.util.Locale; import java.util.Set; import java.util.function.Predicate; import java.util.stream.Collectors; @@ -36,6 +37,6 @@ protected Set getAllPossibleValues() { @NotNull @Override protected String getName(@NotNull EntityType value) { - return value.key().value().toUpperCase(); // should be close enough + return value.key().value().toUpperCase(Locale.ROOT); // should be close enough } } diff --git a/paper-api/src/main/java/org/bukkit/entity/EntityType.java b/paper-api/src/main/java/org/bukkit/entity/EntityType.java index 77eabc710e07..2e34481c0274 100644 --- a/paper-api/src/main/java/org/bukkit/entity/EntityType.java +++ b/paper-api/src/main/java/org/bukkit/entity/EntityType.java @@ -346,7 +346,9 @@ public interface EntityType extends Keyed, Translatable, net.k * An unknown entity without an Entity Class */ @Deprecated(since = "1.21.11", forRemoval = true) @org.jetbrains.annotations.ApiStatus.ScheduledForRemoval(inVersion = "1.22") // Paper - will be removed via asm-utils - EntityType UNKNOWN = InternalAPIBridge.get().constructLegacyUnknownEntityType(); + static EntityType getUnknownInstance() { + return InternalAPIBridge.get().constructLegacyUnknownEntityType(); + } @SuppressWarnings("unchecked") private static EntityType getType(final @KeyPattern.Value String key) { diff --git a/paper-api/src/main/java/org/bukkit/material/SpawnEgg.java b/paper-api/src/main/java/org/bukkit/material/SpawnEgg.java index ce98ef57dbb8..163805e32abe 100644 --- a/paper-api/src/main/java/org/bukkit/material/SpawnEgg.java +++ b/paper-api/src/main/java/org/bukkit/material/SpawnEgg.java @@ -47,7 +47,8 @@ public SpawnEgg(EntityType type) { */ @Deprecated(since = "1.9") public EntityType getSpawnedType() { - return EntityType.UNKNOWN; // todo asm-utils + return null; + //return EntityType.UNKNOWN; // todo asm-utils //return EntityType.fromId(getData()); } diff --git a/paper-server/src/main/java/io/papermc/paper/plugin/entrypoint/classloader/bytecode/ClassToInterfaceRules.java b/paper-server/src/main/java/io/papermc/paper/plugin/entrypoint/classloader/bytecode/EntityTypeRules.java similarity index 78% rename from paper-server/src/main/java/io/papermc/paper/plugin/entrypoint/classloader/bytecode/ClassToInterfaceRules.java rename to paper-server/src/main/java/io/papermc/paper/plugin/entrypoint/classloader/bytecode/EntityTypeRules.java index 9bbd029f1704..8a700686e4c0 100644 --- a/paper-server/src/main/java/io/papermc/paper/plugin/entrypoint/classloader/bytecode/ClassToInterfaceRules.java +++ b/paper-server/src/main/java/io/papermc/paper/plugin/entrypoint/classloader/bytecode/EntityTypeRules.java @@ -2,6 +2,7 @@ import io.papermc.asm.ClassInfoProvider; import io.papermc.asm.RewriteRuleVisitorFactory; +import io.papermc.asm.rules.RewriteRule; import io.papermc.asm.rules.classes.EnumToInterfaceRule; import java.lang.constant.ClassDesc; import java.util.Map; @@ -13,7 +14,7 @@ import org.objectweb.asm.ClassWriter; import org.objectweb.asm.Opcodes; -public final class ClassToInterfaceRules { +public final class EntityTypeRules { private static final RewriteRuleVisitorFactory VISITOR_FACTORY = RewriteRuleVisitorFactory.create( Opcodes.ASM9, @@ -23,11 +24,17 @@ public final class ClassToInterfaceRules { entry -> entry.getValue().describeConstable().orElseThrow() )); chain.then(new EnumToInterfaceRule(enums)); + + chain.then(RewriteRule.forOwnerClass(EntityType.class, factory -> { + factory.changeFieldToMethod("getUnknownInstance", null, true, e -> { // todo move method along CraftEntityType + e.match("UNKNOWN", EntityType.class.describeConstable().orElseThrow()); + }); + })); }, ClassInfoProvider.basic() ); - private ClassToInterfaceRules() { + private EntityTypeRules() { } public static ClassVisitor visitor(final ClassVisitor parent) { diff --git a/paper-server/src/main/java/io/papermc/paper/plugin/entrypoint/classloader/bytecode/PaperClassloaderBytecodeModifier.java b/paper-server/src/main/java/io/papermc/paper/plugin/entrypoint/classloader/bytecode/PaperClassloaderBytecodeModifier.java index d877267cd0ad..0cb774f72000 100644 --- a/paper-server/src/main/java/io/papermc/paper/plugin/entrypoint/classloader/bytecode/PaperClassloaderBytecodeModifier.java +++ b/paper-server/src/main/java/io/papermc/paper/plugin/entrypoint/classloader/bytecode/PaperClassloaderBytecodeModifier.java @@ -11,7 +11,7 @@ public byte[] modify(PluginMeta configuration, byte[] bytecode) { ApiVersion version = ApiVersion.getOrCreateVersion(configuration.getAPIVersion()); if (version.isOlderThanOrSameAs(ApiVersion.CLASS_TO_INTERFACE)) { - bytecode = ClassToInterfaceRules.processClass(bytecode); + bytecode = EntityTypeRules.processClass(bytecode); } return bytecode; } diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/CraftRegionAccessor.java b/paper-server/src/main/java/org/bukkit/craftbukkit/CraftRegionAccessor.java index ad24aaab0fee..9de46997a8ee 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/CraftRegionAccessor.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/CraftRegionAccessor.java @@ -441,7 +441,6 @@ public net.minecraft.world.entity.Entity createEntity(Locatio throw new IllegalArgumentException("Cannot spawn an entity for " + type.key().asString()); } - @SuppressWarnings("unchecked") public net.minecraft.world.entity.Entity createEntity(Location location, Class clazz, boolean randomizeData) throws IllegalArgumentException { Preconditions.checkArgument(location != null, "Location cannot be null"); Preconditions.checkArgument(clazz != null, "Entity class cannot be null"); diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/block/CraftCreatureSpawner.java b/paper-server/src/main/java/org/bukkit/craftbukkit/block/CraftCreatureSpawner.java index b824e8527bac..74fc5a731994 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/block/CraftCreatureSpawner.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/block/CraftCreatureSpawner.java @@ -63,7 +63,7 @@ public void setSpawnedType(EntityType entityType) { this.getSnapshot().getSpawner().nextSpawnData = new SpawnData(); return; } - Preconditions.checkArgument(entityType != EntityType.UNKNOWN, "Can't spawn EntityType %s from mob spawners!", entityType); + Preconditions.checkArgument(entityType != CraftEntityType.LegacyUnknownImpl.INSTANCE, "Can't spawn EntityType %s from mob spawners!", entityType); RandomSource rand = (this.isPlaced()) ? this.getWorldHandle().getRandom() : RandomSource.create(); this.getSnapshot().setEntityId(CraftEntityType.bukkitToMinecraft(entityType), rand); diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/block/CraftTrialSpawnerConfiguration.java b/paper-server/src/main/java/org/bukkit/craftbukkit/block/CraftTrialSpawnerConfiguration.java index 358c65f5b344..e805c6ff43f8 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/block/CraftTrialSpawnerConfiguration.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/block/CraftTrialSpawnerConfiguration.java @@ -88,7 +88,7 @@ public void setSpawnedType(EntityType entityType) { this.spawnPotentialsDefinition = WeightedList.of(); // need clear the spawnPotentials to avoid nextSpawnData being replaced later return; } - Preconditions.checkArgument(entityType != EntityType.UNKNOWN, "Can't spawn EntityType %s from mob spawners!", entityType); + Preconditions.checkArgument(entityType != CraftEntityType.LegacyUnknownImpl.INSTANCE, "Can't spawn EntityType %s from mob spawners!", entityType); SpawnData data = new SpawnData(); data.getEntityToSpawn().putString(Entity.TAG_ID, BuiltInRegistries.ENTITY_TYPE.getKey(CraftEntityType.bukkitToMinecraft(entityType)).toString()); diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftEntityType.java b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftEntityType.java index f5e3e6235593..5d835c629f98 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftEntityType.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftEntityType.java @@ -2,6 +2,7 @@ import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableBiMap; +import io.papermc.asm.rules.classes.LegacyEnum; import io.papermc.paper.attribute.UnmodifiableAttributeMap; import io.papermc.paper.registry.RegistryKey; import io.papermc.paper.util.LegacyEnumHolderable; @@ -73,12 +74,12 @@ public Attributable getDefaultAttributes() { /** * Implementation for the deprecated, API only, UNKNOWN entity type. - * As per {@link #bukkitToMinecraftHolder(EntityType)} it cannot be - * converted into an internal entity type and only serves backwards compatibility reasons. + * As per {@link #bukkitToMinecraftHolder(EntityType)} and {@link #bukkitToMinecraft(EntityType)} + * it cannot be converted into an internal entity type and only serves backwards compatibility reasons. */ @Deprecated(forRemoval = true, since = "1.21.11") @ApiStatus.ScheduledForRemoval(inVersion = "1.22") - public static class LegacyUnknownImpl implements EntityType { // todo legacy enum but getKey needs to be overridden, no vanilla holder + public static class LegacyUnknownImpl implements LegacyEnum, EntityType { public static final EntityType INSTANCE = new LegacyUnknownImpl(); @@ -93,9 +94,8 @@ public NamespacedKey getKey() { return null; } - /* @Override - public int compareTo(final EntityType other) { + public int compareTo(final LegacyUnknownImpl other) { return this.ordinal - other.ordinal(); } @@ -107,18 +107,18 @@ public String name() { @Override public int ordinal() { return this.ordinal; - }*/ + } @Override public boolean equals(final Object object) { if (object == null || getClass() != object.getClass()) return false; final LegacyUnknownImpl that = (LegacyUnknownImpl) object; - return ordinal == that.ordinal; + return this.ordinal == that.ordinal; } @Override public int hashCode() { - return Objects.hashCode(ordinal); + return Objects.hashCode(this.ordinal); } @Override @@ -177,7 +177,7 @@ public static EntityType minecraftToBukkit(net.minecraft.world.entity.EntityT } public static net.minecraft.world.entity.@Nullable EntityType bukkitToMinecraft(EntityType bukkit) { - if (bukkit == EntityType.UNKNOWN) { + if (bukkit == LegacyUnknownImpl.INSTANCE) { return null; } return CraftRegistry.bukkitToMinecraft(bukkit); @@ -188,7 +188,7 @@ public static EntityType minecraftHolderToBukkit(Holder> bukkitToMinecraftHolder(EntityType bukkit) { - if (bukkit == EntityType.UNKNOWN) { + if (bukkit == LegacyUnknownImpl.INSTANCE) { return null; } return CraftRegistry.bukkitToMinecraftHolder(bukkit); @@ -231,7 +231,7 @@ public short getTypeId() { @Deprecated // bytecode rewrites target this public static EntityType valueOf(String name) { if ("UNKNOWN".equals(name)) { - return EntityType.UNKNOWN; + return LegacyUnknownImpl.INSTANCE; } NamespacedKey key = NamespacedKey.fromString(name.toLowerCase(Locale.ROOT)); @@ -253,8 +253,9 @@ public static EntityType[] values() { return LegacyHolder.NUMERIC_IDS.inverse().get(id); } + @Deprecated private static class LegacyHolder { - @Deprecated + private static final ImmutableBiMap, Integer> NUMERIC_IDS = ImmutableBiMap., Integer>builder() .put(EntityType.ITEM, 1) .put(EntityType.EXPERIENCE_ORB, 2) diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftMinecartMobSpawner.java b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftMinecartMobSpawner.java index f051c44b7ce3..718c15daeb95 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftMinecartMobSpawner.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftMinecartMobSpawner.java @@ -54,7 +54,7 @@ public void setSpawnedType(EntityType entityType) { this.getHandle().getSpawner().nextSpawnData = new SpawnData(); return; } - Preconditions.checkArgument(entityType != EntityType.UNKNOWN, "Can't spawn EntityType %s from mob spawners!", entityType); + Preconditions.checkArgument(entityType != CraftEntityType.LegacyUnknownImpl.INSTANCE, "Can't spawn EntityType %s from mob spawners!", entityType); RandomSource rand = this.getHandle().level().getRandom(); this.getHandle().getSpawner().setEntityId(CraftEntityType.bukkitToMinecraft(entityType), this.getHandle().level(), rand, this.getHandle().blockPosition()); diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/generator/CraftLimitedRegion.java b/paper-server/src/main/java/org/bukkit/craftbukkit/generator/CraftLimitedRegion.java index 43530ce8a709..8d4923dbb07c 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/generator/CraftLimitedRegion.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/generator/CraftLimitedRegion.java @@ -33,8 +33,6 @@ import org.bukkit.event.entity.CreatureSpawnEvent; import org.bukkit.generator.LimitedRegion; import org.bukkit.util.BoundingBox; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; import org.slf4j.Logger; public class CraftLimitedRegion extends CraftRegionAccessor implements LimitedRegion { @@ -263,15 +261,9 @@ public E spawnEntity(Location location, org.bukkit.entity.Ent } @Override - public E spawn(@NotNull Location location, @NotNull Class clazz, boolean randomizeData, @Nullable Consumer function) { + protected E spawn0(Location location, Class clazz, Consumer function, CreatureSpawnEvent.SpawnReason reason, boolean randomizeData) throws IllegalArgumentException { Preconditions.checkArgument(this.isInRegion(location), "Coordinates %s, %s, %s are not in the region", location.getBlockX(), location.getBlockY(), location.getBlockZ()); - return super.spawn(location, clazz, randomizeData, function); - } - - @Override - public E spawn(Location location, Class clazz, Consumer function, CreatureSpawnEvent.SpawnReason reason) throws IllegalArgumentException { - Preconditions.checkArgument(this.isInRegion(location), "Coordinates %s, %s, %s are not in the region", location.getBlockX(), location.getBlockY(), location.getBlockZ()); - return super.spawn(location, clazz, function, reason); + return super.spawn0(location, clazz, function, reason, randomizeData); } @Override diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemFactory.java b/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemFactory.java index 4abee7b6d922..3e69d2aea3d2 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemFactory.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemFactory.java @@ -173,7 +173,7 @@ public ItemStack createItemStack(String input) throws IllegalArgumentException { @Override public Material getSpawnEgg(EntityType type) { - if (type == EntityType.UNKNOWN) { + if (type == CraftEntityType.LegacyUnknownImpl.INSTANCE) { return null; } net.minecraft.world.entity.EntityType nmsType = CraftEntityType.bukkitToMinecraft(type); diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/util/Commodore.java b/paper-server/src/main/java/org/bukkit/craftbukkit/util/Commodore.java index d83bb566cb55..760c61994685 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/util/Commodore.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/util/Commodore.java @@ -2,7 +2,7 @@ import com.google.common.base.Predicates; import com.google.common.io.ByteStreams; -import io.papermc.paper.plugin.entrypoint.classloader.bytecode.ClassToInterfaceRules; +import io.papermc.paper.plugin.entrypoint.classloader.bytecode.EntityTypeRules; import java.io.File; import java.io.FileOutputStream; import java.io.InputStream; @@ -227,7 +227,7 @@ public byte[] convert(byte[] b, final String pluginName, final ApiVersion plugin ClassVisitor visitor = cw; if (pluginVersion.isOlderThanOrSameAs(ApiVersion.CLASS_TO_INTERFACE)) { - visitor = ClassToInterfaceRules.visitor(visitor); + visitor = EntityTypeRules.visitor(visitor); } visitor = io.papermc.paper.pluginremap.reflect.ReflectionRemapper.visitor(visitor); // Paper