User Tools

Site Tools




Items and Item Groups

Blocks and Block Entities



World Generation




Tutorials for Minecraft 1.14



Fabric Сontributors

If you'd like to contribute to Fabric, you might be interested in these links:

Extremely Strange People

Wiki Meta

  • Wiki Meta - Starting point for contributing to the wiki
  • Wiki Agenda - See what is on the current agenda, and what other contributors are currently working on.

Adding an Entity


Entities are the next step to take after adding an item and block to your game.

To add an entity, you will need 3 primary classes:

  • an Entity class, which gives your creature logic/AI
  • a Renderer class, which allows you to connect your entity to a model
  • a Model class, which is what your player sees in the game

We're going to be creating a cookie creeper that launches cookies everywhere when it explodes.

Registering an Entity

Unlike blocks & items, you basically always want a class fully dedicated to your entity. We're making a creeper clone, so we'll make our entity class extend CreeperEntity:

public class CookieCreeperEntity extends CreeperEntity {

Your IDE should instruct you to create a constructor matching the super – do that now.

To register your entity, we'll use Registry.ENTITY_TYPE. To get the required registry instance, you can either use EntityType.Builder or FabricEntityTypeBuilder – we recommend using the second one.

  1. public static final EntityType<CookieCreeperEntity> COOKIE_CREEPER =
  2. Registry.register(
  3. Registry.ENTITY_TYPE,
  4. new Identifier("wiki_entity", "cookie_creeper"),
  5. FabricEntityTypeBuilder.create(EntityCategory.AMBIENT, CookieCreeperEntity::new).size(EntityDimensions.fixed(1, 2)).build()
  6. );

The size() method allows you to set the hitbox of your entity. A creeper is 1 block wide and 2 blocks tall, so we'll use (1, 2).

If you load up your game at this point, you will be able to use /summon to see your creation. If all went right, it should appear as a normal creeper. I would not recommend going into survival.

Creating a renderer

Our Cookie creeper automatically has a model because it extended the Creeper class. We're going to change the skin to a cookie skin instead of the normal green camo color.

First, create a MobEntityRenderer class. MobEntityRenderer has 2 generic types: the entity & model. Because we're using the Creeper model to start, we'll also have to tell Creeper model this is not a Creeper Entity by giving it a type as well.

  1. public class CookieCreeperRenderer extends MobEntityRenderer<CookieCreeperEntity, CreeperEntityModel<CookieCreeperEntity>> {
  2. [...]
  3. }

You'll need to override the getTexture method as well as adding in the constructor. The constructor, by default, has 3 arguments (EntityRenderDispatcher, EntityModel, float), but we can remove the last 2 and create them ourselves:

public CookieCreeperRenderer(EntityRenderDispatcher entityRenderDispatcher_1)
    super(entityRenderDispatcher_1, new CreeperEntityModel<>(), 1);

For the getTexture method, you need to return your model's texture. If it is null, your entity will be invisible. This is a 100% guaranteed way to spend 3 hours trying to figure out why your model is not working. For your convenience, I have created a Cookie Creeper texture available to all, which you can download from here.

The default entity texture folder convention is: textures/entity/entity_name/entity.png. Here's an example implementation:

  1. @Override
  2. protected Identifier getTexture(CookieCreeperEntity cookieCreeperEntity)
  3. {
  4. return new Identifier("wiki_entity:textures/entity/cookie_creeper/creeper.png");
  5. }

with the file being stored at resources/assets/wiki_entity/textures/entity/cookie_creeper/creeper.png.

Finally, you'll need to connect your entity to your renderer. As rendering only happens client-side, you should always do this kind of work in a ClientModInitializer:

EntityRendererRegistry.INSTANCE.register(ModEntities.COOKIE_CREEPER, (entityRenderDispatcher, context) -> new CookieCreeperRenderer(entityRenderDispatcher));

This links our entity to our new renderer class. If you load into the game, you should see our new friend:

If you wanted to use your own model, you could create a new class that extends EntityModel and exchange the Creeper model in our renderer for it. This is fairly complex and will be covered in a separate tutorial.

Adding a Spawn Egg

To give your entity a spawn egg, simply create and register a SpawnEggItem. Spawn eggs have a primary color and a secondary color. The primary color is the background color of the egg, and the secondary color is the color of the spots.

Registry.register(Registry.ITEM, new Identifier("wiki_entity", "cookie_creeper_spawn_egg"), new SpawnEggItem(ModEntities.COOKIE_CREEPER, 0x0DA70B, 0x73420E, new Item.Settings().group(ItemGroup.MISC)));

You also need to give your spawn egg a model at …/assets/wiki_entity/models/item/cookie_creeper_spawn_egg.json:

    "parent": "item/template_spawn_egg"

Also, remember to add a language translation entry for item.wiki_entity.cookie_creeper_spawn_egg.

tutorial/entity.txt · Last modified: 2020/02/15 22:25 by earthcomputer