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).
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''. } }
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:
{ "parent": "item/template_spawn_egg" }
Make sure to also add this to your lang file.
{ "item.tutorial.iron_golem_spawn_egg": "Iron Golem Spawn Egg" }
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.