GeckoLib Documentation

repository·main·Indexed 21 days ago

https://github.com/bernie-g/geckolib

A specialized animation and rendering engine for Minecraft mods compatible with Forge, Fabric, and NeoForge. It provides advanced 3D keyframe animation capabilities, including support for 30+ easing functions, concurrent animations, sound and particle keyframe integration, and event keyframes. The library includes tools like the GeoItem interface for implementing animatable items and armor with support for network synchronization and perspective-aware rendering.

Tokens
916
Snippets
2
Records
7
Agent score
24%

What's inside GeckoLib

  1. Overview of GeckoLib

    main

    GeckoLib is an animation and rendering engine designed for Minecraft Mods. It enables developers to implement complex 3D keyframe-based animations.

    Key features include:

    • Support for 30+ easing functions.
    • Concurrent animation support (playing multiple animations at once).
    • Sound and particle keyframe integration.
    • Event keyframes for triggering logic during animations.

    GeckoLib is compatible with the following Minecraft modding loaders:

    • Forge
    • Fabric
    • NeoForge
  2. Install GeckoLib for Modding

    main

    For detailed installation instructions specifically for modders, please refer to the official GeckoLib Quick Reference wiki page. The README points to the following resource for setup guidance:

    https://wiki.geckolib.com/docs/geckolib5/quick-reference
  3. Enable perspective-aware animations for GeoItems

    main

    By default, GeoItem animations are not perspective-aware. If you want animations to change based on the ItemDisplayContext (e.g., how the item looks in a third-person view vs. first-person), you must:

    1. Override isPerspectiveAware() to return true.
    2. GeckoLib will then automatically use ContextBasedAnimatableInstanceCache, which manages separate AnimatableManager instances for each ItemDisplayContext.

    This allows you to use DataTickets.ITEM_RENDER_PERSPECTIVE to determine the current rendering context.

  4. Implement the GeoItem interface for item animations

    main

    To make a Minecraft Item (including armor) animatable using GeckoLib, implement the GeoItem interface. This interface extends SingletonGeoAnimatable, meaning animations are managed via a singleton pattern tied to the item type, but can be differentiated by unique IDs assigned to specific ItemStack instances.

    Key Concepts

    • ID Assignment: GeckoLib uses unique IDs stored in the ItemStack components to differentiate between different instances of the same item (e.g., two different swords having different animation states). Use GeoItem.getOrAssignId(stack, level) to ensure an ID is present.
    • Perspective Awareness: If your item needs to play different animations depending on how it is being viewed (e.g., in a GUI vs. held in hand), override isPerspectiveAware() to return true.
  5. Register a synced GeoItem animatable

    main

    To ensure your GeoItem animations are synchronized across the network, call GeoItem.registerSyncedAnimatable(this) inside the constructor of your item class.

    public class MyAnimatableItem extends Item implements GeoItem {
        public MyAnimatableItem(Properties properties) {
            super(properties);
            GeoItem.registerSyncedAnimatable(this);
        }
    
        // Implement required GeoItem/SingletonGeoAnimatable methods...
    }
    public class MyAnimatableItem extends Item implements GeoItem {
        public MyAnimatableItem(Properties properties) {
            super(properties);
            GeoItem.registerSyncedAnimatable(this);
        }
    }
  6. Manage ItemStack IDs for animations

    main

    GeckoLib tracks individual item instances using unique IDs stored in the ItemStack's data components. Use these static methods to handle ID retrieval and assignment:

    • getId(ItemStack stack): Retrieves the unique ID from the stack's components. Returns Long.MAX_VALUE if no ID is assigned.
    • getOrAssignId(ItemStack stack, ServerLevel level): Retrieves the ID, or if none exists, reserves a new ID from the AnimatableIdCache and assigns it to the stack's components.