    001package net.minecraft.entity.ai;
    002
    003import net.minecraft.entity.EntityLiving;
    004import net.minecraft.entity.monster.EntityCreeper;
    005
    006public class EntityAICreeperSwell extends EntityAIBase
    007{
    008    /** The creeper that is swelling. */
    009    EntityCreeper swellingCreeper;
    010
    011    /**
    012     * The creeper's attack target. This is used for the changing of the creeper's state.
    013     */
    014    EntityLiving creeperAttackTarget;
    015
    016    public EntityAICreeperSwell(EntityCreeper par1EntityCreeper)
    017    {
    018        this.swellingCreeper = par1EntityCreeper;
    019        this.setMutexBits(1);
    020    }
    021
    022    /**
    023     * Returns whether the EntityAIBase should begin execution.
    024     */
    025    public boolean shouldExecute()
    026    {
    027        EntityLiving var1 = this.swellingCreeper.getAttackTarget();
    028        return this.swellingCreeper.getCreeperState() > 0 || var1 != null && this.swellingCreeper.getDistanceSqToEntity(var1) < 9.0D;
    029    }
    030
    031    /**
    032     * Execute a one shot task or start executing a continuous task
    033     */
    034    public void startExecuting()
    035    {
    036        this.swellingCreeper.getNavigator().clearPathEntity();
    037        this.creeperAttackTarget = this.swellingCreeper.getAttackTarget();
    038    }
    039
    040    /**
    041     * Resets the task
    042     */
    043    public void resetTask()
    044    {
    045        this.creeperAttackTarget = null;
    046    }
    047
    048    /**
    049     * Updates the task
    050     */
    051    public void updateTask()
    052    {
    053        if (this.creeperAttackTarget == null)
    054        {
    055            this.swellingCreeper.setCreeperState(-1);
    056        }
    057        else if (this.swellingCreeper.getDistanceSqToEntity(this.creeperAttackTarget) > 49.0D)
    058        {
    059            this.swellingCreeper.setCreeperState(-1);
    060        }
    061        else if (!this.swellingCreeper.getEntitySenses().canSee(this.creeperAttackTarget))
    062        {
    063            this.swellingCreeper.setCreeperState(-1);
    064        }
    065        else
    066        {
    067            this.swellingCreeper.setCreeperState(1);
    068        }
    069    }
    070}