AzAnimator Basics

The AzAnimator is the core system in AzureLib designed to manage the animation logic for various objects, such as entities, block entities, or items. This system provides a reusable framework for integrating MoLang-based animations, custom animation controllers, and smooth transition mechanisms.

Overview of AzAnimator

The AzAnimator is an abstract class with the following key features:

  • It manages animation states and transitions for objects (T) like entities, blocks, and items.
  • It caches and reuses animation data for performance.
  • It provides an extensible structure using animation controllers and Molang queries.

Key Responsibilities

  1. Controller Registration Define and register animation controllers responsible for managing behavioral animations.

  2. Animation Execution Process animations for entities or objects using MoLang queries and baked models.

  3. Custom Animations Overrideable hooks allow custom animations unique to animated objects.

Core Methods

1. registerControllers

  • Abstract method where animation controllers must be created and registered:
    public abstract void registerControllers(AzAnimationControllerContainer<T> animationControllerContainer);
  • Example Usage: Define specific controllers (e.g., idle, walking, interactions) for your entity or object.
  • Controllers are applied in the order they are added. When several controllers animate the same bone, each one is layered on top of the ones before it; see Layering Controllers.
  • A controller can cycle through random animation variants on its own, such as several idles, using a weighted pool; see Random Animation Pools. The controller's transition length controls how the variants blend into each other.

2. getAnimationLocation

  • Abstract method for locating the animation file for the animatable object:
    public abstract @NotNull ResourceLocation getAnimationLocation(T animatable);

3. setCustomAnimations

  • Override this method to define custom animations or behaviors:
    public void setCustomAnimations(T animatable, float partialTicks)
    This is useful for unique animations that aren't predefined in the animation file. Values set here become part of the animated pose; see Writing Bones Directly.

4. registerPoseModifiers

  • Override this method to add pose modifiers, which adjust the animated pose every frame after setCustomAnimations:
    protected void registerPoseModifiers(AzPoseModifierRegistry<T> modifiers)
    Called once, before the first frame. Modifiers can be weighted, faded, ordered and limited to certain bones, and their changes never carry over into the next frame. Inverse kinematics, look-at and spring bones are added here too. See Procedural Animation.
  • Modifiers can also be added or removed later through getPoseModifiers(), and weighted per animatable through context().poseLayer().

5. addUpdateHook

  • Runs code every frame just before the controllers update, for example to set controller weights from per-frame values:
    public void addUpdateHook(AzAnimatorUpdateHook<T> hook)
    Blend spaces use this to drive their controllers. Remove a hook with removeUpdateHook.

6. onFirstAnimate

  • Called once, on the animator's first frame, right before the controllers update for the first time. A good place to start an entity's spawn or idle animation.

MoLang Integration

The applyMolangQueries method facilitates MoLang runtime queries that affect animation states

MoLang Queries Supported:

  • LIFE_TIME: Determines how long the animation has been running.
  • TIME_OF_DAY: Retrieves the in-game time.
  • ACTOR_COUNT: Returns the number of entities in the world.
  • MOON_PHASE: Identifies the moon cycle.