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