diff --git a/src/main/kotlin/me/gabytm/minecraft/guihelper/functions/Items.kt b/src/main/kotlin/me/gabytm/minecraft/guihelper/functions/Items.kt index 23ea039..1ed87e8 100644 --- a/src/main/kotlin/me/gabytm/minecraft/guihelper/functions/Items.kt +++ b/src/main/kotlin/me/gabytm/minecraft/guihelper/functions/Items.kt @@ -51,6 +51,17 @@ private val potions = if (ServerVersion.IS_ANCIENT) { private val fireworkRocket = if (ServerVersion.IS_LEGACY) Material.valueOf("FIREWORK") else Material.FIREWORK_ROCKET private val fireworkStar = if (ServerVersion.IS_LEGACY) Material.valueOf("FIREWORK_CHARGE") else Material.FIREWORK_STAR +private val entityTypeByMaterial = if (ServerVersion.IS_LEGACY) { + emptyMap() +} else { + Material.values() + .filter { material -> material.name.endsWith("_SPAWN_EGG") } + .associateWith { material -> + @Suppress("DEPRECATION") + EntityType.fromName(material.name.replace("_SPAWN_EGG", "")) + } +} + /** * Gets a copy of the item the player is currently holding using the right method for each version * @since 2.0.0 @@ -162,15 +173,19 @@ val ItemStack.meta: ItemMeta? @Suppress("DEPRECATION") val ItemStack.spawnEggType: EntityType get() { - return if (ServerVersion.HAS_SPAWN_EGG_META) { - if (!hasItemMeta()) { - return EntityType.UNKNOWN - } + return when { + !ServerVersion.IS_LEGACY -> entityTypeByMaterial[this.type] - (itemMeta as SpawnEggMeta).spawnedType ?: EntityType.UNKNOWN - } else { - (data as SpawnEgg).spawnedType - } + ServerVersion.HAS_SPAWN_EGG_META -> { + if (!hasItemMeta()) { + return EntityType.UNKNOWN + } + + (this.itemMeta as SpawnEggMeta).spawnedType + } + + else -> (this.data as SpawnEgg).spawnedType + } ?: EntityType.UNKNOWN } /** diff --git a/src/main/kotlin/me/gabytm/minecraft/guihelper/generator/implementations/DeluxeMenusGenerator.kt b/src/main/kotlin/me/gabytm/minecraft/guihelper/generator/implementations/DeluxeMenusGenerator.kt index 50c1c4c..10ee46b 100644 --- a/src/main/kotlin/me/gabytm/minecraft/guihelper/generator/implementations/DeluxeMenusGenerator.kt +++ b/src/main/kotlin/me/gabytm/minecraft/guihelper/generator/implementations/DeluxeMenusGenerator.kt @@ -178,7 +178,7 @@ class DeluxeMenusGenerator( item.isFireworkStar -> { handFireworkStars(section, meta as FireworkEffectMeta) } - item.isSpawnEgg -> { + settings[Setting.SETTINGS__SET_ENTITY_TYPE_FOR_SPAWN_EGGS] && item.isSpawnEgg -> { section["entity_type"] = item.spawnEggType.name } } @@ -254,6 +254,10 @@ class DeluxeMenusGenerator( @Path("settings.saveItemFlagsAsList") val SETTINGS__SET_ITEM_FLAGS_AS_LIST = create(false) + @Comment("Starting with version 1.14.0, the option 'entity_type' is no longer required because each spawn egg has a different material") + @Path("settings.setEntityTypeForSpawnEggs") + val SETTINGS__SET_ENTITY_TYPE_FOR_SPAWN_EGGS = create(false) + } }