package net.minecraft.world.entity.projectile;

import net.minecraft.network.protocol.game.ClientboundAddEntityPacket;
import net.minecraft.network.protocol.Packet;
import net.minecraft.world.phys.BlockHitResult;
import net.minecraft.world.damagesource.DamageSource;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.phys.EntityHitResult;
import net.minecraft.world.phys.HitResult;
import net.minecraft.world.phys.Vec3;
import net.minecraft.world.level.block.state.BlockBehaviour;
import net.minecraft.world.level.ClipContext;
import net.minecraft.core.particles.ParticleOptions;
import net.minecraft.core.particles.ParticleTypes;
import net.minecraft.util.Mth;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.animal.horse.Llama;
import net.minecraft.world.level.Level;
import net.minecraft.world.entity.EntityType;

public class LlamaSpit extends Projectile {
    public LlamaSpit(final EntityType<? extends LlamaSpit> aoq, final Level bqb) {
        super(aoq, bqb);
    }
    
    public LlamaSpit(final Level bqb, final Llama azp) {
        this(EntityType.LLAMA_SPIT, bqb);
        super.setOwner(azp);
        this.setPos(azp.getX() - (azp.getBbWidth() + 1.0f) * 0.5 * Mth.sin(azp.yBodyRot * 0.017453292f), azp.getEyeY() - 0.10000000149011612, azp.getZ() + (azp.getBbWidth() + 1.0f) * 0.5 * Mth.cos(azp.yBodyRot * 0.017453292f));
    }
    
    public LlamaSpit(final Level bqb, final double double2, final double double3, final double double4, final double double5, final double double6, final double double7) {
        this(EntityType.LLAMA_SPIT, bqb);
        this.setPos(double2, double3, double4);
        for (int integer15 = 0; integer15 < 7; ++integer15) {
            final double double8 = 0.4 + 0.1 * integer15;
            bqb.addParticle(ParticleTypes.SPIT, double2, double3, double4, double5 * double8, double6, double7 * double8);
        }
        this.setDeltaMovement(double5, double6, double7);
    }
    
    @Override
    public void tick() {
        super.tick();
        final Vec3 dem2 = this.getDeltaMovement();
        final HitResult dej3 = ProjectileUtil.getHitResult(this, this::canHitEntity, ClipContext.Block.OUTLINE);
        if (dej3 != null) {
            this.onHit(dej3);
        }
        final double double4 = this.getX() + dem2.x;
        final double double5 = this.getY() + dem2.y;
        final double double6 = this.getZ() + dem2.z;
        this.updateRotation();
        final float float10 = 0.99f;
        final float float11 = 0.06f;
        if (this.level.getBlockStates(this.getBoundingBox()).noneMatch(BlockBehaviour.BlockStateBase::isAir)) {
            this.remove();
            return;
        }
        if (this.isInWaterOrBubble()) {
            this.remove();
            return;
        }
        this.setDeltaMovement(dem2.scale(0.9900000095367432));
        if (!this.isNoGravity()) {
            this.setDeltaMovement(this.getDeltaMovement().add(0.0, -0.05999999865889549, 0.0));
        }
        this.setPos(double4, double5, double6);
    }
    
    @Override
    protected void onHitEntity(final EntityHitResult dei) {
        super.onHitEntity(dei);
        final Entity aom3 = this.getOwner();
        if (aom3 instanceof LivingEntity) {
            dei.getEntity().hurt(DamageSource.indirectMobAttack(this, (LivingEntity)aom3).setProjectile(), 1.0f);
        }
    }
    
    @Override
    protected void onHitBlock(final BlockHitResult deh) {
        super.onHitBlock(deh);
        if (!this.level.isClientSide) {
            this.remove();
        }
    }
    
    @Override
    protected void defineSynchedData() {
    }
    
    @Override
    public Packet<?> getAddEntityPacket() {
        return new ClientboundAddEntityPacket(this);
    }
}
