### Example Stateless Entity Implementation Source: https://wiki.geckolib.com/docs/geckolib5/miscellaneous/stateless-animations Demonstrates how to implement the StatelessGeoEntity interface for an entity. This is the base setup required before defining animation logic. ```java public class ExampleEntity extends PathfinderMob implements StatelessGeoEntity { //... } ``` -------------------------------- ### Creating a Basic Advanced Renderer Class Source: https://wiki.geckolib.com/docs/geckolib5/entities/the-entity-renderer Start creating a custom renderer by extending `GeoEntityRenderer`. This is the base for adding custom rendering logic. ```java public class ExampleEntityRenderer extends GeoEntityRenderer { } ``` -------------------------------- ### Client Setup for Fabric Source: https://wiki.geckolib.com/docs/geckolib5/items/copy-paste-templates This snippet demonstrates how to set up the GeoRenderProvider for an item in a Fabric environment during client initialization. It uses a memoized supplier for the renderer. ```java @Override public void onInitializeClient() { ItemRegistry.EXAMPLE_ITEM.geoRenderProvider.setValue(new GeoRenderProvider() { private final Supplier> renderer = Suppliers.memoize(() -> new GeoItemRenderer<>(ExampleItem.this)); @Override public @Nullable GeoItemRenderer getGeoItemRenderer() { return this.renderer.get(); } }); } ``` -------------------------------- ### Create Basic Custom BlockEntity Renderer Class Source: https://wiki.geckolib.com/docs/geckolib5/blocks/the-blockentity-renderer Start creating a custom renderer by extending `GeoBlockRenderer` for your BlockEntity. ```java public class ExampleBlockRenderer extends GeoBlockRenderer { } ``` -------------------------------- ### GeoModel Asset Path (Pre-GeckoLib 5) Source: https://wiki.geckolib.com/docs/geckolib5/updating/noteworthy/geomodel-asset-paths This example shows the traditional method of defining GeoModel asset paths before GeckoLib 5, requiring explicit prefixes and suffixes. ```java @Override public ResourceLocation getModelResource(GeoRenderState renderState) { return ResourceLocation.fromNamespaceAndPath(ExampleMod.MOD_ID, "geckolib/animations/my_model.geo.json"); } ``` -------------------------------- ### Example Forge BlockEntity Class Source: https://wiki.geckolib.com/docs/geckolib5/blocks/copy-paste-templates Template for a Forge BlockEntity. This includes the necessary setup for GeckoLib's animation system. ```java public class ExampleBlockEntity extends BlockEntity { private final AnimatableInstanceCache geoCache = GeckoLibUtil.createInstanceCache(this); public ExampleBlockEntity(BlockPos pos, BlockState state) { super(BlockEntityRegistry.EXAMPLE_BLOCK_ENTITY.get(), pos, state); } @Override public void registerControllers(final AnimatableManager.ControllerRegistrar controllers) { } @Override public AnimatableInstanceCache getAnimatableInstanceCache() { return this.geoCache; } } ``` -------------------------------- ### Example Fabric BlockEntity Class Source: https://wiki.geckolib.com/docs/geckolib5/blocks/copy-paste-templates Template for a Fabric BlockEntity. This includes the necessary setup for GeckoLib's animation system. ```java public class ExampleBlockEntity extends BlockEntity { private final AnimatableInstanceCache geoCache = GeckoLibUtil.createInstanceCache(this); public ExampleBlockEntity(BlockPos pos, BlockState state) { super(BlockEntityRegistry.EXAMPLE_BLOCK_ENTITY, pos, state); } @Override public void registerControllers(final AnimatableManager.ControllerRegistrar controllers) { } @Override public AnimatableInstanceCache getAnimatableInstanceCache() { return this.geoCache; } } ``` -------------------------------- ### Registering Entity Renderer (Forge/NeoForge - Option 1) Source: https://wiki.geckolib.com/docs/geckolib5/entities/copy-paste-templates Template for registering a GeoEntityRenderer in a Forge or NeoForge environment. This example assumes the entity type is accessible via EntityRegistry.EXAMPLE_ENTITY.get(). ```java // Registering the renderer context -> new GeoEntityRenderer<>(context, EntityRegistry.EXAMPLE_ENTITY.get()); ``` -------------------------------- ### Example DefaultedItemGeoModel Usage Source: https://wiki.geckolib.com/docs/geckolib5/concepts/geomodels/defaulted-geomodel Demonstrates how to use the DefaultedItemGeoModel to automatically generate resource paths for item assets. Place your assets in the specified locations based on the provided Identifier. ```java new DefaultedItemGeoModel(Identifier.fromNamespaceAndPath(ExampleMod.MOD_ID, "example_item")); ``` -------------------------------- ### Client Setup for Fabric Source: https://wiki.geckolib.com/docs/geckolib5/armor/copy-paste-templates This snippet shows how to set up the `GeoRenderProvider` for an item on the client side using Fabric's initialization. It assigns a new `GeoRenderProvider` instance to the item's `geoRenderProvider` field. ```java @Override public void onInitializeClient() { ItemRegistry.EXAMPLE_ITEM.geoRenderProvider.setValue(new GeoRenderProvider() { private final Supplier> renderer = Suppliers.memoize(() -> new GeoArmorRenderer<>(ItemRegistry.EXAMPLE_ARMOR_ITEM)); @Override public @Nullable GeoArmorRenderer getGeoArmorRenderer(ItemStack itemStack, EquipmentSlot equipmentSlot) { return this.renderer.get(); } }); } ``` -------------------------------- ### Blockstate JSON Example Source: https://wiki.geckolib.com/docs/geckolib5/blocks/copy-paste-templates Standard JSON structure for defining blockstates in Minecraft. ```json { "variants": { "": { "model": "examplemod:block/example_block" } } } ``` -------------------------------- ### Example DefaultedEntityGeoModel Usage Source: https://wiki.geckolib.com/docs/geckolib5/concepts/geomodels/defaulted-geomodel Shows how to use the DefaultedEntityGeoModel for automatic generation of entity asset paths. Ensure your assets are located according to the Identifier and GeckoLib's conventions. ```java new DefaultedEntityGeoModel(Identifier.fromNamespaceAndPath(ExampleMod.MOD_ID, "animal/example_animal")); ``` -------------------------------- ### Create Basic GeoModel Class Source: https://wiki.geckolib.com/docs/geckolib5/entities/replaced-entities/creating-the-geomodel Start by creating a Java class for your GeoModel. This class will represent your entity's model. ```java public class ExampleReplacedEntityGeoModel { } ``` -------------------------------- ### BlockState JSON Example Source: https://wiki.geckolib.com/docs/geckolib5/blocks/the-block-asset-files Use this JSON structure for your blockstate file. Replace 'examplemod' with your mod ID and 'example_block' with your block's registered ID. ```json { "variants": { "": { "model": "examplemod:block/example_block" } } } ``` -------------------------------- ### Handle Sound Keyframes with a Custom Handler Source: https://wiki.geckolib.com/docs/geckolib5/miscellaneous/keyframe-markers Implement a custom KeyframeEventHandler to play sounds at specific animation keyframes. This example shows how to register the handler and play a sound when triggered. ```java @Override public void registerControllers(AnimatableManager.ControllerRegistrar controllers) { controllers.add(new AnimationController<>(animTest -> PlayState.STOP) .setSoundKeyframeHandler(state -> { // Use helper method to avoid client-code in common class Player player = ClientUtil.getClientPlayer(); if (player != null) player.playSound(SoundRegistry.EXAMPLE_SOUND.get(), 1, 1); })); } ``` -------------------------------- ### GeoModel Asset Path (GeckoLib 5+) Source: https://wiki.geckolib.com/docs/geckolib5/updating/noteworthy/geomodel-asset-paths This example demonstrates the simplified asset path definition in GeckoLib 5 and later, where explicit prefixes and suffixes are no longer required for model and animation resources. ```java @Override public Identifier getModelResource(GeoRenderState renderState) { return Identifier.fromNamespaceAndPath(ExampleMod.MOD_ID, "my_model"); } ``` -------------------------------- ### Example Basic GeoModel Class Source: https://wiki.geckolib.com/docs/geckolib5/concepts/geomodels/basic-geomodel This Java code demonstrates how to create a basic `GeoModel` class. It extends `GeoModel` and implements the necessary methods to specify the resource paths for a model, animations, and textures. Caching of `Identifier` objects is shown for efficiency. ```java public class ExampleGeoModel extends GeoModel { // Looks for a model file at '/assets/examplemod/geckolib/models/example_entity.geo.json' private final Identifier modelPath = Identifier.fromNamespaceAndPath(ExampleMod.MOD_ID, "example_entity"); // Looks for an animations file at '/assets/examplemod/geckolib/animations/example_entity.animation.json' private final Identifier animationsPath = Identifier.fromNamespaceAndPath(ExampleMod.MOD_ID, "example_entity"); // Looks for a texture file at '/assets/examplemod/textures/example_entity.png' private final Identifier texturePath = Identifier.fromNamespaceAndPath(ExampleMod.MOD_ID, "example_entity.png"); @Override public Identifier getModelResource(GeoRenderState renderState) { return this.modelPath; } @Override public Identifier getAnimationResource(ExampleEntity animatable) { return this.animationsPath; } @Override public Identifier getTextureResource(GeoRenderState renderState) { return this.texturePath; } } ``` -------------------------------- ### Example Forge Block Class Source: https://wiki.geckolib.com/docs/geckolib5/blocks/copy-paste-templates Template for a Forge block that implements EntityBlock. Use this when your block requires a BlockEntity. ```java public class ExampleBlock extends Block implements EntityBlock { public ExampleBlock(BlockBehaviour.Properties properties) { super(properties); } @Nullable @Override public BlockEntity newBlockEntity(BlockPos pos, BlockState state) { return BlockEntityRegistry.EXAMPLE_BLOCK_ENTITY.get().create(pos, state); } } ``` -------------------------------- ### Example Fabric Block Class Source: https://wiki.geckolib.com/docs/geckolib5/blocks/copy-paste-templates Template for a Fabric block that implements EntityBlock. Use this when your block requires a BlockEntity. ```java public class ExampleBlock extends Block implements EntityBlock { public ExampleBlock(BlockBehaviour.Properties properties) { super(properties); } @Override public @Nullable BlockEntity newBlockEntity(BlockPos pos, BlockState state) { return BlockEntityRegistry.EXAMPLE_BLOCK_ENTITY.create(pos, state); } } ``` -------------------------------- ### Registering Entity Renderer (Fabric) Source: https://wiki.geckolib.com/docs/geckolib5/entities/copy-paste-templates Template for registering a GeoEntityRenderer in a Fabric environment. This example assumes the entity type is accessible via EntityRegistry.EXAMPLE_ENTITY. ```java // Registering the renderer context -> new GeoEntityRenderer<>(context, EntityRegistry.EXAMPLE_ENTITY); ``` -------------------------------- ### Client Setup for Forge/NeoForge (EntityRenderersEvent) Source: https://wiki.geckolib.com/docs/geckolib5/armor/copy-paste-templates This snippet demonstrates how to register the `GeoRenderProvider` using Forge's `EntityRenderersEvent.RegisterRenderers` event. It's used to associate the custom renderer with the item on the client. ```java @SubscribeEvent public static void registerRenderers(final EntityRenderersEvent.RegisterRenderers event) { ItemRegistry.EXAMPLE_ITEM.geoRenderProvider.setValue(new GeoRenderProvider() { private final Supplier> renderer = Suppliers.memoize(() -> new GeoArmorRenderer<>(ItemRegistry.EXAMPLE_ARMOR_ITEM.get())); @Override public @Nullable GeoArmorRenderer getGeoArmorRenderer(ItemStack itemStack, EquipmentSlot equipmentSlot) { return this.renderer.get(); } }); } ``` -------------------------------- ### Block Model JSON Example Source: https://wiki.geckolib.com/docs/geckolib5/blocks/copy-paste-templates Basic JSON structure for defining a block model in Minecraft, specifying textures. ```json { "textures": { "particle": "examplemod:block/example_block" } } ``` -------------------------------- ### Manually Animate a Bone using BoneSnapshots Source: https://wiki.geckolib.com/docs/geckolib5/concepts/geobones/bone-snapshots Example of animating a specific bone ('MyBoneName') by rotating it 45 degrees using BoneSnapshots. It is generally recommended to use Molang variables and JSON animations instead of manual manipulation. ```java @Override public void adjustModelBonesForRender(RenderPassInfo renderPassInfo, BoneSnapshots snapshots) { snapshots.ifPresent("MyBoneName", boneSnapshot -> { boneSnapshot.setRotX(45 * Mth.DEG_TO_RAD); }); } ``` -------------------------------- ### Molang Compound Expression Example Source: https://wiki.geckolib.com/docs/geckolib5/concepts/animation/molang Evaluate multiple Molang expressions sequentially in a single keyframe. The last expression's result is returned for the animation. ```Molang v.is_animating_walk = 1;math.sin(query.anim_time) ``` -------------------------------- ### Playing and Stopping Animations in Stateless Entity Source: https://wiki.geckolib.com/docs/geckolib5/miscellaneous/stateless-animations Shows how to play and stop animations within the tick method of a stateless entity. This example demonstrates playing the 'living' animation constantly and switching between 'walk' and 'idle' based on movement. It's recommended to use client-side logic for animations unless server-side is specifically required. ```java public class ExampleEntity extends PathfinderMob implements StatelessGeoEntity { //... @Override public void tick() { super.tick(); // Preference the client side unless you need the server side for some reason. The code is the same either way. if (level().isClientSide()) { // Just play the living animation all the time playAnimation(DefaultAnimations.LIVING); if (getDeltaMovement().horizontalDistanceSqr() > 0.01) { // Play the walking animation if we're moving, and stop the idle animation playAnimation(DefaultAnimations.WALK); stopAnimation(DefaultAnimations.IDLE); } else { // Play the idle animation if we're not moving, and stop the walking animation playAnimation(DefaultAnimations.IDLE); stopAnimation(DefaultAnimations.WALK); } } } } ``` -------------------------------- ### Complex Expression with Queries and Functions Source: https://wiki.geckolib.com/docs/geckolib5/concepts/animation/molang Combine multiple math functions, queries, and arithmetic operations for highly customized and dynamic animation behaviors. This example uses ground speed to influence animation. ```Molang ((-0.2 + 1.5 * (math.abs(math.mod(query.ground_speed, 13) - 6.5) - 3.25) / 3.25) * query.ground_speed) * 57.3 ``` -------------------------------- ### Block Model JSON Example Source: https://wiki.geckolib.com/docs/geckolib5/blocks/the-block-asset-files Use this JSON structure for your block model file. Replace 'examplemod' with your mod ID and 'example_block' with your block's registered ID. The particle texture can also target other blocks. ```json { "textures": { "particle": "examplemod:block/example_block" } } ``` -------------------------------- ### Triggering an Animation on an Entity Source: https://wiki.geckolib.com/docs/geckolib5/miscellaneous/triggerable-animations Trigger a registered animation on an animatable entity instance. This example shows triggering from an interaction. ```java @Override public InteractionResult mobInteract(Player player, InteractionHand hand) { if (!level.clientSide()) triggerAnim("shoot_controller", "shoot"); return InteractionResult.sidedSuccess(level().isClientSide()); } ``` -------------------------------- ### Creating an ExampleArmorRenderer Class Source: https://wiki.geckolib.com/docs/geckolib5/armor/the-armor-renderer This is the initial step for creating a standalone renderer class that extends GeoArmorRenderer. It serves as a base for further customization. ```java public class ExampleArmorRenderer extends GeoArmorRenderer { } ``` -------------------------------- ### Create Base Replaced Entity Class Source: https://wiki.geckolib.com/docs/geckolib5/entities/replaced-entities/creating-the-entity-class Implement the GeoReplacedEntity interface to start creating a custom replaced entity. ```java public class ExampleReplacedEntity implements GeoReplacedEntity { } ``` -------------------------------- ### Client Setup for Forge Source: https://wiki.geckolib.com/docs/geckolib5/items/applying-the-item-renderer For Forge, use the EntityRenderersEvent.RegisterRenderers event to set the geoRenderProvider in your item's instance. This ensures the renderer is registered. ```java @SubscribeEvent public static void registerRenderers(final EntityRenderersEvent.RegisterRenderers event) { ItemRegistry.EXAMPLE_ITEM.geoRenderProvider.setValue(new GeoRenderProvider() { private final Supplier> renderer = Suppliers.memoize(() -> new GeoItemRenderer<>(ItemRegistry.EXAMPLE_ITEM.get())); @Override public @Nullable GeoItemRenderer getGeoItemRenderer() { return this.renderer.get(); } }); } ``` -------------------------------- ### Create Base Entity Class Source: https://wiki.geckolib.com/docs/geckolib5/entities/the-entity-class This snippet shows the initial creation of a Java class that extends PathfinderMob, serving as the foundation for a GeckoLib entity. ```java public class ExampleEntity extends PathfinderMob { public ExampleEntity(EntityType entityType, Level level) { super(entityType, level); } } ``` -------------------------------- ### Instantiate and Return AnimatableInstanceCache Source: https://wiki.geckolib.com/docs/geckolib5/entities/the-entity-class This snippet shows the final step in setting up the entity class by instantiating an AnimatableInstanceCache using GeckoLibUtil and returning it from the getAnimatableInstanceCache method. ```java public class ExampleEntity extends PathfinderMob implements GeoEntity { private final AnimatableInstanceCache geoCache = GeckoLibUtil.createInstanceCache(this); public ExampleEntity(EntityType entityType, Level level) { super(entityType, level); } @Override public void registerControllers(final AnimatableManager.ControllerRegistrar controllers) { // We can fill this in later } @Override public AnimatableInstanceCache getAnimatableInstanceCache() { return this.geoCache; } } ``` -------------------------------- ### Create Base Block Class Source: https://wiki.geckolib.com/docs/geckolib5/blocks/the-block-class This snippet shows the initial creation of a basic block class with its constructor. ```java public class ExampleBlock extends Block { public ExampleBlock(BlockBehaviour.Properties properties) { super(properties); } } ``` -------------------------------- ### Create Base BlockEntity Class Source: https://wiki.geckolib.com/docs/geckolib5/blocks/the-blockentity-class This snippet shows the initial creation of a basic BlockEntity class that extends the vanilla BlockEntity. ```java public class ExampleBlockEntity extends BlockEntity { } ``` -------------------------------- ### Provide GeoRenderProvider Instance Source: https://wiki.geckolib.com/docs/geckolib5/armor/applying-the-armor-renderer Next, provide a new GeoRenderProvider instance to the consumer within the createGeoRenderer method. ```java public class ExampleArmorItem extends Item implements GeoItem { // ... @Override public void createGeoRenderer(Consumer consumer) { consumer.accept(new GeoRenderProvider() { }); } } ``` -------------------------------- ### Declare GeckoLib Library (libs.versions.toml) Source: https://wiki.geckolib.com/docs/geckolib5/setup/forge/quick-reference Declare the GeckoLib library in your libs.versions.toml file. ```toml geckolib = { group = "com.geckolib", name = "geckolib-forge-26.1", version.ref = "geckolib" } ``` -------------------------------- ### Animation Transition Controller Source: https://wiki.geckolib.com/docs/geckolib5/miscellaneous/triggerable-animations Implement a controller to manage transitions between animation states, such as sitting and standing. Triggerable animations like 'Sit' and 'Stand' can disguise the swap between states. ```java @Override public void registerControllers(AnimatableManager.ControllerRegistrar controllers) { controllers.add(new AnimationController(animTest -> { // This check is made up for this example, to simplify it // Be in sitting pose if sitting if (checkIsSitting()) return animTest.setAndContinue(MY_SITTING_ANIM); // Walk or idle if not sitting return animTest.isMoving() ? animTest.setAndContinue(DefaultAnimations.WALK) : animTest.setAndContinue(DefaultAnimations.IDLE); }).triggerableAnim("Sit", SIT_DOWN_ANIM) // Triggerable anim to 'stand up' .triggerableAnim("Stand", STAND_UP_ANIM)) // Triggerable anim to 'sit down' } ``` -------------------------------- ### Basic Entity Class Structure Source: https://wiki.geckolib.com/docs/geckolib5/entities/copy-paste-templates Use this template to create a new entity class that implements GeckoLib's GeoEntity interface. Ensure you have the necessary imports for PathfinderMob, GeoEntity, AnimatableInstanceCache, and GeckoLibUtil. ```java public class ExampleEntity extends PathfinderMob implements GeoEntity { private final AnimatableInstanceCache geoCache = GeckoLibUtil.createInstanceCache(this); public ExampleEntity(EntityType entityType, Level level) { super(entityType, level); } @Override public void registerControllers(final AnimatableManager.ControllerRegistrar controllers) { } @Override public AnimatableInstanceCache getAnimatableInstanceCache() { return this.geoCache; } } ``` -------------------------------- ### Registering a Network-Synced Item Source: https://wiki.geckolib.com/docs/geckolib5/miscellaneous/triggerable-animations Make an item network-synced so GeckoLib can manage its animations. This is done in the item's constructor. ```java public ExampleItem(Properties properties) { super(properties); GeoItem.registerSyncedAnimatable(this); } ``` -------------------------------- ### Override Render State Methods for Replaced Entity Source: https://wiki.geckolib.com/docs/geckolib5/entities/replaced-entities/creating-the-renderer Override createRenderState and extractRenderState to manage the render state, ensuring it matches the target entity's behavior. This example is for replacing a Creeper. ```java @Override public R createRenderState(ExampleReplacedEntity animatable, Creeper relatedObject) { return (R)new CreeperRenderState(); } @Override public void extractRenderState(Creeper entity, R renderState, float partialTick) { super.extractRenderState(entity, renderState, partialTick); renderState.swelling = entity.getSwelling(partialTick); renderState.isPowered = entity.isPowered(); } ``` -------------------------------- ### Implement EntityBlock Interface Source: https://wiki.geckolib.com/docs/geckolib5/blocks/the-block-class Adds the EntityBlock interface to the ExampleBlock class, preparing it for block entity integration. ```java public class ExampleBlock extends Block implements EntityBlock { public ExampleBlock(BlockBehaviour.Properties properties) { super(properties); } } ``` -------------------------------- ### Registering a Generic Walk/Idle Controller Source: https://wiki.geckolib.com/docs/geckolib5/concepts/animation/controller/defaultanimations This snippet shows how to register a pre-built generic walk/idle animation controller using DefaultAnimations. Make sure to import the necessary classes. ```java @Override public void registerControllers(AnimatableManager.ControllerRegistrar controllers) { controllers.add(DefaultAnimations.genericWalkIdleController()); } ``` -------------------------------- ### Item Class with Mutable GeoRenderProvider Source: https://wiki.geckolib.com/docs/geckolib5/armor/copy-paste-templates This template is for an armor item that uses a mutable `GeoRenderProvider`, allowing for dynamic assignment of the renderer. It's useful when the renderer needs to be set externally, such as during client setup. ```java public class ExampleArmorItem extends Item implements GeoItem { public final MutableObject geoRenderProvider = new MutableObject<>(); private final AnimatableInstanceCache geoCache = GeckoLibUtil.createInstanceCache(this); public ExampleArmorItem(ArmorMaterial material, ArmorType type, Properties properties) { super(properties.humanoidArmor(material, type)); // Uncomment the below line to enable triggered animations //GeoItem.registerSyncedAnimatable(this); } @Override public void createGeoRenderer(Consumer consumer) { consumer.accept(this.geoRenderProvider.getValue()); } @Override public void registerControllers(final AnimatableManager.ControllerRegistrar controllers) { } @Override public AnimatableInstanceCache getAnimatableInstanceCache() { return this.geoCache; } } ``` -------------------------------- ### Registering a Simple Entity Renderer (Forge/NeoForge) Source: https://wiki.geckolib.com/docs/geckolib5/entities/the-entity-renderer Use this when no custom rendering logic is required. Pass a new instance of `GeoEntityRenderer` with the context and entity type, accessing the entity type via `.get()`. ```java context -> new GeoEntityRenderer<>(context, EntityRegistry.EXAMPLE_ENTITY.get()); ``` -------------------------------- ### Using Math Functions Source: https://wiki.geckolib.com/docs/geckolib5/concepts/animation/molang Integrate built-in math functions like `math.cos` to create smooth, cyclical animations based on mathematical principles. ```Molang math.cos(5) ``` -------------------------------- ### Registering an Additive Controller Source: https://wiki.geckolib.com/docs/geckolib5/concepts/animation/controller/ordering Make a controller additive by calling `.additiveAnimations()` to combine its animation values with existing ones, rather than overriding them. ```java @Override public void registerControllers(AnimatableManager.ControllerRegistrar controllers) { controllers.add( DefaultAnimations.genericWalkIdleController(), DefaultAnimations.genericAttackController(this).additiveAnimations()); } ``` -------------------------------- ### Registering a Simple Entity Renderer (Fabric) Source: https://wiki.geckolib.com/docs/geckolib5/entities/the-entity-renderer Use this when no custom rendering logic is required. Pass a new instance of `GeoEntityRenderer` with the context and entity type. ```java context -> new GeoEntityRenderer<>(context, EntityRegistry.EXAMPLE_ENTITY); ``` -------------------------------- ### Declare GeckoLib Version (libs.versions.toml) Source: https://wiki.geckolib.com/docs/geckolib5/setup/forge/quick-reference Declare the GeckoLib version in your libs.versions.toml file. ```toml geckolib = ``` -------------------------------- ### Register Simple GeoBlockRenderer (Forge/NeoForge) Source: https://wiki.geckolib.com/docs/geckolib5/blocks/the-blockentity-renderer Use this when no custom rendering logic is needed. Pass a new instance of `GeoBlockRenderer` with the BlockEntityType, accessing it via `.get()`. ```java context -> new GeoBlockRenderer<>(context, BlockEntityRegistry.EXAMPLE_BLOCK_ENTITY.get()); ``` -------------------------------- ### Reference GeckoLib from libs.versions.toml (Groovy) Source: https://wiki.geckolib.com/docs/geckolib5/setup/fabric/adding-the-dependency Reference the previously defined GeckoLib library in your build.gradle file using Groovy syntax. ```gradle modImplementation libs.geckolib ``` -------------------------------- ### Item Class with Combined Sources Source: https://wiki.geckolib.com/docs/geckolib5/items/copy-paste-templates Use this template for an item class that combines its rendering logic within the item itself. It initializes the GeoItem interface and sets up the GeoRenderer. ```java public class ExampleItem extends Item implements GeoItem { private final AnimatableInstanceCache geoCache = GeckoLibUtil.createInstanceCache(this); public ExampleItem(Properties properties) { super(properties); // Uncomment the below line to enable triggered animations //GeoItem.registerSyncedAnimatable(this); } @Override public void createGeoRenderer(Consumer consumer) { consumer.accept(new GeoRenderProvider() { private final Supplier> renderer = Suppliers.memoize(() -> new GeoItemRenderer<>(ExampleItem.this)); @Override public @Nullable GeoItemRenderer getGeoItemRenderer() { return this.renderer.get(); } }); } @Override public void registerControllers(final AnimatableManager.ControllerRegistrar controllers) { } @Override public AnimatableInstanceCache getAnimatableInstanceCache() { return this.geoCache; } } ``` -------------------------------- ### Define GeckoLib Library in libs.versions.toml Source: https://wiki.geckolib.com/docs/geckolib5/setup/fabric/adding-the-dependency Define the GeckoLib library entry in your libs.versions.toml file. Ensure the version number matches your intended Minecraft version. ```toml geckolib = { group = "com.geckolib", name = "geckolib-fabric-26.1", version.ref = "geckolib" } ``` -------------------------------- ### Basic Item Class with GeoItem Implementation Source: https://wiki.geckolib.com/docs/geckolib5/armor/copy-paste-templates Use this template for a basic armor item that implements the `GeoItem` interface. It sets up the `AnimatableInstanceCache` and the `GeoRenderProvider` for rendering. ```java public class ExampleArmorItem extends Item implements GeoItem { private final AnimatableInstanceCache geoCache = GeckoLibUtil.createInstanceCache(this); public ExampleArmorItem(ArmorMaterial material, ArmorType type, Properties properties) { super(properties.humanoidArmor(material, type)); // Uncomment the below line to enable triggered animations //GeoItem.registerSyncedAnimatable(this); } @Override public void createGeoRenderer(Consumer consumer) { consumer.accept(new GeoRenderProvider() { private final Supplier> renderer = Suppliers.memoize(() -> new GeoArmorRenderer<>(ExampleArmorItem.this)); @Override public @Nullable GeoArmorRenderer getGeoArmorRenderer(ItemStack itemStack, EquipmentSlot equipmentSlot) { return this.renderer.get(); } }); } @Override public void registerControllers(final AnimatableManager.ControllerRegistrar controllers) { } @Override public AnimatableInstanceCache getAnimatableInstanceCache() { return this.geoCache; } } ``` -------------------------------- ### Instantiate and Return AnimatableInstanceCache Source: https://wiki.geckolib.com/docs/geckolib5/entities/replaced-entities/creating-the-entity-class Initialize the AnimatableInstanceCache using GeckoLibUtil.createInstanceCache and return it from the getAnimatableInstanceCache method. ```java public class ExampleReplacedEntity implements GeoReplacedEntity { private final AnimatableInstanceCache geoCache = GeckoLibUtil.createInstanceCache(this); @Override public void registerControllers(final AnimatableManager.ControllerRegistrar controllers) { // We can fill this in later } @Override public AnimatableInstanceCache getAnimatableInstanceCache() { return this.geoCache; } } ``` -------------------------------- ### Reference GeckoLib from libs.versions.toml (Kotlin) Source: https://wiki.geckolib.com/docs/geckolib5/setup/fabric/adding-the-dependency Reference the previously defined GeckoLib library in your build.gradle file using Kotlin syntax. ```gradle modImplementation(libs.geckolib) ``` -------------------------------- ### Applying a Simple GeoItemRenderer Source: https://wiki.geckolib.com/docs/geckolib5/items/the-item-renderer Use this approach when no custom handling is required for your item's rendering. Simply pass a new instance of `GeoItemRenderer` when applying the renderer. ```java () -> new GeoItemRenderer<>(ExampleItem.this); ``` -------------------------------- ### Declare GeckoLib Repository (build.gradle - Kotlin) Source: https://wiki.geckolib.com/docs/geckolib5/setup/fabric/quick-reference Declare the GeckoLib Maven repository in your `build.gradle` file using Kotlin syntax. This is the Kotlin equivalent of the Groovy repository declaration. ```kotlin repositories { exclusiveContent { forRepository { maven { name = "GeckoLib" url = uri("https://dl.cloudsmith.io/public/geckolib3/geckolib/maven/") } } filter { includeGroupAndSubgroups("com.geckolib") } } } ``` -------------------------------- ### Create Base Item Class Source: https://wiki.geckolib.com/docs/geckolib5/items/the-item-class This is the initial step to create a basic item class in Java, extending the base Item class and implementing its constructor. ```java public class ExampleItem extends Item { public ExampleItem(Properties properties) { super(properties); } } ``` -------------------------------- ### Basic Animated Texture .mcmeta File Source: https://wiki.geckolib.com/docs/geckolib5/miscellaneous/animated-textures This is the minimal .mcmeta file required to enable texture animation. Ensure it is named after your texture file with an additional .mcmeta extension and placed in the same directory. ```json { "animation": { } } ``` -------------------------------- ### Using Animation Time Query Source: https://wiki.geckolib.com/docs/geckolib5/concepts/animation/molang Leverage `query.anim_time` to synchronize animations with the elapsed time of the animation, creating automatic back-and-forth motion. ```Molang math.cos(query.anim_time) ``` -------------------------------- ### Reference GeckoLib Library in build.gradle.kts (Kotlin) Source: https://wiki.geckolib.com/docs/geckolib5/setup/forge/adding-the-dependency After defining the library in libs.versions.toml, use this snippet in your build.gradle.kts file (Kotlin) to reference the GeckoLib dependency. ```kotlin implementation(minecraft.dependency(libs.geckolib)) ``` -------------------------------- ### Item Display JSON Configuration Source: https://wiki.geckolib.com/docs/geckolib5/items/copy-paste-templates Configures the display properties and particle texture for an item model. Remember to replace placeholders. ```json { "parent": "builtin/entity", "textures": { "particle": ":item/" } } ``` -------------------------------- ### Add Constructor with BlockEntity Reference (Forge/NeoForge) Source: https://wiki.geckolib.com/docs/geckolib5/blocks/the-blockentity-class Add the constructor for the BlockEntity, referencing the BlockEntity type using .get() for Forge and NeoForge compatibility. This links the entity to its registration. ```java public class ExampleBlockEntity extends BlockEntity { private final AnimatableInstanceCache geoCache = GeckoLibUtil.createInstanceCache(this); public ExampleBlockEntity(BlockPos pos, BlockState state) { super(BlockEntityRegistry.EXAMPLE_BLOCK_ENTITY.get(), pos, state); } @Override public void registerControllers(final AnimatableManager.ControllerRegistrar controllers) { // We can fill this in later } @Override public AnimatableInstanceCache getAnimatableInstanceCache() { return this.geoCache; } } ``` -------------------------------- ### Applying a Simple GeoArmorRenderer Source: https://wiki.geckolib.com/docs/geckolib5/armor/the-armor-renderer Use this approach when no custom handling is needed for your armor's rendering. It involves passing a new instance of GeoArmorRenderer when applying the renderer. ```java () -> new GeoArmorRenderer<>(ExampleArmorItem.this); ``` -------------------------------- ### Adding Constructor to Armor Renderer Source: https://wiki.geckolib.com/docs/geckolib5/armor/the-armor-renderer Include a constructor that accepts an Item and passes it to the superclass. This automatically creates the GeoModel for the armor. ```java public class ExampleArmorRenderer extends GeoArmorRenderer { public ExampleArmorRenderer(Item item) { super(item); } } ``` -------------------------------- ### Add Interface Injection Data (Groovy) Source: https://wiki.geckolib.com/docs/geckolib5/setup/neoforge/adding-the-dependency Include this for compile-time interface injections if you are using ModDevGradle, using Groovy syntax. ```groovy interfaceInjectionData "com.geckolib:geckolib-neoforge-${minecraftVersion}:${geckolibVersion}" ``` -------------------------------- ### Create Base Armor Item Class Source: https://wiki.geckolib.com/docs/geckolib5/armor/the-item-class Initializes the base item class for armor with the provided material, type, and properties. This sets up the fundamental structure for GeckoLib armor. ```java public class ExampleArmorItem extends Item { public ExampleArmorItem(ArmorMaterial material, ArmorType type, Properties properties) { super(properties.humanoidArmor(material, type)); } } ``` -------------------------------- ### Use Interface Injection Data from Version Catalog (Kotlin DSL) Source: https://wiki.geckolib.com/docs/geckolib5/setup/neoforge/adding-the-dependency Reference interface injection data using its alias from libs.versions.toml in your build.gradle.kts file. ```kotlin interfaceInjectionData(libs.geckolib) ``` -------------------------------- ### Registering Controllers with Priority Source: https://wiki.geckolib.com/docs/geckolib5/concepts/animation/controller/ordering Register controllers in the desired order of priority. Controllers registered earlier will have lower priority. ```java @Override public void registerControllers(AnimatableManager.ControllerRegistrar controllers) { controllers.add( DefaultAnimations.genericWalkIdleController(), DefaultAnimations.genericAttackController(this)); } ``` -------------------------------- ### Implement Constructor for Replaced Entity Renderer Source: https://wiki.geckolib.com/docs/geckolib5/entities/replaced-entities/creating-the-renderer Add a constructor to the renderer, passing the EntityRendererProvider context, a GeoModel instance, and an instance of your replaced entity. ```java public ExampleReplacedEntityRenderer extends GeoEntityRenderer { public ExampleReplacedEntityRenderer(EntityRendererProvider.Context context) { super(context, new ExampleReplacedEntityGeoModel(), new ExampleReplacedEntity(); } } ``` -------------------------------- ### Add GeckoLib Maven Repository (Groovy) Source: https://wiki.geckolib.com/docs/geckolib5/setup/fabric/adding-the-repository Add GeckoLib's exclusive Maven repository to your build.gradle file using Groovy syntax. This allows Gradle to find GeckoLib artifacts. ```gradle repositories { exclusiveContent { forRepository { maven { name = 'GeckoLib' url = 'https://dl.cloudsmith.io/public/geckolib3/geckolib/maven/' } } filter { includeGroupAndSubgroups('com.geckolib') } } } ``` -------------------------------- ### Item Class with Split Sources Source: https://wiki.geckolib.com/docs/geckolib5/items/copy-paste-templates This template is for an item class where the GeoRenderer is managed separately. It initializes the GeoItem interface and holds a mutable GeoRenderProvider. ```java public class ExampleItem extends Item implements GeoItem { public final MutableObject geoRenderProvider = new MutableObject<>(); private final AnimatableInstanceCache geoCache = GeckoLibUtil.createInstanceCache(this); public ExampleItem(Properties properties) { super(properties); // Uncomment the below line to enable triggered animations //GeoItem.registerSyncedAnimatable(this); } @Override public void createGeoRenderer(Consumer consumer) { consumer.accept(this.geoRenderProvider.getValue()); } @Override public void registerControllers(final AnimatableManager.ControllerRegistrar controllers) { } @Override public AnimatableInstanceCache getAnimatableInstanceCache() { return this.geoCache; } } ``` -------------------------------- ### Define GeckoLib in libs.versions.toml Source: https://wiki.geckolib.com/docs/geckolib5/setup/neoforge/adding-the-dependency Add this library definition to the [libraries] section of your libs.versions.toml file. ```toml geckolib = { group = "com.geckolib", name = "geckolib-neoforge-26.1", version.ref = "geckolib" } ``` -------------------------------- ### Reference GeckoLib Library in build.gradle (Groovy) Source: https://wiki.geckolib.com/docs/geckolib5/setup/forge/adding-the-dependency After defining the library in libs.versions.toml, use this snippet in your build.gradle file (Groovy) to reference the GeckoLib dependency. ```groovy implementation minecraft.dependency(libs.geckolib) ``` -------------------------------- ### Spawning Animation Controller Source: https://wiki.geckolib.com/docs/geckolib5/concepts/animation/controller/statehandler Plays a spawning animation for a limited duration upon entity creation. Stops after a set number of ticks. ```java @Override public void registerControllers(AnimatableManager.ControllerRegistrar controllers) { controllers.add(new AnimationController<>(test -> { if (MyEntity.this.tickCount <= 100) return test.setAndContinue(MY_SPAWN_ANIMATION); return PlayState.STOP; })); } ``` -------------------------------- ### Creating a Custom Defaulted GeoModel Source: https://wiki.geckolib.com/docs/geckolib5/concepts/geomodels/defaulted-geomodel Illustrates how to create a custom Defaulted GeoModel by extending the DefaultedGeoModel class and overriding the subtype() method to define a custom subfolder for asset paths. ```java public class ExampleCustomDefaultedGeoModel extends DefaultedGeoModel { public ExampleCustomDefaultedGeoModel(Identifier identifier) { super(identifier); } @Override protected String subtype() { return "custom"; } } ``` -------------------------------- ### Add GeckoLib Dependency (Kotlin DSL) Source: https://wiki.geckolib.com/docs/geckolib5/setup/neoforge/adding-the-dependency Use this line in your build.gradle.kts file's dependencies block to add GeckoLib. ```kotlin implementation("com.geckolib:geckolib-neoforge-${minecraftVersion}:${geckolibVersion}") ``` -------------------------------- ### Basic Arithmetic Expression Source: https://wiki.geckolib.com/docs/geckolib5/concepts/animation/molang Molang can evaluate simple mathematical expressions directly in keyframes. Use this for straightforward calculations. ```Molang 5 * 4 ``` -------------------------------- ### Register Simple GeoBlockRenderer (Fabric) Source: https://wiki.geckolib.com/docs/geckolib5/blocks/the-blockentity-renderer Use this when no custom rendering logic is needed. Pass a new instance of `GeoBlockRenderer` with the BlockEntityType. ```java context -> new GeoBlockRenderer<>(context, BlockEntityRegistry.EXAMPLE_BLOCK_ENTITY); ```