package net.minecraft.world.entity.monster;

import com.mojang.math.Quaternion;
import com.mojang.math.Vector3f;
import net.minecraft.world.entity.Entity;
import net.minecraft.sounds.SoundEvents;
import net.minecraft.world.phys.Vec3;
import net.minecraft.util.Mth;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.item.CrossbowItem;
import net.minecraft.world.entity.projectile.ProjectileUtil;
import net.minecraft.world.item.Items;
import javax.annotation.Nullable;
import net.minecraft.world.entity.projectile.Projectile;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.entity.LivingEntity;

public interface CrossbowAttackMob extends RangedAttackMob {
    void setChargingCrossbow(final boolean boolean1);
    
    void shootCrossbowProjectile(final LivingEntity aoy, final ItemStack bki, final Projectile bes, final float float4);
    
    @Nullable
    LivingEntity getTarget();
    
    void onCrossbowAttackPerformed();
    
    default void performCrossbowAttack(final LivingEntity aoy, final float float2) {
        final InteractionHand anf4 = ProjectileUtil.getWeaponHoldingHand(aoy, Items.CROSSBOW);
        final ItemStack bki5 = aoy.getItemInHand(anf4);
        if (aoy.isHolding(Items.CROSSBOW)) {
            CrossbowItem.performShooting(aoy.level, aoy, anf4, bki5, float2, (float)(14 - aoy.level.getDifficulty().getId() * 4));
        }
        this.onCrossbowAttackPerformed();
    }
    
    default void shootCrossbowProjectile(final LivingEntity aoy1, final LivingEntity aoy2, final Projectile bes, final float float4, final float float5) {
        final Entity aom7 = bes;
        final double double8 = aoy2.getX() - aoy1.getX();
        final double double9 = aoy2.getZ() - aoy1.getZ();
        final double double10 = Mth.sqrt(double8 * double8 + double9 * double9);
        final double double11 = aoy2.getY(0.3333333333333333) - aom7.getY() + double10 * 0.20000000298023224;
        final Vector3f g16 = this.getProjectileShotVector(aoy1, new Vec3(double8, double11, double9), float4);
        bes.shoot(g16.x(), g16.y(), g16.z(), float5, (float)(14 - aoy1.level.getDifficulty().getId() * 4));
        aoy1.playSound(SoundEvents.CROSSBOW_SHOOT, 1.0f, 1.0f / (aoy1.getRandom().nextFloat() * 0.4f + 0.8f));
    }
    
    default Vector3f getProjectileShotVector(final LivingEntity aoy, final Vec3 dem, final float float3) {
        final Vec3 dem2 = dem.normalize();
        Vec3 dem3 = dem2.cross(new Vec3(0.0, 1.0, 0.0));
        if (dem3.lengthSqr() <= 1.0E-7) {
            dem3 = dem2.cross(aoy.getUpVector(1.0f));
        }
        final Quaternion d7 = new Quaternion(new Vector3f(dem3), 90.0f, true);
        final Vector3f g8 = new Vector3f(dem2);
        g8.transform(d7);
        final Quaternion d8 = new Quaternion(g8, float3, true);
        final Vector3f g9 = new Vector3f(dem2);
        g9.transform(d8);
        return g9;
    }
}
