How to trigger Item Animations

Setting up your Item

In your Item class, add SingletonGeoAnimatable.registerSyncedAnimatable to your constructor. This is needed to sync the animations from the server to the clients.

Next in your registerControllers add triggerableAnim to your controller like so

@Override
public void registerControllers(ControllerRegistrar controllers) {
controllers.add(
    new AnimationController<>(this, "controllerName", event -> PlayState.CONTINUE)
        .triggerableAnim("animation", 
            RawAnimation.begin().then("animation", LoopType.PLAY_ONCE)));
}

You can add more triggers for each animation you need on your item.

Calling the trigger

To call the trigger, you will simply need to call triggerAnim wherever you wish to use the trigger, ensuring you are calling the server side only. Here is an example of calling on the onUseTick method of an item

@Override
public void onUseTick(Level level, LivingEntity entity, ItemStack stack, int count) {
    if (entity instanceof Player player)
        if (!level.isClientSide())
            triggerAnim(player, GeoItem.getOrAssignId(stack, (ServerLevel) level), "controllerName", "animation");
}

Last updated