package net.minecraft.world.entity.monster;

import java.util.Iterator;
import java.util.List;
import net.minecraft.world.effect.MobEffect;
import net.minecraft.core.BlockPos;
import net.minecraft.world.effect.MobEffectInstance;
import net.minecraft.network.protocol.Packet;
import net.minecraft.network.protocol.game.ClientboundGameEventPacket;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.entity.Entity;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.effect.MobEffects;
import net.minecraft.world.damagesource.DamageSource;
import net.minecraft.sounds.SoundEvents;
import net.minecraft.sounds.SoundEvent;
import net.minecraft.world.level.Level;
import net.minecraft.world.entity.EntityType;

public class ElderGuardian extends Guardian {
    public static final float ELDER_SIZE_SCALE;
    
    public ElderGuardian(final EntityType<? extends ElderGuardian> aku, final Level bjw) {
        super(aku, bjw);
        this.setPersistenceRequired();
        if (this.randomStrollGoal != null) {
            this.randomStrollGoal.setInterval(400);
        }
    }
    
    @Override
    protected void registerAttributes() {
        super.registerAttributes();
        this.getAttribute(SharedMonsterAttributes.MOVEMENT_SPEED).setBaseValue(0.30000001192092896);
        this.getAttribute(SharedMonsterAttributes.ATTACK_DAMAGE).setBaseValue(8.0);
        this.getAttribute(SharedMonsterAttributes.MAX_HEALTH).setBaseValue(80.0);
    }
    
    @Override
    public int getAttackDuration() {
        return 60;
    }
    
    @Override
    protected SoundEvent getAmbientSound() {
        return this.isInWaterOrBubble() ? SoundEvents.ELDER_GUARDIAN_AMBIENT : SoundEvents.ELDER_GUARDIAN_AMBIENT_LAND;
    }
    
    @Override
    protected SoundEvent getHurtSound(final DamageSource ajz) {
        return this.isInWaterOrBubble() ? SoundEvents.ELDER_GUARDIAN_HURT : SoundEvents.ELDER_GUARDIAN_HURT_LAND;
    }
    
    @Override
    protected SoundEvent getDeathSound() {
        return this.isInWaterOrBubble() ? SoundEvents.ELDER_GUARDIAN_DEATH : SoundEvents.ELDER_GUARDIAN_DEATH_LAND;
    }
    
    @Override
    protected SoundEvent getFlopSound() {
        return SoundEvents.ELDER_GUARDIAN_FLOP;
    }
    
    @Override
    protected void customServerAiStep() {
        super.customServerAiStep();
        final int integer2 = 1200;
        if ((this.tickCount + this.getId()) % 1200 == 0) {
            final MobEffect aki3 = MobEffects.DIG_SLOWDOWN;
            final List<ServerPlayer> list4 = ((ServerLevel)this.level).getPlayers(xe -> this.distanceToSqr(xe) < 2500.0 && xe.gameMode.isSurvival());
            final int integer3 = 2;
            final int integer4 = 6000;
            final int integer5 = 1200;
            for (final ServerPlayer xe2 : list4) {
                if (!xe2.hasEffect(aki3) || xe2.getEffect(aki3).getAmplifier() < 2 || xe2.getEffect(aki3).getDuration() < 1200) {
                    xe2.connection.send(new ClientboundGameEventPacket(10, 0.0f));
                    xe2.addEffect(new MobEffectInstance(aki3, 6000, 2));
                }
            }
        }
        if (!this.hasRestriction()) {
            this.restrictTo(new BlockPos(this), 16);
        }
    }
    
    static {
        ELDER_SIZE_SCALE = EntityType.ELDER_GUARDIAN.getWidth() / EntityType.GUARDIAN.getWidth();
    }
}
