From d28a96121646e4a1c2374923c0967904fe62c108 Mon Sep 17 00:00:00 2001 From: Christian Koop Date: Sat, 1 Jul 2023 13:51:20 +0200 Subject: [PATCH] Re-implement `CompatibleMaterial#getEggType` --- .../compatibility/CompatibleMaterial.java | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/Compatibility/src/main/java/com/craftaro/core/compatibility/CompatibleMaterial.java b/Compatibility/src/main/java/com/craftaro/core/compatibility/CompatibleMaterial.java index d1f48cc7..8988a588 100644 --- a/Compatibility/src/main/java/com/craftaro/core/compatibility/CompatibleMaterial.java +++ b/Compatibility/src/main/java/com/craftaro/core/compatibility/CompatibleMaterial.java @@ -47,6 +47,26 @@ public class CompatibleMaterial { return getMaterial(type.name() + "_SPAWN_EGG"); } + public static EntityType getEntityForSpawnEgg(XMaterial material) { + if (!material.name().endsWith("_SPAWN_EGG")) { + throw new IllegalArgumentException("Material is not a spawn egg"); + } + + String entityName = material.name().substring(0, material.name().length() - "_SPAWN_EGG".length()); + + if (entityName.equals("MOOSHROOM")) { + entityName = "MUSHROOM_COW"; + } else if (entityName.equals("ZOMBIE_PIGMAN")) { + entityName = "PIG_ZOMBIE"; + } + + try { + return EntityType.valueOf(entityName); + } catch (IllegalArgumentException ignore) { + } + return null; + } + public static @Nullable XMaterial getYieldForCrop(XMaterial material) { switch (material) { case BEETROOTS: