Spawn Eggs
Learn how to register a spawn egg item.
WARNING
This page is written for version 1.21.10. Documentation for older versions may be incomplete.
PREREQUISITES
You must first understand how to create an item, which you can then turn into a spawn egg.
Spawn eggs are special items that, when used, spawn their corresponding mob. You can register one with the register method from your items class, by passing SpawnEggItem::new to it.
public static final SpawnEggItem CUSTOM_SPAWN_EGG = register(
"custom_spawn_egg",
SpawnEggItem::new,
new Item.Properties().spawnEgg(EntityType.FROG)
);
ItemGroupEvents.modifyEntriesEvent(CreativeModeTabs.SPAWN_EGGS)
.register(itemGroup -> itemGroup.accept(ModItems.CUSTOM_SPAWN_EGG));2
3
4
5
6
7

There are still a few things to do before it's ready: you must add a texture, an item model, a client item, a name, and add the spawn egg to the appropriate creative tab.
Adding a Texture
Create the 16x16 item texture in the assets/example-mod/textures/item directory, with the same file name as the id of the item: custom_spawn_egg.png. An example texture is provided below.
Adding a Model
Create the item model in the assets/example-mod/models/item directory, with the same file name as the id of the item: custom_spawn_egg.json.
{
"parent": "minecraft:item/generated",
"textures": {
"layer0": "example-mod:item/custom_spawn_egg"
}
}2
3
4
5
6
Creating the Client Item
Create the client item JSON in the assets/example-mod/items directory, with the same file name as the id of the item model: custom_spawn_egg.json.
{
"model": {
"type": "minecraft:model",
"model": "example-mod:item/custom_spawn_egg"
}
}2
3
4
5
6

Naming The Spawn Egg
To name the spawn egg, the translation key item.example-mod.custom_spawn_egg must be assigned a value. This process is similar to Naming The Item.
Create or edit JSON file at: src/main/resources/assets/example-mod/lang/en_us.json and put in the translation key, and its value:
{
"item.example-mod.custom_spawn_egg": "Custom Spawn Egg"
}2
3
Adding To A Creative Mode Tab
The spawn egg is added to the spawn egg CreativeModeTab in the initialize() method of the items class.
ItemGroupEvents.modifyEntriesEvent(CreativeModeTabs.SPAWN_EGGS)
.register(itemGroup -> itemGroup.accept(ModItems.CUSTOM_SPAWN_EGG));2

Check out Adding the Item to a Creative Tab for more detailed information.





