    001package net.minecraft.entity.ai;
    002
    003import net.minecraft.entity.monster.EntityIronGolem;
    004import net.minecraft.entity.passive.EntityVillager;
    005
    006public class EntityAILookAtVillager extends EntityAIBase
    007{
    008    private EntityIronGolem theGolem;
    009    private EntityVillager theVillager;
    010    private int lookTime;
    011
    012    public EntityAILookAtVillager(EntityIronGolem par1EntityIronGolem)
    013    {
    014        this.theGolem = par1EntityIronGolem;
    015        this.setMutexBits(3);
    016    }
    017
    018    /**
    019     * Returns whether the EntityAIBase should begin execution.
    020     */
    021    public boolean shouldExecute()
    022    {
    023        if (!this.theGolem.worldObj.isDaytime())
    024        {
    025            return false;
    026        }
    027        else if (this.theGolem.getRNG().nextInt(8000) != 0)
    028        {
    029            return false;
    030        }
    031        else
    032        {
    033            this.theVillager = (EntityVillager)this.theGolem.worldObj.findNearestEntityWithinAABB(EntityVillager.class, this.theGolem.boundingBox.expand(6.0D, 2.0D, 6.0D), this.theGolem);
    034            return this.theVillager != null;
    035        }
    036    }
    037
    038    /**
    039     * Returns whether an in-progress EntityAIBase should continue executing
    040     */
    041    public boolean continueExecuting()
    042    {
    043        return this.lookTime > 0;
    044    }
    045
    046    /**
    047     * Execute a one shot task or start executing a continuous task
    048     */
    049    public void startExecuting()
    050    {
    051        this.lookTime = 400;
    052        this.theGolem.setHoldingRose(true);
    053    }
    054
    055    /**
    056     * Resets the task
    057     */
    058    public void resetTask()
    059    {
    060        this.theGolem.setHoldingRose(false);
    061        this.theVillager = null;
    062    }
    063
    064    /**
    065     * Updates the task
    066     */
    067    public void updateTask()
    068    {
    069        this.theGolem.getLookHelper().setLookPositionWithEntity(this.theVillager, 30.0F, 30.0F);
    070        --this.lookTime;
    071    }
    072}