From ef20430e54b3a233192932c6e668ff87de76e95c Mon Sep 17 00:00:00 2001 From: TheMode Date: Thu, 9 Jun 2022 21:41:28 +0200 Subject: [PATCH] Use ofEntries for EntityType meta Signed-off-by: TheMode --- .../server/entity/EntityTypeImpl.java | 239 +++++++++--------- 1 file changed, 120 insertions(+), 119 deletions(-) diff --git a/src/main/java/net/minestom/server/entity/EntityTypeImpl.java b/src/main/java/net/minestom/server/entity/EntityTypeImpl.java index e912ed0bb..75f302d57 100644 --- a/src/main/java/net/minestom/server/entity/EntityTypeImpl.java +++ b/src/main/java/net/minestom/server/entity/EntityTypeImpl.java @@ -38,10 +38,11 @@ import net.minestom.server.registry.Registry; import org.jetbrains.annotations.NotNull; import java.util.Collection; -import java.util.HashMap; import java.util.Map; import java.util.function.BiFunction; +import static java.util.Map.entry; + record EntityTypeImpl(Registry.EntityEntry registry) implements EntityType { private static final Registry.Container CONTAINER = Registry.createContainer(Registry.Resource.ENTITIES, (namespace, properties) -> new EntityTypeImpl(Registry.entity(namespace, properties))); @@ -67,126 +68,126 @@ record EntityTypeImpl(Registry.EntityEntry registry) implements EntityType { return ENTITY_META_SUPPLIER.get(entityType.name()).apply(entity, metadata); } - private static Map> createMetaMap() { - Map> supplier = new HashMap<>(); - supplier.put("minecraft:area_effect_cloud", AreaEffectCloudMeta::new); - supplier.put("minecraft:armor_stand", ArmorStandMeta::new); - supplier.put("minecraft:arrow", ArrowMeta::new); - supplier.put("minecraft:axolotl", AxolotlMeta::new); - supplier.put("minecraft:bat", BatMeta::new); - supplier.put("minecraft:bee", BeeMeta::new); - supplier.put("minecraft:blaze", BlazeMeta::new); - supplier.put("minecraft:boat", BoatMeta::new); - supplier.put("minecraft:cat", CatMeta::new); - supplier.put("minecraft:cave_spider", CaveSpiderMeta::new); - supplier.put("minecraft:chicken", ChickenMeta::new); - supplier.put("minecraft:cod", CodMeta::new); - supplier.put("minecraft:cow", CowMeta::new); - supplier.put("minecraft:creeper", CreeperMeta::new); - supplier.put("minecraft:dolphin", DolphinMeta::new); - supplier.put("minecraft:donkey", DonkeyMeta::new); - supplier.put("minecraft:dragon_fireball", DragonFireballMeta::new); - supplier.put("minecraft:drowned", DrownedMeta::new); - supplier.put("minecraft:elder_guardian", ElderGuardianMeta::new); - supplier.put("minecraft:end_crystal", EndCrystalMeta::new); - supplier.put("minecraft:ender_dragon", EnderDragonMeta::new); - supplier.put("minecraft:enderman", EndermanMeta::new); - supplier.put("minecraft:endermite", EndermiteMeta::new); - supplier.put("minecraft:evoker", EvokerMeta::new); - supplier.put("minecraft:evoker_fangs", EvokerFangsMeta::new); - supplier.put("minecraft:experience_orb", ExperienceOrbMeta::new); - supplier.put("minecraft:eye_of_ender", EyeOfEnderMeta::new); - supplier.put("minecraft:falling_block", FallingBlockMeta::new); - supplier.put("minecraft:firework_rocket", FireworkRocketMeta::new); - supplier.put("minecraft:fox", FoxMeta::new); - supplier.put("minecraft:ghast", GhastMeta::new); - supplier.put("minecraft:giant", GiantMeta::new); - supplier.put("minecraft:glow_item_frame", GlowItemFrameMeta::new); - supplier.put("minecraft:glow_squid", GlowSquidMeta::new); - supplier.put("minecraft:goat", GoatMeta::new); - supplier.put("minecraft:guardian", GuardianMeta::new); - supplier.put("minecraft:hoglin", HoglinMeta::new); - supplier.put("minecraft:horse", HorseMeta::new); - supplier.put("minecraft:husk", HuskMeta::new); - supplier.put("minecraft:illusioner", IllusionerMeta::new); - supplier.put("minecraft:iron_golem", IronGolemMeta::new); - supplier.put("minecraft:item", ItemEntityMeta::new); - supplier.put("minecraft:item_frame", ItemFrameMeta::new); - supplier.put("minecraft:fireball", FireballMeta::new); - supplier.put("minecraft:leash_knot", LeashKnotMeta::new); - supplier.put("minecraft:lightning_bolt", LightningBoltMeta::new); - supplier.put("minecraft:llama", LlamaMeta::new); - supplier.put("minecraft:llama_spit", LlamaSpitMeta::new); - supplier.put("minecraft:magma_cube", MagmaCubeMeta::new); - supplier.put("minecraft:marker", MarkerMeta::new); - supplier.put("minecraft:minecart", MinecartMeta::new); - supplier.put("minecraft:chest_minecart", ChestMinecartMeta::new); - supplier.put("minecraft:command_block_minecart", CommandBlockMinecartMeta::new); - supplier.put("minecraft:furnace_minecart", FurnaceMinecartMeta::new); - supplier.put("minecraft:hopper_minecart", HopperMinecartMeta::new); - supplier.put("minecraft:spawner_minecart", SpawnerMinecartMeta::new); - supplier.put("minecraft:tnt_minecart", TntMinecartMeta::new); - supplier.put("minecraft:mule", MuleMeta::new); - supplier.put("minecraft:mooshroom", MooshroomMeta::new); - supplier.put("minecraft:ocelot", OcelotMeta::new); - supplier.put("minecraft:painting", PaintingMeta::new); - supplier.put("minecraft:panda", PandaMeta::new); - supplier.put("minecraft:parrot", ParrotMeta::new); - supplier.put("minecraft:phantom", PhantomMeta::new); - supplier.put("minecraft:pig", PigMeta::new); - supplier.put("minecraft:piglin", PiglinMeta::new); - supplier.put("minecraft:piglin_brute", PiglinBruteMeta::new); - supplier.put("minecraft:pillager", PillagerMeta::new); - supplier.put("minecraft:polar_bear", PolarBearMeta::new); - supplier.put("minecraft:tnt", PrimedTntMeta::new); - supplier.put("minecraft:pufferfish", PufferfishMeta::new); - supplier.put("minecraft:rabbit", RabbitMeta::new); - supplier.put("minecraft:ravager", RavagerMeta::new); - supplier.put("minecraft:salmon", SalmonMeta::new); - supplier.put("minecraft:sheep", SheepMeta::new); - supplier.put("minecraft:shulker", ShulkerMeta::new); - supplier.put("minecraft:shulker_bullet", ShulkerBulletMeta::new); - supplier.put("minecraft:silverfish", SilverfishMeta::new); - supplier.put("minecraft:skeleton", SkeletonMeta::new); - supplier.put("minecraft:skeleton_horse", SkeletonHorseMeta::new); - supplier.put("minecraft:slime", SlimeMeta::new); - supplier.put("minecraft:small_fireball", SmallFireballMeta::new); - supplier.put("minecraft:snow_golem", SnowGolemMeta::new); - supplier.put("minecraft:snowball", SnowballMeta::new); - supplier.put("minecraft:spectral_arrow", SpectralArrowMeta::new); - supplier.put("minecraft:spider", SpiderMeta::new); - supplier.put("minecraft:squid", SquidMeta::new); - supplier.put("minecraft:stray", StrayMeta::new); - supplier.put("minecraft:strider", StriderMeta::new); - supplier.put("minecraft:egg", ThrownEggMeta::new); - supplier.put("minecraft:ender_pearl", ThrownEnderPearlMeta::new); - supplier.put("minecraft:experience_bottle", ThrownExperienceBottleMeta::new); - supplier.put("minecraft:potion", ThrownPotionMeta::new); - supplier.put("minecraft:trident", ThrownTridentMeta::new); - supplier.put("minecraft:trader_llama", TraderLlamaMeta::new); - supplier.put("minecraft:tropical_fish", TropicalFishMeta::new); - supplier.put("minecraft:turtle", TurtleMeta::new); - supplier.put("minecraft:vex", VexMeta::new); - supplier.put("minecraft:villager", VillagerMeta::new); - supplier.put("minecraft:vindicator", VindicatorMeta::new); - supplier.put("minecraft:wandering_trader", WanderingTraderMeta::new); - supplier.put("minecraft:witch", WitchMeta::new); - supplier.put("minecraft:wither", WitherMeta::new); - supplier.put("minecraft:wither_skeleton", WitherSkeletonMeta::new); - supplier.put("minecraft:wither_skull", WitherSkullMeta::new); - supplier.put("minecraft:wolf", WolfMeta::new); - supplier.put("minecraft:zoglin", ZoglinMeta::new); - supplier.put("minecraft:zombie", ZombieMeta::new); - supplier.put("minecraft:zombie_horse", ZombieHorseMeta::new); - supplier.put("minecraft:zombie_villager", ZombieVillagerMeta::new); - supplier.put("minecraft:zombified_piglin", ZombifiedPiglinMeta::new); - supplier.put("minecraft:player", PlayerMeta::new); - supplier.put("minecraft:fishing_bobber", FishingHookMeta::new); - return supplier; - } - @Override public String toString() { return name(); } + + private static Map> createMetaMap() { + return Map.>ofEntries( + entry("minecraft:area_effect_cloud", AreaEffectCloudMeta::new), + entry("minecraft:armor_stand", ArmorStandMeta::new), + entry("minecraft:arrow", ArrowMeta::new), + entry("minecraft:axolotl", AxolotlMeta::new), + entry("minecraft:bat", BatMeta::new), + entry("minecraft:bee", BeeMeta::new), + entry("minecraft:blaze", BlazeMeta::new), + entry("minecraft:boat", BoatMeta::new), + entry("minecraft:cat", CatMeta::new), + entry("minecraft:cave_spider", CaveSpiderMeta::new), + entry("minecraft:chicken", ChickenMeta::new), + entry("minecraft:cod", CodMeta::new), + entry("minecraft:cow", CowMeta::new), + entry("minecraft:creeper", CreeperMeta::new), + entry("minecraft:dolphin", DolphinMeta::new), + entry("minecraft:donkey", DonkeyMeta::new), + entry("minecraft:dragon_fireball", DragonFireballMeta::new), + entry("minecraft:drowned", DrownedMeta::new), + entry("minecraft:elder_guardian", ElderGuardianMeta::new), + entry("minecraft:end_crystal", EndCrystalMeta::new), + entry("minecraft:ender_dragon", EnderDragonMeta::new), + entry("minecraft:enderman", EndermanMeta::new), + entry("minecraft:endermite", EndermiteMeta::new), + entry("minecraft:evoker", EvokerMeta::new), + entry("minecraft:evoker_fangs", EvokerFangsMeta::new), + entry("minecraft:experience_orb", ExperienceOrbMeta::new), + entry("minecraft:eye_of_ender", EyeOfEnderMeta::new), + entry("minecraft:falling_block", FallingBlockMeta::new), + entry("minecraft:firework_rocket", FireworkRocketMeta::new), + entry("minecraft:fox", FoxMeta::new), + entry("minecraft:ghast", GhastMeta::new), + entry("minecraft:giant", GiantMeta::new), + entry("minecraft:glow_item_frame", GlowItemFrameMeta::new), + entry("minecraft:glow_squid", GlowSquidMeta::new), + entry("minecraft:goat", GoatMeta::new), + entry("minecraft:guardian", GuardianMeta::new), + entry("minecraft:hoglin", HoglinMeta::new), + entry("minecraft:horse", HorseMeta::new), + entry("minecraft:husk", HuskMeta::new), + entry("minecraft:illusioner", IllusionerMeta::new), + entry("minecraft:iron_golem", IronGolemMeta::new), + entry("minecraft:item", ItemEntityMeta::new), + entry("minecraft:item_frame", ItemFrameMeta::new), + entry("minecraft:fireball", FireballMeta::new), + entry("minecraft:leash_knot", LeashKnotMeta::new), + entry("minecraft:lightning_bolt", LightningBoltMeta::new), + entry("minecraft:llama", LlamaMeta::new), + entry("minecraft:llama_spit", LlamaSpitMeta::new), + entry("minecraft:magma_cube", MagmaCubeMeta::new), + entry("minecraft:marker", MarkerMeta::new), + entry("minecraft:minecart", MinecartMeta::new), + entry("minecraft:chest_minecart", ChestMinecartMeta::new), + entry("minecraft:command_block_minecart", CommandBlockMinecartMeta::new), + entry("minecraft:furnace_minecart", FurnaceMinecartMeta::new), + entry("minecraft:hopper_minecart", HopperMinecartMeta::new), + entry("minecraft:spawner_minecart", SpawnerMinecartMeta::new), + entry("minecraft:tnt_minecart", TntMinecartMeta::new), + entry("minecraft:mule", MuleMeta::new), + entry("minecraft:mooshroom", MooshroomMeta::new), + entry("minecraft:ocelot", OcelotMeta::new), + entry("minecraft:painting", PaintingMeta::new), + entry("minecraft:panda", PandaMeta::new), + entry("minecraft:parrot", ParrotMeta::new), + entry("minecraft:phantom", PhantomMeta::new), + entry("minecraft:pig", PigMeta::new), + entry("minecraft:piglin", PiglinMeta::new), + entry("minecraft:piglin_brute", PiglinBruteMeta::new), + entry("minecraft:pillager", PillagerMeta::new), + entry("minecraft:polar_bear", PolarBearMeta::new), + entry("minecraft:tnt", PrimedTntMeta::new), + entry("minecraft:pufferfish", PufferfishMeta::new), + entry("minecraft:rabbit", RabbitMeta::new), + entry("minecraft:ravager", RavagerMeta::new), + entry("minecraft:salmon", SalmonMeta::new), + entry("minecraft:sheep", SheepMeta::new), + entry("minecraft:shulker", ShulkerMeta::new), + entry("minecraft:shulker_bullet", ShulkerBulletMeta::new), + entry("minecraft:silverfish", SilverfishMeta::new), + entry("minecraft:skeleton", SkeletonMeta::new), + entry("minecraft:skeleton_horse", SkeletonHorseMeta::new), + entry("minecraft:slime", SlimeMeta::new), + entry("minecraft:small_fireball", SmallFireballMeta::new), + entry("minecraft:snow_golem", SnowGolemMeta::new), + entry("minecraft:snowball", SnowballMeta::new), + entry("minecraft:spectral_arrow", SpectralArrowMeta::new), + entry("minecraft:spider", SpiderMeta::new), + entry("minecraft:squid", SquidMeta::new), + entry("minecraft:stray", StrayMeta::new), + entry("minecraft:strider", StriderMeta::new), + entry("minecraft:egg", ThrownEggMeta::new), + entry("minecraft:ender_pearl", ThrownEnderPearlMeta::new), + entry("minecraft:experience_bottle", ThrownExperienceBottleMeta::new), + entry("minecraft:potion", ThrownPotionMeta::new), + entry("minecraft:trident", ThrownTridentMeta::new), + entry("minecraft:trader_llama", TraderLlamaMeta::new), + entry("minecraft:tropical_fish", TropicalFishMeta::new), + entry("minecraft:turtle", TurtleMeta::new), + entry("minecraft:vex", VexMeta::new), + entry("minecraft:villager", VillagerMeta::new), + entry("minecraft:vindicator", VindicatorMeta::new), + entry("minecraft:wandering_trader", WanderingTraderMeta::new), + entry("minecraft:witch", WitchMeta::new), + entry("minecraft:wither", WitherMeta::new), + entry("minecraft:wither_skeleton", WitherSkeletonMeta::new), + entry("minecraft:wither_skull", WitherSkullMeta::new), + entry("minecraft:wolf", WolfMeta::new), + entry("minecraft:zoglin", ZoglinMeta::new), + entry("minecraft:zombie", ZombieMeta::new), + entry("minecraft:zombie_horse", ZombieHorseMeta::new), + entry("minecraft:zombie_villager", ZombieVillagerMeta::new), + entry("minecraft:zombified_piglin", ZombifiedPiglinMeta::new), + entry("minecraft:player", PlayerMeta::new), + entry("minecraft:fishing_bobber", FishingHookMeta::new) + ); + } }