TechStudios TechStudios - 1 year ago 166
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;

Answer Source

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);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download