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