package net.minecraft.entity.ai;

import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.monster.EntityIronGolem;
import net.minecraft.village.Village;

public class EntityAIDefendVillage extends EntityAITarget
{
	EntityIronGolem irongolem;
	EntityLivingBase villageAgressorTarget;
	private static final String __OBFID = "CL_00001618";

	public EntityAIDefendVillage(EntityIronGolem par1EntityIronGolem)
	{
		super(par1EntityIronGolem, false, true);
		this.irongolem = par1EntityIronGolem;
		this.setMutexBits(1);
	}

	public boolean shouldExecute()
	{
		Village village = this.irongolem.getVillage();

		if (village == null)
		{
			return false;
		}
		else
		{
			this.villageAgressorTarget = village.findNearestVillageAggressor(this.irongolem);

			if (!this.isSuitableTarget(this.villageAgressorTarget, false))
			{
				if (this.taskOwner.getRNG().nextInt(20) == 0)
				{
					this.villageAgressorTarget = village.func_82685_c(this.irongolem);
					return this.isSuitableTarget(this.villageAgressorTarget, false);
				}
				else
				{
					return false;
				}
			}
			else
			{
				return true;
			}
		}
	}

	public void startExecuting()
	{
		this.irongolem.setAttackTarget(this.villageAgressorTarget);
		super.startExecuting();
	}
}