package net.minecraft.world.entity.ai.goal.target;

import java.util.Iterator;
import java.util.List;
import net.minecraft.world.phys.AABB;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.entity.npc.Villager;
import java.util.EnumSet;
import net.minecraft.world.entity.ai.goal.Goal;
import net.minecraft.world.entity.Mob;
import net.minecraft.world.entity.ai.targeting.TargetingConditions;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.animal.IronGolem;

public class DefendVillageTargetGoal extends TargetGoal {
    private final IronGolem golem;
    private LivingEntity potentialTarget;
    private final TargetingConditions attackTargeting;
    
    public DefendVillageTargetGoal(final IronGolem ayt) {
        super(ayt, false, true);
        this.attackTargeting = new TargetingConditions().range(64.0);
        this.golem = ayt;
        this.setFlags(EnumSet.<Flag>of(Flag.TARGET));
    }
    
    @Override
    public boolean canUse() {
        final AABB deg2 = this.golem.getBoundingBox().inflate(10.0, 8.0, 10.0);
        final List<LivingEntity> list3 = this.golem.level.<LivingEntity>getNearbyEntities(Villager.class, this.attackTargeting, (LivingEntity)this.golem, deg2);
        final List<Player> list4 = this.golem.level.getNearbyPlayers(this.attackTargeting, this.golem, deg2);
        for (final LivingEntity aoy6 : list3) {
            final Villager bdp7 = (Villager)aoy6;
            for (final Player bec9 : list4) {
                final int integer10 = bdp7.getPlayerReputation(bec9);
                if (integer10 <= -100) {
                    this.potentialTarget = bec9;
                }
            }
        }
        return this.potentialTarget != null && (!(this.potentialTarget instanceof Player) || (!this.potentialTarget.isSpectator() && !((Player)this.potentialTarget).isCreative()));
    }
    
    @Override
    public void start() {
        this.golem.setTarget(this.potentialTarget);
        super.start();
    }
}
