Conditional Animations - ZigyTheBird/ZigysPlayerAnimatorAPI GitHub Wiki

When playing an animation you can add certain criteria that once met will change the animation without resetting it's progress.
Here is an example of how you can use this feature:

    public static void clientInit() {
        ConditionalAnimations.addModConditions("examplemod", ClientInit::getAnimationForCurrentConditions);
    }

    public static ResourceLocation getAnimationForCurrentConditions(PlayerAnimationData data) {
        AbstractClientPlayer player = (AbstractClientPlayer) Minecraft.getInstance().level.getPlayerByUUID(data.playerUUID());
        CustomModifierLayer animationContainer = (CustomModifierLayer) PlayerAnimationAccess.getPlayerAssociatedData(player).get(animationLayerId);

        ResourceLocation currentAnim = animationContainer.currentAnim;
        ResourceLocation baseAnim = data.animationID();
        ResourceLocation useAnim = data.animationID().withPath(data.animationID().getPath() + "_use");

        Map<ResourceLocation, KeyframeAnimation> animations = PlayerAnimationRegistry.getAnimations();

        if (player.isUsingItem() && currentAnim != useAnim && animations.containsKey(useAnim)) {
            return useAnim;
        }

        return baseAnim;
    }