001package net.minecraft.entity.ai;
002
003import java.util.Iterator;
004import java.util.List;
005import net.minecraft.entity.monster.EntityIronGolem;
006import net.minecraft.entity.passive.EntityVillager;
007
008public class EntityAIFollowGolem extends EntityAIBase
009{
010    private EntityVillager theVillager;
011    private EntityIronGolem theGolem;
012    private int takeGolemRoseTick;
013    private boolean tookGolemRose = false;
014
015    public EntityAIFollowGolem(EntityVillager par1EntityVillager)
016    {
017        this.theVillager = par1EntityVillager;
018        this.setMutexBits(3);
019    }
020
021    /**
022     * Returns whether the EntityAIBase should begin execution.
023     */
024    public boolean shouldExecute()
025    {
026        if (this.theVillager.getGrowingAge() >= 0)
027        {
028            return false;
029        }
030        else if (!this.theVillager.worldObj.isDaytime())
031        {
032            return false;
033        }
034        else
035        {
036            List list = this.theVillager.worldObj.getEntitiesWithinAABB(EntityIronGolem.class, this.theVillager.boundingBox.expand(6.0D, 2.0D, 6.0D));
037
038            if (list.isEmpty())
039            {
040                return false;
041            }
042            else
043            {
044                Iterator iterator = list.iterator();
045
046                while (iterator.hasNext())
047                {
048                    EntityIronGolem entityirongolem = (EntityIronGolem)iterator.next();
049
050                    if (entityirongolem.getHoldRoseTick() > 0)
051                    {
052                        this.theGolem = entityirongolem;
053                        break;
054                    }
055                }
056
057                return this.theGolem != null;
058            }
059        }
060    }
061
062    /**
063     * Returns whether an in-progress EntityAIBase should continue executing
064     */
065    public boolean continueExecuting()
066    {
067        return this.theGolem.getHoldRoseTick() > 0;
068    }
069
070    /**
071     * Execute a one shot task or start executing a continuous task
072     */
073    public void startExecuting()
074    {
075        this.takeGolemRoseTick = this.theVillager.getRNG().nextInt(320);
076        this.tookGolemRose = false;
077        this.theGolem.getNavigator().clearPathEntity();
078    }
079
080    /**
081     * Resets the task
082     */
083    public void resetTask()
084    {
085        this.theGolem = null;
086        this.theVillager.getNavigator().clearPathEntity();
087    }
088
089    /**
090     * Updates the task
091     */
092    public void updateTask()
093    {
094        this.theVillager.getLookHelper().setLookPositionWithEntity(this.theGolem, 30.0F, 30.0F);
095
096        if (this.theGolem.getHoldRoseTick() == this.takeGolemRoseTick)
097        {
098            this.theVillager.getNavigator().tryMoveToEntityLiving(this.theGolem, 0.15F);
099            this.tookGolemRose = true;
100        }
101
102        if (this.tookGolemRose && this.theVillager.getDistanceSqToEntity(this.theGolem) < 4.0D)
103        {
104            this.theGolem.setHoldingRose(false);
105            this.theVillager.getNavigator().clearPathEntity();
106        }
107    }
108}