I created a class extending CreatureEntity:
public class FarmerEntity extends CreatureEntity {
public FarmerEntity(EntityType<? extends CreatureEntity> type, World worldIn) {
super(type, worldIn);
}
@Override
protected void registerGoals() {
this.goalSelector.addGoal(1, new LookAtGoal(this, PlayerEntity.class, 10.0F));
this.goalSelector.addGoal(2, new LookRandomlyGoal(this));
applyEntityAI();
}
protected void applyEntityAI() {
this.goalSelector.addGoal(1, new SwimGoal(this));
this.goalSelector.addGoal(2, new WaterAvoidingRandomWalkingGoal(this, 1.0D));
}
@Override
protected void registerAttributes() {
super.registerAttributes();
this.getAttribute(SharedMonsterAttributes.MAX_HEALTH).setBaseValue(20.0D);
}
}
I then registered entity types:
public class EntityTypes {
public static final EntityType<FarmerEntity> FARMER = null;
@Mod.EventBusSubscriber(modid = Utils.MODID, bus = Bus.MOD)
public static class RegistrationHandler {
/**
* Register this mod's {@link Entity} types.
*
* @param event The event
*/
@SubscribeEvent
public static void registerEntities(final RegistryEvent.Register<EntityType<?>> event) {
final EntityType<FarmerEntity> farmer = build(
"farmer",
EntityType.Builder.<FarmerEntity>create((FarmerEntity::new), EntityClassification.MISC)
.size(0.5f, 0.5f)
);
event.getRegistry().registerAll(
farmer
);
}
/**
* Build an {@link EntityType} from a {@link EntityType.Builder} using the specified name.
*
* @param name The entity type name
* @param builder The entity type builder to build
* @return The built entity type
*/
private static <T extends Entity> EntityType<T> build(final String name, final EntityType.Builder<T> builder) {
final ResourceLocation registryName = new ResourceLocation(Utils.MODID, name);
final EntityType<T> entityType = builder
.build(registryName.toString());
entityType.setRegistryName(registryName);
return entityType;
}
}
}
And finally made a class implementing IRenderFactory:
public class RenderFarmerEntity implements IRenderFactory<FarmerEntity> {
@Override
public EntityRenderer<? super FarmerEntity> createRenderFor(EntityRendererManager manager) {
return Minecraft.getInstance().getRenderManager().getRenderer(RabbitEntity.class);
}
}