Skip to content

GeckoLib

Gugas749 edited this page Nov 5, 2026 · 1 revision

GeckoLib

Base classes that already handle the animation cache, synced-animatable registration (items) and getTick. GeckoLib's API differs between versions, so these classes differ per jar:

NeoForge 1.21.1 Forge 1.20.1
GeckoLib packages software.bernie.geckolib.animation.*, .animatable.* software.bernie.geckolib.core.*
Item renderer hook createGeoRenderer(Consumer<GeoRenderProvider>) initializeClient(Consumer<IClientItemExtensions>)
Entity synced data defineSynchedData(SynchedEntityData.Builder) defineSynchedData()
Class What it is
AbyssGeoBase Interface extending GeoAnimatable, with createCache()
AbyssGeoItem Item + GeoItem: cache, registerSyncedAnimatable, getTick = render tick
AbyssGeoEntity Entity + GeoEntity: cache, getTick = tickCount

You only implement registerControllers (plus the renderer and the usual Entity methods).

Item — NeoForge 1.21.1

public class RuneStaffItem extends AbyssGeoItem {
    private static final RawAnimation IDLE = RawAnimation.begin().thenLoop("animation.rune_staff.idle");

    public RuneStaffItem() {
        super(new Item.Properties().stacksTo(1));
    }

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

    @Override
    public void createGeoRenderer(Consumer<GeoRenderProvider> consumer) {
        consumer.accept(new GeoRenderProvider() {
            private RuneStaffRenderer renderer;

            @Override
            public BlockEntityWithoutLevelRenderer getGeoItemRenderer() {
                if (renderer == null) renderer = new RuneStaffRenderer();
                return renderer;
            }
        });
    }
}

public class RuneStaffRenderer extends GeoItemRenderer<RuneStaffItem> {
    public RuneStaffRenderer() {
        // assets/mymod/geo/item/rune_staff.geo.json, animations/item/rune_staff.animation.json, textures/item/rune_staff.png
        super(new DefaultedItemGeoModel<>(ResourceLocation.fromNamespaceAndPath("mymod", "rune_staff")));
    }
}

Item — Forge 1.20.1

public class RuneStaffItem extends AbyssGeoItem {
    private static final RawAnimation IDLE = RawAnimation.begin().thenLoop("animation.rune_staff.idle");

    public RuneStaffItem() {
        super(new Item.Properties().stacksTo(1));
    }

    @Override
    public void registerControllers(AnimatableManager.ControllerRegistrar controllers) {   // core.animation.*
        controllers.add(new AnimationController<>(this, "main", 0, state -> state.setAndContinue(IDLE)));
    }

    @Override
    public void initializeClient(Consumer<IClientItemExtensions> consumer) {
        consumer.accept(new IClientItemExtensions() {
            private RuneStaffRenderer renderer;

            @Override
            public BlockEntityWithoutLevelRenderer getCustomRenderer() {
                if (renderer == null) renderer = new RuneStaffRenderer();
                return renderer;
            }
        });
    }
}

// renderer: same as NeoForge, but new ResourceLocation("mymod", "rune_staff")

Entity (both; the differences are commented)

public class VortexEntity extends AbyssGeoEntity {
    private static final RawAnimation SPIN = RawAnimation.begin().thenLoop("animation.vortex.spin");

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

    @Override
    public void registerControllers(AnimatableManager.ControllerRegistrar controllers) {
        controllers.add(new AnimationController<>(this, "spin", 0, state -> state.setAndContinue(SPIN)));
    }

    // NeoForge 1.21.1:
    @Override protected void defineSynchedData(SynchedEntityData.Builder builder) {}
    // Forge 1.20.1 instead:
    // @Override protected void defineSynchedData() {}

    @Override protected void readAdditionalSaveData(CompoundTag tag) {}
    @Override protected void addAdditionalSaveData(CompoundTag tag) {}
}

// Client: EntityRenderersEvent.RegisterRenderers → event.registerEntityRenderer(MyEntities.VORTEX.get(), VortexRenderer::new)
public class VortexRenderer extends GeoEntityRenderer<VortexEntity> {
    public VortexRenderer(EntityRendererProvider.Context ctx) {
        super(ctx, new DefaultedEntityGeoModel<>(ResourceLocation.fromNamespaceAndPath("mymod", "vortex")));
    }
}

Mobs and other entity types

AbyssGeoEntity extends plain Entity. For a Mob, Monster or Animal, implement AbyssGeoBase + GeoEntity on your own class and use createCache():

public class ShadeMob extends Monster implements AbyssGeoBase, GeoEntity {
    private final AnimatableInstanceCache cache = createCache();

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

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

    @Override
    public void registerControllers(AnimatableManager.ControllerRegistrar controllers) {
        controllers.add(new AnimationController<>(this, "move", 5, state ->
                state.setAndContinue(state.isMoving() ? WALK : IDLE)));
    }
}

Clone this wiki locally