Skip to content

Custom GeckoLib Entity

Tslat edited this page Jul 12, 2024 · 7 revisions

This wiki page assumes you are in the Entity setting in your GeckoLib blockbench model. Learn how to change this here

Video Guides

Entity Animations

In order to create an entity with GeckoLib you need to do several things.

  1. Create the Entity class (extends LivingEntity or any subtype)
  2. Create the Renderer class (extends GeoEntityRenderer)
  3. Create the Model class (extends GeoModel)

This wiki almost exclusively uses Mojmap mappings. If you need to figure out the yarn name for a Mojmap class/field/method, check out the Mappings Website

Entity Class

Any GeckoLib object has to extend GeoAnimatable. This exposes two methods you need to override:

  • getAnimatableInstanceCache() - All you need to here is return a member field of type AnimatableInstanceCache. This needs to be passed in an instance of your entity (usually done by passing in this)
  • registerControllers - This method is called every time a new instance of your animatable object (in this case your entity) is created. So, you should create your animation controllers, register listeners, and do any initial setup here. Take a look at the example below for a more obvious example.

Entity Class Example

public class ExampleEntity extends PathfinderMob implements GeoEntity {
    private final AnimatableInstanceCache cache = GeckoLibUtil.createInstanceCache(this);

    public ExampleEntity(EntityType<? extends ExampleEntity> type, Level level) {
        super(type, level);
    }

	@Override
    public void registerControllers(AnimatableManager.ControllerRegistrar controllers) {
        controllers.add(new AnimationController<>(this, "idle", 5, state -> state.setAndContinue(DefaultAnimations.IDLE)));
    }

    @Override
    public AnimatableInstanceCache getAnimatableInstanceCache() {
        return this.cache;
    }
}

Registering the Entity

To register the entity, use Deferred Registries for Forge and for Fabric see HERE.

Renderer

Entity renderers are fairly simple. All you need to do is create a renderer class that extends GeoEntityRenderer, like this:

    public class ExampleGeoRenderer extends GeoEntityRenderer<GeoExampleEntity> {
        public ExampleGeoRenderer(EntityRendererProvider.Context renderManager) {
            super(renderManager, new ExampleEntityModel());
        }
    }

Make sure to pass in the correct model class into the super constructor.

Registering the Renderer

If you don't register the renderer, your game will crash. To register your renderer, place this method call in your EntityRenderersEvent.RegisterRenderers event handler (or onInitializeClient in Fabric):

Forge

    @SubscribeEvent
    public static void registerRenderers(final EntityRenderersEvent.RegisterRenderers event) {
        event.registerEntityRenderer(EntityRegistry.EXAMPLE_ENTITY.get(), ExampleGeoRenderer::new);
    }

Fabric

    @Override
    public void onInitializeClient() {
        EntityRendererRegistry.register(EntityRegistry.EXAMPLE_ENTITY, ExampleGeoRenderer::new);
    }

Model

Entity models in GeckoLib are the same as models for any other animation type. See the article on models.

Table of Contents

Geckolib 3
Geckolib 4

Hosted By: Cloudsmith

Package repository hosting is graciously provided by Cloudsmith.

Cloudsmith is the only fully hosted, cloud-native, universal package management solution that enables your organization to create, store and share packages in any format, to any place, with total confidence.

Clone this wiki locally