From 25413e80a1dafe8b500e95192e19ffa7f23cfb21 Mon Sep 17 00:00:00 2001 From: CraftBukkit/Spigot Date: Tue, 18 Jul 2023 21:28:02 +1000 Subject: [PATCH] #1224: Add ItemFactory#getSpawnEgg By: Jishuna --- .../inventory/CraftItemFactory.java | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) 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 f7b9155864..d163cfbfc3 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 @@ -6,11 +6,16 @@ import com.mojang.brigadier.exceptions.CommandSyntaxException; import net.minecraft.commands.arguments.item.ArgumentParserItemStack; import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.world.entity.EntityTypes; import net.minecraft.world.item.Item; +import net.minecraft.world.item.ItemMonsterEgg; import org.bukkit.Color; import org.bukkit.Material; import org.bukkit.configuration.serialization.ConfigurationSerialization; import org.bukkit.craftbukkit.util.CraftLegacy; +import org.bukkit.craftbukkit.util.CraftMagicNumbers; +import org.bukkit.craftbukkit.util.CraftNamespacedKey; +import org.bukkit.entity.EntityType; import org.bukkit.inventory.ItemFactory; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; @@ -437,4 +442,19 @@ public final class CraftItemFactory implements ItemFactory { public Material updateMaterial(ItemMeta meta, Material material) throws IllegalArgumentException { return ((CraftMetaItem) meta).updateMaterial(material); } + + @Override + public Material getSpawnEgg(EntityType type) { + if (type == EntityType.UNKNOWN) { + return null; + } + EntityTypes nmsType = BuiltInRegistries.ENTITY_TYPE.get(CraftNamespacedKey.toMinecraft(type.getKey())); + Item nmsItem = ItemMonsterEgg.byId(nmsType); + + if (nmsItem == null) { + return null; + } + + return CraftMagicNumbers.getMaterial(nmsItem); + } }