package net.minecraft.world.entity.projectile;

import net.minecraft.network.syncher.SynchedEntityData;
import net.minecraft.network.syncher.EntityDataSerializers;
import net.minecraft.world.level.GameRules;
import net.minecraft.world.phys.HitResult;
import net.minecraft.world.effect.MobEffectInstance;
import net.minecraft.world.effect.MobEffects;
import net.minecraft.world.Difficulty;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.damagesource.DamageSource;
import net.minecraft.world.phys.EntityHitResult;
import net.minecraft.world.entity.boss.wither.WitherBoss;
import net.minecraft.world.level.material.FluidState;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.core.BlockPos;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.Explosion;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.level.Level;
import net.minecraft.world.entity.EntityType;
import net.minecraft.network.syncher.EntityDataAccessor;

public class WitherSkull extends AbstractHurtingProjectile {
    private static final EntityDataAccessor<Boolean> DATA_DANGEROUS;
    
    public WitherSkull(final EntityType<? extends WitherSkull> aoq, final Level bqb) {
        super(aoq, bqb);
    }
    
    public WitherSkull(final Level bqb, final LivingEntity aoy, final double double3, final double double4, final double double5) {
        super(EntityType.WITHER_SKULL, aoy, double3, double4, double5, bqb);
    }
    
    public WitherSkull(final Level bqb, final double double2, final double double3, final double double4, final double double5, final double double6, final double double7) {
        super(EntityType.WITHER_SKULL, double2, double3, double4, double5, double6, double7, bqb);
    }
    
    @Override
    protected float getInertia() {
        return this.isDangerous() ? 0.73f : super.getInertia();
    }
    
    @Override
    public boolean isOnFire() {
        return false;
    }
    
    @Override
    public float getBlockExplosionResistance(final Explosion bpt, final BlockGetter bpg, final BlockPos fu, final BlockState cfj, final FluidState cxa, final float float6) {
        if (this.isDangerous() && WitherBoss.canDestroy(cfj)) {
            return Math.min(0.8f, float6);
        }
        return float6;
    }
    
    @Override
    protected void onHitEntity(final EntityHitResult dei) {
        super.onHitEntity(dei);
        if (this.level.isClientSide) {
            return;
        }
        final Entity aom3 = dei.getEntity();
        final Entity aom4 = this.getOwner();
        boolean boolean5;
        if (aom4 instanceof LivingEntity) {
            final LivingEntity aoy6 = (LivingEntity)aom4;
            boolean5 = aom3.hurt(DamageSource.witherSkull(this, aoy6), 8.0f);
            if (boolean5) {
                if (aom3.isAlive()) {
                    this.doEnchantDamageEffects(aoy6, aom3);
                }
                else {
                    aoy6.heal(5.0f);
                }
            }
        }
        else {
            boolean5 = aom3.hurt(DamageSource.MAGIC, 5.0f);
        }
        if (boolean5 && aom3 instanceof LivingEntity) {
            int integer6 = 0;
            if (this.level.getDifficulty() == Difficulty.NORMAL) {
                integer6 = 10;
            }
            else if (this.level.getDifficulty() == Difficulty.HARD) {
                integer6 = 40;
            }
            if (integer6 > 0) {
                ((LivingEntity)aom3).addEffect(new MobEffectInstance(MobEffects.WITHER, 20 * integer6, 1));
            }
        }
    }
    
    @Override
    protected void onHit(final HitResult dej) {
        super.onHit(dej);
        if (!this.level.isClientSide) {
            final Explosion.BlockInteraction a3 = this.level.getGameRules().getBoolean(GameRules.RULE_MOBGRIEFING) ? Explosion.BlockInteraction.DESTROY : Explosion.BlockInteraction.NONE;
            this.level.explode(this, this.getX(), this.getY(), this.getZ(), 1.0f, false, a3);
            this.remove();
        }
    }
    
    @Override
    public boolean isPickable() {
        return false;
    }
    
    @Override
    public boolean hurt(final DamageSource anw, final float float2) {
        return false;
    }
    
    @Override
    protected void defineSynchedData() {
        this.entityData.<Boolean>define(WitherSkull.DATA_DANGEROUS, false);
    }
    
    public boolean isDangerous() {
        return this.entityData.<Boolean>get(WitherSkull.DATA_DANGEROUS);
    }
    
    public void setDangerous(final boolean boolean1) {
        this.entityData.<Boolean>set(WitherSkull.DATA_DANGEROUS, boolean1);
    }
    
    @Override
    protected boolean shouldBurn() {
        return false;
    }
    
    static {
        DATA_DANGEROUS = SynchedEntityData.<Boolean>defineId(WitherSkull.class, EntityDataSerializers.BOOLEAN);
    }
}
