001    package net.minecraft.src;
002    
003    public class EntityAILookIdle extends EntityAIBase
004    {
005        /** The entity that is looking idle. */
006        private EntityLiving idleEntity;
007    
008        /** X offset to look at */
009        private double lookX;
010    
011        /** Z offset to look at */
012        private double lookZ;
013    
014        /**
015         * A decrementing tick that stops the entity from being idle once it reaches 0.
016         */
017        private int idleTime = 0;
018    
019        public EntityAILookIdle(EntityLiving par1EntityLiving)
020        {
021            this.idleEntity = par1EntityLiving;
022            this.setMutexBits(3);
023        }
024    
025        /**
026         * Returns whether the EntityAIBase should begin execution.
027         */
028        public boolean shouldExecute()
029        {
030            return this.idleEntity.getRNG().nextFloat() < 0.02F;
031        }
032    
033        /**
034         * Returns whether an in-progress EntityAIBase should continue executing
035         */
036        public boolean continueExecuting()
037        {
038            return this.idleTime >= 0;
039        }
040    
041        /**
042         * Execute a one shot task or start executing a continuous task
043         */
044        public void startExecuting()
045        {
046            double var1 = (Math.PI * 2D) * this.idleEntity.getRNG().nextDouble();
047            this.lookX = Math.cos(var1);
048            this.lookZ = Math.sin(var1);
049            this.idleTime = 20 + this.idleEntity.getRNG().nextInt(20);
050        }
051    
052        /**
053         * Updates the task
054         */
055        public void updateTask()
056        {
057            --this.idleTime;
058            this.idleEntity.getLookHelper().setLookPosition(this.idleEntity.posX + this.lookX, this.idleEntity.posY + (double)this.idleEntity.getEyeHeight(), this.idleEntity.posZ + this.lookZ, 10.0F, (float)this.idleEntity.getVerticalFaceSpeed());
059        }
060    }