User Tools

Site Tools


Sidebar

Setup

Basics

Advanced

Items

Blocks and Block Entities

Fluids

Entities

World Generation

Recipe Types

Miscellaneous

Events

Mixins

Dynamic Data Generation

Tutorials for Minecraft 1.15

Tutorials for Minecraft 1.14

Documentation

tutorial:spawn_egg

Adding a Custom Spawn Egg

So, you finally finished making your custom entity, but you don't want to use commands every single time you need to test something with your entity.
That's where a spawn egg comes in. Adding a custom spawn egg is actually much easier than you might think. (It's definitely much easier than creating an entity).

Creating the Spawn Egg

For starters, create an instance of your item in your initializer class like so:

public class ExampleMod implements ModInitializer {
    public static final Item IRON_GOLEM_SPAWN_EGG = new SpawnEggItem(EntityType.IRON_GOLEM, 12895428, 11382189, new Item.Settings().group(ItemGroup.MISC));
}

The spawn egg item takes an entity type, a primary and secondary color, and an item settings option.
It also uses decimal coloring for the spawn egg colors. Not hexadecimal, just decimal.
You can also convert your color to a decimal color if you would like.

After you've done that, you will need to register your item:

public class ExampleMod implements ModInitializer {
 
	public static final Item IRON_GOLEM_SPAWN_EGG = new SpawnEggItem(EntityType.IRON_GOLEM, 12895428, 11382189, new Item.Settings().group(ItemGroup.MISC));
 
	@Override
	public void onInitialize() {
		Registry.register(Registry.ITEM, new Identifier("modid", "iron_golem_spawn_egg"), IRON_GOLEM_SPAWN_EGG);
	}
}

Giving the Spawn Egg a Texture

If you ran the game now, your spawn egg wouldn't have a texture, so to give it a texture you would need to do as follows:

src/main/resources/assets/modid/models/item/iron_golem_spawn_egg.json
{
  "parent": "item/template_spawn_egg"
}

Make sure to also add this to your lang file.

src/main/resources/assets/modid/lang/en_us.json
{
    "item.modid.iron_golem_spawn_egg": "Iron Golem Spawn Egg"
}

Finished!

And with that your spawn egg should be complete! Just launch the game and go into the tab where you put your spawn egg and it should be there! Now you don't have to use commands to summon your entity every single time.

tutorial/spawn_egg.txt · Last modified: 2021/07/18 18:01 by daviddevsdumbstuff