Animating Entities Within SmartBrainLib Tasks

AzureLib supports using SmartBrainLib to handle animating entities within their AI, allowing for animations, such as attack animations, to be programmed into the entity itself and called when the entity AI performs said task(s).

Adding a new AnimationController

Within your entity's AzEntityAnimator class, within the registerControllers method, you can add a secondary AzAnimationController, like so:

// ... Somewhere in your project
public static final RawAnimation ATTACK = RawAnimation.begin().then("attack", LoopType.PLAY_ONCE);
// ... In registerControllers
.add(new AnimationController<>(this, "attackController", 1, event -> PlayState.STOP).triggerableAnim("melee", ATTACK));

Defining the Dispatcher

The following section is only applicable to Azurelib 3.x

public class MyEntityDispatcher {
public static final AzCommand GENERIC_ATTACK_COMMAND = AzCommand.create("attack_controller", "attack", AzPlayBehaviors.PLAY_ONCE)
private final Entity entity;
public MyEntityDispatcher(Entity animatable) {this.entity = animatable;}
public void genericAttack() {
GENERIC_ATTACK_COMMAND.sendForEntity(entity);
}
// ... Rest of the Entity Animation Dispatcher code
}

Calling the Animation

Within your entity's BrainActivityGroup method, within the Behavior[] lists, you can utilize a lambda to extend the function of an existing Behavior, like so:

// ... Within getFightTasks()
(new AnimatableMeleeAttack<>(0)).whenStarting((entity) -> {this.triggerAnim("attackController", "melee");})

This example has an entity performing a generic melee attack animation immediately when the attack task begins.

Tips for Animating with SmartBrainLib and AzureLib

  1. Unified names:
    • AzureLib fully supports the use of enums and string variables in place of directly providing strings.
    • Using variables instead of strings helps reduce errors caused by typos or inconsistencies, and is generally a good practice.
    • For the purposes of keeping documentation simple, the practice of making a common entity Dispatcher and Animator class was not used.
  2. Tasks with hit delays:
    • When timing attack animations with the hit calculation, remember that Minecraft performs calculations at a speed of 20 ticks per second
    • To change the delay, such as if the hit calculation should sync at 0.5 seconds, you would set the tick delay to (for example) AnimatableMeleeAttack<>(10), where 10 is the equivalent to 0.5 seconds in real time.
  3. Stopping all movement to perform an animation:
    • With the above in consideration, in the whenStarting() method, a status effect can be applied to the entity, as so:
    this.addEffect(new MobEffectInstance(MobEffects.MOVEMENT_SLOWDOWN, 10, 20, false, false));