### Example 3 - Spawning Animation Source: https://wiki.geckolib.com/docs/geckolib5/concepts/animation/controller/statehandler This example shows how to play a 'spawning' animation when an entity first appears. It checks the entity's `tickCount` against the animation length. ```APIDOC ## POST /registerControllers (Spawning) ### Description Registers animation controllers. This example plays a specific animation when the entity first spawns, based on its tick count. ### Method POST ### Endpoint `/registerControllers` ### Parameters #### Request Body - **controllers** (AnimatableManager.ControllerRegistrar) - Required - The registrar to add controllers to. ### Request Example ```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; })); } ``` ### Response #### Success Response (200) - **None** - This method is for registering controllers and does not return a value. #### Response Example ``` // No response body ``` ``` -------------------------------- ### Example 2 - Walk/Idle Animation Source: https://wiki.geckolib.com/docs/geckolib5/concepts/animation/controller/statehandler This example extends the previous one by adding an idle animation. If the entity is not moving, it will play the idle animation instead of stopping. ```APIDOC ## POST /registerControllers (Walk/Idle) ### Description Registers animation controllers. This example demonstrates switching between a walk animation and an idle animation based on entity movement. ### Method POST ### Endpoint `/registerControllers` ### Parameters #### Request Body - **controllers** (AnimatableManager.ControllerRegistrar) - Required - The registrar to add controllers to. ### Request Example ```java @Override public void registerControllers(AnimatableManager.ControllerRegistrar controllers) { controllers.add(new AnimationController<>(test -> { if (test.isMoving()) return test.setAndContinue(DefaultAnimations.WALK); return test.setAndContinue(DefaultAnimations.IDLE); })); } ``` ### Response #### Success Response (200) - **None** - This method is for registering controllers and does not return a value. #### Response Example ``` // No response body ``` ``` -------------------------------- ### Example 4 - Attacking Animation Source: https://wiki.geckolib.com/docs/geckolib5/concepts/animation/controller/statehandler This example demonstrates playing an attack animation when the entity is swinging. It checks the entity's `swinging` state. ```APIDOC ## POST /registerControllers (Attacking) ### Description Registers animation controllers. This example plays an attack animation when the entity is in a swinging state. ### Method POST ### Endpoint `/registerControllers` ### Parameters #### Request Body - **controllers** (AnimatableManager.ControllerRegistrar) - Required - The registrar to add controllers to. ### Request Example ```java @Override public void registerControllers(AnimatableManager.ControllerRegistrar controllers) { controllers.add(new AnimationController<>(test -> { if (MyEntity.this.swinging) return test.setAndContinue(DefaultAnimations.ATTACK_SWING); return PlayState.STOP; })); } ``` ### Response #### Success Response (200) - **None** - This method is for registering controllers and does not return a value. #### Response Example ``` // No response body ``` ``` -------------------------------- ### Example 1 - Walk Animation Source: https://wiki.geckolib.com/docs/geckolib5/concepts/animation/controller/statehandler This example demonstrates how to control a walk animation based on whether the entity is moving. It uses `setAndContinue` to play the walk animation if the entity is moving, and stops animation otherwise. ```APIDOC ## POST /registerControllers ### Description Registers animation controllers for an entity. This example shows a controller that plays a walk animation when the entity is moving. ### Method POST ### Endpoint `/registerControllers` ### Parameters #### Request Body - **controllers** (AnimatableManager.ControllerRegistrar) - Required - The registrar to add controllers to. ### Request Example ```java @Override public void registerControllers(AnimatableManager.ControllerRegistrar controllers) { controllers.add(new AnimationController<>(test -> { if (test.isMoving()) return test.setAndContinue(DefaultAnimations.WALK); return PlayState.STOP; })); } ``` ### Response #### Success Response (200) - **None** - This method is for registering controllers and does not return a value. #### Response Example ``` // No response body ``` ``` -------------------------------- ### Creating a DataTicket Source: https://wiki.geckolib.com/docs/geckolib5/concepts/rendering/datatickets Demonstrates how to instantiate a DataTicket for use in GeckoLib. Includes examples for both simple types and complex generic types using TypeToken. ```java public static final DataTicket EXAMPLE_BOOLEAN_TICKET = DataTicket.create("example_boolean", Boolean.class); ``` ```java public static final DataTicket> EXAMPLE_DIRECTIONS_TICKET = DataTicket.create("example_directions", EnumMap.class, new TypeToken<>() {}); ``` -------------------------------- ### Implementing GeoModel Source: https://wiki.geckolib.com/docs/geckolib5/concepts/geomodels/basic-geomodel Guidelines and code example for creating a custom GeoModel class by overriding resource retrieval methods. ```APIDOC ## Class Implementation: GeoModel ### Description To create a basic GeoModel, you must extend the `GeoModel` class and implement three specific methods to define the paths for your model, animation, and texture assets. ### Required Methods - **getModelResource(GeoRenderState)**: Returns the Identifier for the .geo.json model file. - **getAnimationResource(T)**: Returns the Identifier for the .animation.json file. - **getTextureResource(GeoRenderState)**: Returns the Identifier for the .png texture file. ### Implementation Example ```java public class ExampleGeoModel extends GeoModel { private final Identifier modelPath = Identifier.fromNamespaceAndPath(ExampleMod.MOD_ID, "example_entity"); private final Identifier animationsPath = Identifier.fromNamespaceAndPath(ExampleMod.MOD_ID, "example_entity"); 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; } } ``` ``` -------------------------------- ### Java: Control Walk Animation with StateHandler Source: https://wiki.geckolib.com/docs/geckolib5/concepts/animation/controller/statehandler This example demonstrates a StateHandler that plays a walk animation when the entity is moving and stops animation when idle. It uses the `setAndContinue` method to manage the animation state. ```Java @Override public void registerControllers(AnimatableManager.ControllerRegistrar controllers) { controllers.add(new AnimationController<>(test -> { if (test.isMoving()) return test.setAndContinue(DefaultAnimations.WALK); return PlayState.STOP; })); } ``` -------------------------------- ### Java: Control Walk/Idle Animation with StateHandler Source: https://wiki.geckolib.com/docs/geckolib5/concepts/animation/controller/statehandler This StateHandler example extends the previous one by playing an idle animation when the entity is not moving, instead of stopping all animations. It ensures a continuous animation loop. ```Java @Override public void registerControllers(AnimatableManager.ControllerRegistrar controllers) { controllers.add(new AnimationController<>(test -> { if (test.isMoving()) return test.setAndContinue(DefaultAnimations.WALK); return test.setAndContinue(DefaultAnimations.IDLE); })); } ``` -------------------------------- ### Java: Play Spawn Animation on Entity Appearance Source: https://wiki.geckolib.com/docs/geckolib5/concepts/animation/controller/statehandler This example shows how to play a specific 'spawning' animation when an entity first appears. It checks the entity's `tickCount` against a predefined duration to trigger the animation. ```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; })); } ``` -------------------------------- ### Java Item Class Setup for GeckoLib Source: https://wiki.geckolib.com/docs/geckolib5/armor/copy-paste-templates Defines a custom item class that implements the GeoItem interface, enabling custom animations and rendering. It includes setup for the animatable instance cache and the geo renderer provider. This template is suitable for both combined and split source setups. ```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; } } ``` ```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; } } ``` -------------------------------- ### Fabric Client Setup for GeoRenderProvider Source: https://wiki.geckolib.com/docs/geckolib5/items/applying-the-item-renderer This snippet demonstrates how to set the GeoRenderProvider for an item in a Fabric mod's client setup. It initializes a GeoItemRenderer and provides it to the item's geoRenderProvider. This is typically done within the onInitializeClient method. ```java @Override public void onInitializeClient() { ItemRegistry.EXAMPLE_ITEM.geoRenderProvider.setValue(new GeoRenderProvider() { private final Supplier> renderer = Suppliers.memoize(() -> new GeoItemRenderer<>(ItemRegistry.EXAMPLE_ITEM)); @Override public @Nullable GeoItemRenderer getGeoItemRenderer() { return this.renderer.get(); } }); } ``` -------------------------------- ### Basic Molang Mathematical Expressions Source: https://wiki.geckolib.com/docs/geckolib5/concepts/animation/molang Examples of simple mathematical operations and function calls within Molang to define animation values. ```Molang 5 * 4 math.cos(5) math.cos(query.anim_time) ``` -------------------------------- ### Java Client Setup for GeckoLib Item Rendering (Forge/NeoForge) Source: https://wiki.geckolib.com/docs/geckolib5/armor/copy-paste-templates Sets up the GeoRenderProvider for a custom item on the client side using Forge/NeoForge's event bus. This method is called during the registration of entity renderers to associate the item with its custom renderer. ```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(); } }); } ``` ```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(); } }); } ``` -------------------------------- ### Implement GeoItem Interface and Methods (Java) Source: https://wiki.geckolib.com/docs/geckolib5/armor/the-item-class This code extends the previous example by implementing the `GeoItem` interface and overriding the `registerControllers` and `getAnimatableInstanceCache` methods, which are essential for GeckoLib's animation system. ```java public class ExampleArmorItem extends Item implements GeoItem { public ExampleArmorItem(ArmorMaterial material, ArmorType type, Properties properties) { super(properties.humanoidArmor(material, type)); } @Override public void registerControllers(final AnimatableManager.ControllerRegistrar controllers) { // We can fill this in later } @Override public AnimatableInstanceCache getAnimatableInstanceCache() { return null; } } ``` -------------------------------- ### Creating a GeckoLib Block Class Source: https://wiki.geckolib.com/docs/geckolib5/blocks/the-block-class This snippet demonstrates the evolution of a custom block class, starting from a basic block implementation to one that integrates with a BlockEntity. It highlights the differences in registry access between Fabric, Forge, and NeoForge. ```Java (Fabric) 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); } } ``` ```Java (Forge) 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.get().create(pos, state); } } ``` ```Java (NeoForge) 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.get().create(pos, state); } } ``` -------------------------------- ### Implementing a Custom GeoModel Class Source: https://wiki.geckolib.com/docs/geckolib5/concepts/geomodels/basic-geomodel This example demonstrates how to extend the GeoModel class to define custom resource paths for a model, animation, and texture. It includes the implementation of the three required methods: getModelResource, getAnimationResource, and getTextureResource. ```java public class ExampleGeoModel extends GeoModel { private final Identifier modelPath = Identifier.fromNamespaceAndPath(ExampleMod.MOD_ID, "example_entity"); private final Identifier animationsPath = Identifier.fromNamespaceAndPath(ExampleMod.MOD_ID, "example_entity"); 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; } } ``` -------------------------------- ### GET /query/global-state Source: https://wiki.geckolib.com/docs/geckolib5/concepts/animation/molang Retrieves global game state information such as time of day, moon phase, and player XP level. ```APIDOC ## GET /query/global-state ### Description Retrieves environmental or global player data that is not tied to a specific entity instance. ### Method GET ### Endpoint /query/{query_name} ### Parameters #### Path Parameters - **query_name** (string) - Required - The global query (e.g., query.time_of_day, query.moon_phase, query.player_level) ### Response #### Success Response (200) - **value** (float) - The global state value. #### Response Example { "value": 0.5 } ``` -------------------------------- ### Implementing the GeoModel Class Source: https://wiki.geckolib.com/docs/geckolib5/entities/replaced-entities/creating-the-geomodel This snippet demonstrates the incremental creation of a GeoModel class. It starts with a basic class definition, extends the DefaultedEntityGeoModel, and finally adds the constructor to initialize asset identifiers. ```java public class ExampleReplacedEntityGeoModel extends DefaultedEntityGeoModel { public ExampleReplacedEntityGeoModel() { super(Identifier.fromNamespaceAndPath(ExampleMod.MOD_ID, "example_replaced_entity")); } } ``` -------------------------------- ### Fabric Client Setup for GeoRenderProvider Source: https://wiki.geckolib.com/docs/geckolib5/armor/applying-the-armor-renderer Sets the geoRenderProvider for an item in the client's onInitializeClient method for Fabric mods. It uses a memoized supplier to create a GeoArmorRenderer instance. ```java @Override public void onInitializeClient() { ItemRegistry.EXAMPLE_ARMOR_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(); } }); } ``` -------------------------------- ### Getting Distance From Camera in GeckoLib Source: https://wiki.geckolib.com/docs/geckolib5/concepts/animation/molang Demonstrates how to use the 'distance_from_camera' query to find the distance in blocks between an entity's center and the camera. Applicable to Entities. ```javascript function getDistanceFromCamera() { // Accessing the distance_from_camera query for an Entity const distanceFromCamera = query.distance_from_camera; console.log("Distance from camera:", distanceFromCamera, "blocks"); return distanceFromCamera; } ``` -------------------------------- ### Querying Entity Equipment Count in GeckoLib Source: https://wiki.geckolib.com/docs/geckolib5/concepts/animation/molang Shows how to use the 'equipment_count' query to get the number of worn items, excluding mainhand and offhand. Applicable to LivingEntities. ```javascript function getEquipmentCount() { // Accessing the equipment_count query for a LivingEntity const equipmentCount = query.equipment_count; console.log("Entity equipment count (excluding hands):", equipmentCount); return equipmentCount; } ``` -------------------------------- ### Create Custom DefaultedGeoModel Source: https://wiki.geckolib.com/docs/geckolib5/concepts/geomodels/defaulted-geomodel Provides an example of extending the DefaultedGeoModel class. By overriding the subtype method, developers can define custom subfolder structures for their assets. ```java public class ExampleCustomDefaultedGeoModel extends DefaultedGeoModel { public ExampleCustomDefaultedGeoModel(Identifier identifier) { super(identifier); } @Override protected String subtype() { return "custom"; } } ``` -------------------------------- ### Java Client Setup for GeckoLib Item Rendering (Fabric) Source: https://wiki.geckolib.com/docs/geckolib5/armor/copy-paste-templates Configures the GeoRenderProvider for a custom item on the client side using Fabric's initialization. This allows the item to use its defined animations and render models. ```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(); } }); } ``` -------------------------------- ### Retrieving Entity Head X Rotation in GeckoLib Source: https://wiki.geckolib.com/docs/geckolib5/concepts/animation/molang Demonstrates how to use the 'head_x_rotation' query to get the lerped pitch rotation of a LivingEntity's head. Applicable to LivingEntities. ```javascript function getHeadXRotation() { // Accessing the head_x_rotation query for a LivingEntity const headXRotation = query.head_x_rotation; console.log("LivingEntity head X rotation:", headXRotation); return headXRotation; } ``` -------------------------------- ### Querying Entity Walk Capability in GeckoLib Source: https://wiki.geckolib.com/docs/geckolib5/concepts/animation/molang Provides an example of using the 'can_walk' query to check if an entity can walk. It returns 1 if the entity's AI is not disabled and uses GroundPathNavigation or AmphibiousPathNavigation, otherwise 0. Applicable to Mobs. ```javascript function canEntityWalk() { // Accessing the can_walk query for a Mob const canWalk = query.can_walk; console.log("Entity can walk:", canWalk); return canWalk; } ``` -------------------------------- ### Getting Player Facing Direction in GeckoLib Source: https://wiki.geckolib.com/docs/geckolib5/concepts/animation/molang Provides an example of using the 'cardinal_player_facing' query to get the client player's facing direction as an ordinal (0=Down, 1=Up, 2=North, 3=South, 4=West, 5=East). This is a global query. ```javascript function getPlayerFacingDirection() { // Accessing the global cardinal_player_facing query const playerFacingDirection = query.cardinal_player_facing; console.log("Client player facing direction:", playerFacingDirection); return playerFacingDirection; } ``` -------------------------------- ### Querying Entity Health in GeckoLib Source: https://wiki.geckolib.com/docs/geckolib5/concepts/animation/molang Provides an example of using the 'health' query to get the current health of a LivingEntity. Applicable to LivingEntities. ```javascript function getEntityHealth() { // Accessing the health query for a LivingEntity const health = query.health; console.log("LivingEntity current health:", health); return health; } ``` -------------------------------- ### Getting Partial Tick in GeckoLib Source: https://wiki.geckolib.com/docs/geckolib5/concepts/animation/molang Provides an example of using the 'frame_alpha' query, which returns the fraction of a tick that has passed since the last tick (partialtick). Applicable to any animatable. ```javascript function getPartialTick() { // Accessing the frame_alpha query (partialtick) const partialTick = query.frame_alpha; console.log("Current partial tick:", partialTick); return partialTick; } ``` -------------------------------- ### Querying Entity Death Time in GeckoLib Source: https://wiki.geckolib.com/docs/geckolib5/concepts/animation/molang Provides an example of using the 'death_ticks' query to get the remaining time in ticks for an entity's death overlay. Applicable to LivingEntities. ```javascript function getEntityDeathTime() { // Accessing the death_ticks query for a LivingEntity const deathTicks = query.death_ticks; console.log("Entity death ticks remaining:", deathTicks); return deathTicks; } ``` -------------------------------- ### Implement DefaultedItemGeoModel Source: https://wiki.geckolib.com/docs/geckolib5/concepts/geomodels/defaulted-geomodel Demonstrates how to instantiate a DefaultedItemGeoModel using a namespaced identifier. This automatically maps to specific asset subfolders for items. ```java new DefaultedItemGeoModel(Identifier.fromNamespaceAndPath(ExampleMod.MOD_ID, "example_item")); ``` -------------------------------- ### Getting Entity Head Y Rotation in GeckoLib Source: https://wiki.geckolib.com/docs/geckolib5/concepts/animation/molang Shows how to use the 'head_y_rotation' query to get the lerped yaw rotation of a LivingEntity's head. Applicable to LivingEntities. ```javascript function getHeadYRotation() { // Accessing the head_y_rotation query for a LivingEntity const headYRotation = query.head_y_rotation; console.log("LivingEntity head Y rotation:", headYRotation); return headYRotation; } ``` -------------------------------- ### Getting Entity Hurt Time in GeckoLib Source: https://wiki.geckolib.com/docs/geckolib5/concepts/animation/molang Demonstrates how to use the 'hurt_time' query to get the remaining time in ticks for a LivingEntity's hurt overlay. Applicable to LivingEntities. ```javascript function getEntityHurtTime() { // Accessing the hurt_time query for a LivingEntity const hurtTime = query.hurt_time; console.log("LivingEntity hurt time remaining:", hurtTime, "ticks"); return hurtTime; } ``` -------------------------------- ### Apply Simple GeoItemRenderer Source: https://wiki.geckolib.com/docs/geckolib5/items/the-item-renderer Demonstrates how to instantiate a default GeoItemRenderer directly without creating a custom class. This is the recommended approach for items that do not require custom rendering logic. ```java () -> new GeoItemRenderer<>(ExampleItem.this); ``` -------------------------------- ### Registering a Simple GeoEntityRenderer Source: https://wiki.geckolib.com/docs/geckolib5/entities/the-entity-renderer Demonstrates the simplest way to register a renderer by passing a new instance of GeoEntityRenderer directly. This is suitable for entities that do not require custom rendering logic. ```Java // Fabric context -> new GeoEntityRenderer<>(context, EntityRegistry.EXAMPLE_ENTITY); ``` ```Java // Forge context -> new GeoEntityRenderer<>(context, EntityRegistry.EXAMPLE_ENTITY.get()); ``` ```Java // NeoForge context -> new GeoEntityRenderer<>(context, EntityRegistry.EXAMPLE_ENTITY.get()); ``` -------------------------------- ### GET /query/entity-attributes Source: https://wiki.geckolib.com/docs/geckolib5/concepts/animation/molang Retrieves numerical attributes and rotation data for entities, such as health, scale, and rider orientation. ```APIDOC ## GET /query/entity-attributes ### Description Retrieves specific numerical attributes or rotation data for an entity or living entity. ### Method GET ### Endpoint /query/{query_name} ### Parameters #### Path Parameters - **query_name** (string) - Required - The specific attribute query (e.g., query.max_health, query.scale, query.rider_head_y_rotation) ### Response #### Success Response (200) - **value** (float) - The numerical value of the requested attribute. #### Response Example { "value": 20.0 } ``` -------------------------------- ### Registering Animation Controllers with Priority Source: https://wiki.geckolib.com/docs/geckolib5/concepts/animation/controller/ordering Demonstrates how to register multiple animation controllers where the registration order determines priority. Controllers registered later take precedence over those registered earlier for the same bone transformations. ```java @Override public void registerControllers(AnimatableManager.ControllerRegistrar controllers) { controllers.add( DefaultAnimations.genericWalkIdleController(), DefaultAnimations.genericAttackController(this)); } ``` -------------------------------- ### Declare GeckoLib Dependency using Version Catalog Source: https://wiki.geckolib.com/docs/geckolib5/setup/fabric/quick-reference Demonstrates how to reference GeckoLib using a Version Catalog (libs.versions.toml) and apply it in the build.gradle file. ```TOML [libraries] geckolib = { group = "software.bernie.geckolib", name = "geckolib-fabric-26.1", version.ref = "geckolib" } ``` ```Groovy modImplementation libs.geckolib ``` ```Kotlin modImplementation(libs.geckolib) ``` -------------------------------- ### GET /query/entity-state Source: https://wiki.geckolib.com/docs/geckolib5/concepts/animation/molang Retrieves various boolean state flags for entities such as movement, fire status, and riding status. ```APIDOC ## GET /query/entity-state ### Description Returns boolean status flags (1 for true, 0 for false) regarding an entity's current physical state. ### Method GET ### Endpoint /query/{query_name} ### Parameters #### Path Parameters - **query_name** (string) - Required - The specific query to execute (e.g., query.is_moving, query.is_on_fire, query.is_sneaking) ### Response #### Success Response (200) - **value** (integer) - Returns 1 if the condition is met, otherwise 0. #### Response Example { "value": 1 } ``` -------------------------------- ### Apply Simple GeoArmorRenderer Source: https://wiki.geckolib.com/docs/geckolib5/armor/the-armor-renderer Demonstrates the simplest way to apply a renderer to an armor item by instantiating GeoArmorRenderer directly without a custom class. ```java () -> new GeoArmorRenderer<>(ExampleArmorItem.this); ``` -------------------------------- ### Registering a Custom Sound Keyframe Handler Source: https://wiki.geckolib.com/docs/geckolib5/miscellaneous/keyframe-markers Demonstrates how to implement a custom sound keyframe handler within the registerControllers method. This approach allows for manual control over sound playback triggered by animation keyframes. ```java @Override public void registerControllers(AnimatableManager.ControllerRegistrar controllers) { controllers.add(new AnimationController<>(animTest -> PlayState.STOP) .setSoundKeyframeHandler(state -> { Player player = ClientUtil.getClientPlayer(); if (player != null) player.playSound(SoundRegistry.EXAMPLE_SOUND.get(), 1, 1); })); } ``` -------------------------------- ### Implementing GeoItemRenderer in Armor Items Source: https://wiki.geckolib.com/docs/geckolib5/armor/applying-the-armor-renderer Demonstrates the step-by-step implementation of the createGeoRenderer method, including caching the renderer using Suppliers.memoize to optimize performance during render passes. ```java public class ExampleArmorItem extends Item implements GeoItem { @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(); } }); } } ``` -------------------------------- ### Getting Entity Y Body Rotation with GeckoLib Source: https://wiki.geckolib.com/docs/geckolib5/concepts/animation/molang Shows how to use the 'body_y_rotation' query to obtain the yaw rotation of an entity. This query is applicable to all Entities. ```javascript function getBodyYRotation() { // Accessing the body_y_rotation query for an Entity const yRotation = query.body_y_rotation; console.log("Entity Y body rotation:", yRotation); return yRotation; } ``` -------------------------------- ### Configure GeckoLib in libs.versions.toml Source: https://wiki.geckolib.com/docs/geckolib5/setup/forge/adding-the-dependency Define the GeckoLib library in the version catalog file to manage dependencies centrally. This allows for cleaner build.gradle files. ```TOML geckolib = { group = "com.geckolib", name = "geckolib-forge-26.1", version.ref = "geckolib" } ``` -------------------------------- ### Retrieving Entity X Body Rotation in GeckoLib Source: https://wiki.geckolib.com/docs/geckolib5/concepts/animation/molang Demonstrates how to get the 'body_x_rotation' query, which represents the pitch rotation of an entity. This query applies to all Entities. ```javascript function getBodyXRotation() { // Accessing the body_x_rotation query for an Entity const xRotation = query.body_x_rotation; console.log("Entity X body rotation:", xRotation); return xRotation; } ``` -------------------------------- ### Creating an Advanced Custom Renderer Class Source: https://wiki.geckolib.com/docs/geckolib5/entities/the-entity-renderer Shows how to create a custom renderer class extending GeoEntityRenderer. This allows for overriding methods to implement complex rendering behaviors. ```Java public class ExampleEntityRenderer extends GeoEntityRenderer { public ExampleEntityRenderer(EntityRendererProvider.Context context, EntityType entityType) { super(context, entityType); } } ``` -------------------------------- ### Implement GeckoLib Dependency using libs.versions.toml (Groovy) Source: https://wiki.geckolib.com/docs/geckolib5/setup/forge/quick-reference Implements the GeckoLib dependency in your build.gradle file using Groovy syntax, referencing the definition in libs.versions.toml. This promotes cleaner dependency management. ```groovy implementation minecraft.dependency(libs.geckolib) ``` -------------------------------- ### Forge/NeoForge Client Setup for GeoRenderProvider Source: https://wiki.geckolib.com/docs/geckolib5/armor/applying-the-armor-renderer Registers the geoRenderProvider for an item using the EntityRenderersEvent.RegisterRenderers event for Forge and NeoForge mods. It utilizes a memoized supplier for efficient GeoArmorRenderer creation. ```java @SubscribeEvent public static void registerRenderers(final EntityRenderersEvent.RegisterRenderers event) { ItemRegistry.EXAMPLE_ARMOR_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(); } }); } ``` ```java @SubscribeEvent public static void registerRenderers(final EntityRenderersEvent.RegisterRenderers event) { ItemRegistry.EXAMPLE_ARMOR_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(); } }); } ``` -------------------------------- ### Querying Entity Headgear Status in GeckoLib Source: https://wiki.geckolib.com/docs/geckolib5/concepts/animation/molang Provides an example of using the 'has_head_gear' query to check if a LivingEntity is wearing headgear. Returns 1 if true, 0 otherwise. ```javascript function hasEntityHeadgear() { // Accessing the has_head_gear query for a LivingEntity const hasHeadgear = query.has_head_gear; console.log("LivingEntity has headgear:", hasHeadgear); return hasHeadgear; } ``` -------------------------------- ### Create Base Armor Item Class (Java) Source: https://wiki.geckolib.com/docs/geckolib5/armor/the-item-class This snippet shows the initial creation of a custom armor item class that extends the base `Item` class and implements a constructor to handle armor material, type, and properties. ```java public class ExampleArmorItem extends Item { public ExampleArmorItem(ArmorMaterial material, ArmorType type, Properties properties) { super(properties.humanoidArmor(material, type)); } } ``` -------------------------------- ### Configuring Split Source Renderers Source: https://wiki.geckolib.com/docs/geckolib5/armor/applying-the-armor-renderer Shows how to handle client-server split source environments by using a MutableObject to store the GeoRenderProvider, ensuring the renderer is accessible across different source sets. ```java public class ExampleArmorItem extends Item implements GeoItem { public final MutableObject geoRenderProvider = new MutableObject<>(); @Override public void createGeoRenderer(Consumer consumer) { consumer.accept(this.geoRenderProvider.getValue()); } } ``` -------------------------------- ### Querying Entity Invulnerable Time in GeckoLib Source: https://wiki.geckolib.com/docs/geckolib5/concepts/animation/molang Shows how to use the 'invulnerable_ticks' query to get the remaining invulnerability time in ticks after a LivingEntity takes damage. Applicable to LivingEntities. ```javascript function getEntityInvulnerableTime() { // Accessing the invulnerable_ticks query for a LivingEntity const invulnerableTime = query.invulnerable_ticks; console.log("LivingEntity invulnerable time remaining:", invulnerableTime, "ticks"); return invulnerableTime; } ``` -------------------------------- ### Querying Entity Ground Speed in GeckoLib Source: https://wiki.geckolib.com/docs/geckolib5/concepts/animation/molang Shows how to use the 'ground_speed' query to get the current lateral velocity of an entity in blocks per tick. Applicable to LivingEntities. ```javascript function getGroundSpeed() { // Accessing the ground_speed query for a LivingEntity const groundSpeed = query.ground_speed; console.log("Entity ground speed:", groundSpeed, "blocks/tick"); return groundSpeed; } ``` -------------------------------- ### Use GeckoLib Dependency from libs.versions.toml Source: https://wiki.geckolib.com/docs/geckolib5/setup/fabric/adding-the-dependency This snippet illustrates how to reference the previously defined GeckoLib library from your build.gradle file using the alias defined in libs.versions.toml. It supports both Groovy and Kotlin DSL syntax. ```groovy modImplementation libs.geckolib ``` ```kotlin modImplementation(libs.geckolib) ``` -------------------------------- ### Getting World Day Number in GeckoLib Source: https://wiki.geckolib.com/docs/geckolib5/concepts/animation/molang Shows how to use the 'day' query to retrieve the current day number in the world. This is a global query and returns a non-integer value. ```javascript function getWorldDay() { // Accessing the global day query const worldDay = query.day; console.log("Current world day:", worldDay); return worldDay; } ``` -------------------------------- ### Instantiate AnimatableInstanceCache (Java) Source: https://wiki.geckolib.com/docs/geckolib5/entities/replaced-entities/creating-the-entity-class This final code snippet demonstrates how to properly instantiate and return an AnimatableInstanceCache. It involves creating a final field for the cache and initializing it using GeckoLibUtil.createInstanceCache(), ensuring correct animation management. ```java public class ExampleReplacedEntity implements GeoReplacedEntity { private final AnimatableInstanceCache geoCache = GeckoLibUtil.createInstanceCache(this); @Override public EntityType getReplacingEntityType() { return EntityType.CREEPER; } @Override public void registerControllers(final AnimatableManager.ControllerRegistrar controllers) { // We can fill this in later } @Override public AnimatableInstanceCache getAnimatableInstanceCache() { return this.geoCache; } } ``` -------------------------------- ### Implement GeckoLib Dependency using libs.versions.toml (Kotlin) Source: https://wiki.geckolib.com/docs/geckolib5/setup/forge/quick-reference Implements the GeckoLib dependency in your build.gradle file using Kotlin syntax, utilizing the library definition from libs.versions.toml. This approach streamlines dependency updates. ```kotlin implementation(minecraft.dependency(libs.geckolib)) ``` -------------------------------- ### Checking Entity Is Alive Status in GeckoLib Source: https://wiki.geckolib.com/docs/geckolib5/concepts/animation/molang Provides an example of using the 'is_alive' query to check if an entity is alive. Returns 1 if alive, 0 otherwise. Applicable to Entities. ```javascript function isEntityAlive() { // Accessing the is_alive query for an Entity const isAlive = query.is_alive; console.log("Entity is alive:", isAlive); return isAlive; } ``` -------------------------------- ### Declare GeckoLib Repository Source: https://wiki.geckolib.com/docs/geckolib5/setup/neoforge/quick-reference Configure your project's repositories to include the GeckoLib Maven repository. This allows Gradle to download GeckoLib artifacts. ```groovy repositories { exclusiveContent { forRepository { maven { name = 'GeckoLib' url = 'https://dl.cloudsmith.io/public/geckolib3/geckolib/maven/' } } filter { includeGroupAndSubgroups('software.bernie.geckolib') } } } ``` ```kotlin repositories { exclusiveContent { forRepository { maven { name = "GeckoLib" url = uri("https://dl.cloudsmith.io/public/geckolib3/geckolib/maven/") } } filter { includeGroupAndSubgroups("software.bernie.geckolib") } } } ``` -------------------------------- ### Checking Entity Passenger Status in GeckoLib Source: https://wiki.geckolib.com/docs/geckolib5/concepts/animation/molang Provides an example of using the 'has_rider' query to check if an entity has any passenger. Returns 1 if true, 0 otherwise. Applicable to Entities. ```javascript function hasPassenger() { // Accessing the has_rider query for an Entity const hasRider = query.has_rider; console.log("Entity has a passenger:", hasRider); return hasRider; } ``` -------------------------------- ### Manually Animate Bone with BoneSnapshots in Java Source: https://wiki.geckolib.com/docs/geckolib5/concepts/geobones/bone-snapshots An example demonstrating how to manually animate a specific bone by name using BoneSnapshots. It rotates the bone named 'MyBoneName' by 45 degrees. ```Java @Override public void adjustModelBonesForRender(RenderPassInfo renderPassInfo, BoneSnapshots snapshots) { snapshots.ifPresent("MyBoneName", boneSnapshot -> { boneSnapshot.setRotX(45 * Mth.DEG_TO_RAD); }); } ``` -------------------------------- ### Create Base Item Class with GeckoLib Source: https://wiki.geckolib.com/docs/geckolib5/items/the-item-class This snippet shows the initial creation of a Java item class that extends the base Item class. It includes the constructor required for item initialization. ```java public class ExampleItem extends Item { public ExampleItem(Properties properties) { super(properties); } } ``` -------------------------------- ### Using Animation Time Query in GeckoLib Source: https://wiki.geckolib.com/docs/geckolib5/concepts/animation/molang Shows how to use the 'anim_time' query to get the current animation's running time in seconds. This query is applicable to any animatable entity. ```javascript function getAnimationTime() { // Accessing the anim_time query for the current animation const animationTime = query.anim_time; console.log("Animation running for:", animationTime, "seconds"); return animationTime; } ``` -------------------------------- ### Querying Entity Is Breathing Status in GeckoLib Source: https://wiki.geckolib.com/docs/geckolib5/concepts/animation/molang Provides an example of using the 'is_breathing' query to check if an entity has full air. Returns 1 if true, 0 otherwise. Applicable to Entities. ```javascript function isEntityBreathing() { // Accessing the is_breathing query for an Entity const isBreathing = query.is_breathing; console.log("Entity has full air:", isBreathing); return isBreathing; } ``` -------------------------------- ### Register Simple GeoBlockRenderer (Fabric/Forge/NeoForge) Source: https://wiki.geckolib.com/docs/geckolib5/blocks/the-blockentity-renderer This demonstrates the straightforward method of registering a block entity renderer by instantiating `GeoBlockRenderer` directly. It's suitable when no custom rendering logic is needed beyond what GeckoLib provides. The `BlockEntityType` is passed to the constructor. ```java context -> new GeoBlockRenderer<>(context, BlockEntityRegistry.EXAMPLE_BLOCK_ENTITY); ``` ```java context -> new GeoBlockRenderer<>(context, BlockEntityRegistry.EXAMPLE_BLOCK_ENTITY.get()); ``` ```java context -> new GeoBlockRenderer<>(context, BlockEntityRegistry.EXAMPLE_BLOCK_ENTITY.get()); ``` -------------------------------- ### Define GeckoLib Library in libs.versions.toml Source: https://wiki.geckolib.com/docs/geckolib5/setup/forge/quick-reference Defines the GeckoLib library entry in your libs.versions.toml file. This centralizes version management and simplifies dependency declarations. Remember to update '26.1' to your target Minecraft version. ```toml geckolib = { group = "software.bernie.geckolib", name = "geckolib-forge-26.1", version.ref = "geckolib" } ``` -------------------------------- ### Checking Blocking Status with GeckoLib Query Source: https://wiki.geckolib.com/docs/geckolib5/concepts/animation/molang Provides an example of using the 'blocking' query to check if an entity is currently blocking. It returns 1 if blocking, otherwise 0. Applicable to LivingEntities. ```javascript function isEntityBlocking() { // Accessing the blocking query for a LivingEntity const blockingStatus = query.blocking; console.log("Entity blocking status:", blockingStatus); return blockingStatus; } ``` -------------------------------- ### Create Base Entity Class - Java Source: https://wiki.geckolib.com/docs/geckolib5/entities/the-entity-class Initializes the base entity class by extending PathfinderMob. This is the foundational step for creating a new entity. ```Java public class ExampleEntity extends PathfinderMob { public ExampleEntity(EntityType entityType, Level level) { super(entityType, level); } } ```