Spent a few too many minutes making a spawn egg switch case, and figured some other poor soul will save a few minutes with this: I also added separated sections for fish buckets and eggs so you don't have to separate if you need different logic. Spoiler: isSpawnEgg(Material) Code (Text): public static boolean isSpawnEgg(@NotNull final Material m) { if (m == null) return false; switch (m) { case BAT_SPAWN_EGG: case BEE_SPAWN_EGG: case BLAZE_SPAWN_EGG: case CAT_SPAWN_EGG: case CAVE_SPIDER_SPAWN_EGG: case CHICKEN_SPAWN_EGG: case COD_SPAWN_EGG: case COW_SPAWN_EGG: case CREEPER_SPAWN_EGG: case DOLPHIN_SPAWN_EGG: case DONKEY_SPAWN_EGG: case DROWNED_SPAWN_EGG: case ELDER_GUARDIAN_SPAWN_EGG: case ENDERMAN_SPAWN_EGG: case ENDERMITE_SPAWN_EGG: case EVOKER_SPAWN_EGG: case FOX_SPAWN_EGG: case GHAST_SPAWN_EGG: case GUARDIAN_SPAWN_EGG: case HORSE_SPAWN_EGG: case HUSK_SPAWN_EGG: case LLAMA_SPAWN_EGG: case MAGMA_CUBE_SPAWN_EGG: case MOOSHROOM_SPAWN_EGG: case MULE_SPAWN_EGG: case OCELOT_SPAWN_EGG: case PANDA_SPAWN_EGG: case PARROT_SPAWN_EGG: case PHANTOM_SPAWN_EGG: case PIG_SPAWN_EGG: case PILLAGER_SPAWN_EGG: case POLAR_BEAR_SPAWN_EGG: case PUFFERFISH_SPAWN_EGG: case RABBIT_SPAWN_EGG: case RAVAGER_SPAWN_EGG: case SALMON_SPAWN_EGG: case SHEEP_SPAWN_EGG: case SHULKER_SPAWN_EGG: case SILVERFISH_SPAWN_EGG: case SKELETON_HORSE_SPAWN_EGG: case SKELETON_SPAWN_EGG: case SLIME_SPAWN_EGG: case SPIDER_SPAWN_EGG: case SQUID_SPAWN_EGG: case STRAY_SPAWN_EGG: case TRADER_LLAMA_SPAWN_EGG: case TROPICAL_FISH_SPAWN_EGG: case TURTLE_SPAWN_EGG: case VEX_SPAWN_EGG: case VILLAGER_SPAWN_EGG: case VINDICATOR_SPAWN_EGG: case WANDERING_TRADER_SPAWN_EGG: case WITCH_SPAWN_EGG: case WITHER_SKELETON_SPAWN_EGG: case WOLF_SPAWN_EGG: case ZOMBIE_HORSE_SPAWN_EGG: case ZOMBIE_PIGMAN_SPAWN_EGG: case ZOMBIE_SPAWN_EGG: case ZOMBIE_VILLAGER_SPAWN_EGG: return true; case COD_BUCKET: case PUFFERFISH_BUCKET: case SALMON_BUCKET: case TROPICAL_FISH_BUCKET: return true; case EGG: return true; default: return false; } } Also I made a hostile checker for spawn eggs if it interests you: Spoiler: isHostileEgg(Material) Code (Text): public static boolean isHostileEgg(@NotNull final Material m) { if (m == null) return false; switch (m) { case BLAZE_SPAWN_EGG: case CAVE_SPIDER_SPAWN_EGG: case DROWNED_SPAWN_EGG: case CREEPER_SPAWN_EGG: case ENDERMITE_SPAWN_EGG: case ELDER_GUARDIAN_SPAWN_EGG: case EVOKER_SPAWN_EGG: case GHAST_SPAWN_EGG: case GUARDIAN_SPAWN_EGG: case HUSK_SPAWN_EGG: case MAGMA_CUBE_SPAWN_EGG: case PHANTOM_SPAWN_EGG: case PILLAGER_SPAWN_EGG: case RAVAGER_SPAWN_EGG: case SHULKER_SPAWN_EGG: case SILVERFISH_SPAWN_EGG: case SKELETON_SPAWN_EGG: case SLIME_SPAWN_EGG: case SPIDER_SPAWN_EGG: case STRAY_SPAWN_EGG: case VEX_SPAWN_EGG: case VINDICATOR_SPAWN_EGG: case WITCH_SPAWN_EGG: case WITHER_SKELETON_SPAWN_EGG: case ZOMBIE_SPAWN_EGG: case ZOMBIE_VILLAGER_SPAWN_EGG: return true; case ENDERMAN_SPAWN_EGG: case ZOMBIE_PIGMAN_SPAWN_EGG: return true; case BEE_SPAWN_EGG: case DOLPHIN_SPAWN_EGG: case LLAMA_SPAWN_EGG: case POLAR_BEAR_SPAWN_EGG: case PUFFERFISH_SPAWN_EGG: case TRADER_LLAMA_SPAWN_EGG: case WOLF_SPAWN_EGG: return false; default: return false; } }
Because EGG and DRAGON_EGG are not spawn eggs and there may be more items added in the future with a name ending on 'EGG'. This resource provides a nice utility method. Edit: I just found out about the Tag<T> class, though there is no provided instance for spawn eggs, I think it's likely it can be added if submitted in a pull request