TechStudios TechStudios - 8 months ago 66
Java Question

Bukkit Custom Inventory spawn eggs

How do you put a Creeper spawn egg into a custom inventory? Can you continue my lines of code so I understand what you did to do it? For additional information, the creeper spawn egg ID is 383:50.

Player player = (Player) sender;
Inventory inv = Bukkit.createInventory(null, 27, "Disguise Menu");

ItemStack spawnItem = nameItem(Material.MONSTER_EGG, ChatColor.AQUA + "Admin Vanish");

inv.setItem(4, spawnItem);
return true;


To create your SpawnEgg ItemStack you should do the following:

ItemStack stack = new ItemStack(Material.MONSTER_EGG, 1, EntityType.CREEPER.getTypeId());

That creates an MonsterEgg for a Creeper.

To rename it:

ItemMeta meta = stack.getItemMeta();
meta.setDisplayName(ChatColor.AQUA + "Creeper Egg");

To add that to your custom inventory, you can do

inv.setItem(4, stack);