Conditional Animations - ZigyTheBird/ZigysPlayerAnimatorAPI GitHub Wiki

When playing an animation if certain conditions are met they can be changed to that animation plus a specific extension.
For example by default if you play the animation minecraft:example and you start running the animation will switch to minecraft:example_run. (If it exists)
By default the mod uses the extensions _run, _crouch, _crawl and _swim which are all self explanatory.
You may add your own conditional animations for animations from your mod here is an example:

    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;
    }