User Tools

Site Tools


Sidebar

← Go back to the homepage

Fabric Tutorials

Setup

Basics

These pages are essential must-reads when modding with Fabric, and modding Minecraft in general, if you are new to modding, it is recommended you read the following.

Items

Blocks and Block Entities

Data Generation

World Generation

Commands

These pages will guide you through Mojang's Brigadier library which allows you to create commands with complex arguments and actions.

Events

These pages will guide you through using the many events included in Fabric API, and how to create your own events for you or other mods to use.

Entities

Fluids

Mixins & ASM

These pages will guide you through the usage of SpongePowered's Mixin library, which is a highly complex topic. We recommend you read these pages thoroughly.

Miscellaneous

Yarn

Contribute to Fabric

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 FabricItemSettings().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: 2022/10/21 17:21 by nexus-dino