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