package net.minecraft.client.model;

import net.minecraft.world.entity.HumanoidArm;
import net.minecraft.world.entity.Mob;
import net.minecraft.util.Mth;
import net.minecraft.world.item.CrossbowItem;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.client.model.geom.ModelPart;

public class AnimationUtils {
    public static void animateCrossbowHold(final ModelPart dyg1, final ModelPart dyg2, final ModelPart dyg3, final boolean boolean4) {
        final ModelPart dyg4 = boolean4 ? dyg1 : dyg2;
        final ModelPart dyg5 = boolean4 ? dyg2 : dyg1;
        dyg4.yRot = (boolean4 ? -0.3f : 0.3f) + dyg3.yRot;
        dyg5.yRot = (boolean4 ? 0.6f : -0.6f) + dyg3.yRot;
        dyg4.xRot = -1.5707964f + dyg3.xRot + 0.1f;
        dyg5.xRot = -1.5f + dyg3.xRot;
    }
    
    public static void animateCrossbowCharge(final ModelPart dyg1, final ModelPart dyg2, final LivingEntity aoy, final boolean boolean4) {
        final ModelPart dyg3 = boolean4 ? dyg1 : dyg2;
        final ModelPart dyg4 = boolean4 ? dyg2 : dyg1;
        dyg3.yRot = (boolean4 ? -0.8f : 0.8f);
        dyg3.xRot = -0.97079635f;
        dyg4.xRot = dyg3.xRot;
        final float float7 = (float)CrossbowItem.getChargeDuration(aoy.getUseItem());
        final float float8 = Mth.clamp((float)aoy.getTicksUsingItem(), 0.0f, float7);
        final float float9 = float8 / float7;
        dyg4.yRot = Mth.lerp(float9, 0.4f, 0.85f) * (boolean4 ? 1 : -1);
        dyg4.xRot = Mth.lerp(float9, dyg4.xRot, -1.5707964f);
    }
    
    public static <T extends Mob> void swingWeaponDown(final ModelPart dyg1, final ModelPart dyg2, final T aoz, final float float4, final float float5) {
        final float float6 = Mth.sin(float4 * 3.1415927f);
        final float float7 = Mth.sin((1.0f - (1.0f - float4) * (1.0f - float4)) * 3.1415927f);
        dyg1.zRot = 0.0f;
        dyg2.zRot = 0.0f;
        dyg1.yRot = 0.15707964f;
        dyg2.yRot = -0.15707964f;
        if (aoz.getMainArm() == HumanoidArm.RIGHT) {
            dyg1.xRot = -1.8849558f + Mth.cos(float5 * 0.09f) * 0.15f;
            dyg2.xRot = -0.0f + Mth.cos(float5 * 0.19f) * 0.5f;
            dyg1.xRot += float6 * 2.2f - float7 * 0.4f;
            dyg2.xRot += float6 * 1.2f - float7 * 0.4f;
        }
        else {
            dyg1.xRot = -0.0f + Mth.cos(float5 * 0.19f) * 0.5f;
            dyg2.xRot = -1.8849558f + Mth.cos(float5 * 0.09f) * 0.15f;
            dyg1.xRot += float6 * 1.2f - float7 * 0.4f;
            dyg2.xRot += float6 * 2.2f - float7 * 0.4f;
        }
        bobArms(dyg1, dyg2, float5);
    }
    
    public static void bobArms(final ModelPart dyg1, final ModelPart dyg2, final float float3) {
        dyg1.zRot += Mth.cos(float3 * 0.09f) * 0.05f + 0.05f;
        dyg2.zRot -= Mth.cos(float3 * 0.09f) * 0.05f + 0.05f;
        dyg1.xRot += Mth.sin(float3 * 0.067f) * 0.05f;
        dyg2.xRot -= Mth.sin(float3 * 0.067f) * 0.05f;
    }
    
    public static void animateZombieArms(final ModelPart dyg1, final ModelPart dyg2, final boolean boolean3, final float float4, final float float5) {
        final float float6 = Mth.sin(float4 * 3.1415927f);
        final float float7 = Mth.sin((1.0f - (1.0f - float4) * (1.0f - float4)) * 3.1415927f);
        dyg2.zRot = 0.0f;
        dyg1.zRot = 0.0f;
        dyg2.yRot = -(0.1f - float6 * 0.6f);
        dyg1.yRot = 0.1f - float6 * 0.6f;
        final float float8 = -3.1415927f / (boolean3 ? 1.5f : 2.25f);
        dyg2.xRot = float8;
        dyg1.xRot = float8;
        dyg2.xRot += float6 * 1.2f - float7 * 0.4f;
        dyg1.xRot += float6 * 1.2f - float7 * 0.4f;
        bobArms(dyg2, dyg1, float5);
    }
}
