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, 0xc4c4c4, 0xadadad, new FabricItemSettings().group(ItemGroup.MISC));
}

:!: This example is used for versions before 1.19.3, as Minecraft 1.19.3 directly added iron golem spawn eggs. However, you can create spawn eggs for other entity types. In 1.19.3, remember to remove the group method invoke. To add the spawn egg to item groups in 1.19.3, see itemgroup.

The spawn egg item takes an entity type, a primary and secondary color, and an item settings option.

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, 0xc4c4c4, 0xadadad, new FabricItemSettings().group(ItemGroup.MISC));
 
	@Override
	public void onInitialize() {
		Registry.register(Registry.ITEM, new Identifier("tutorial", "iron_golem_spawn_egg"), IRON_GOLEM_SPAWN_EGG);
                // For versions above 1.19.3, replace ''Registry.ITEM'' with ''Registries.ITEM''.
	}
}

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/tutorial/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/tutorial/lang/en_us.json
{
    "item.tutorial.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: 2023/01/15 01:33 by solidblock