    001package net.minecraft.entity.ai;
    002
    003import net.minecraft.entity.EntityCreature;
    004import net.minecraft.entity.player.EntityPlayer;
    005import net.minecraft.item.ItemStack;
    006
    007public class EntityAITempt extends EntityAIBase
    008{
    009    /** The entity using this AI that is tempted by the player. */
    010    private EntityCreature temptedEntity;
    011    private float field_75282_b;
    012    private double field_75283_c;
    013    private double field_75280_d;
    014    private double field_75281_e;
    015    private double field_75278_f;
    016    private double field_75279_g;
    017
    018    /** The player that is tempting the entity that is using this AI. */
    019    private EntityPlayer temptingPlayer;
    020
    021    /**
    022     * A counter that is decremented each time the shouldExecute method is called. The shouldExecute method will always
    023     * return false if delayTemptCounter is greater than 0.
    024     */
    025    private int delayTemptCounter = 0;
    026    private boolean field_75287_j;
    027
    028    /**
    029     * This field saves the ID of the items that can be used to breed entities with this behaviour.
    030     */
    031    private int breedingFood;
    032
    033    /**
    034     * Whether the entity using this AI will be scared by the tempter's sudden movement.
    035     */
    036    private boolean scaredByPlayerMovement;
    037    private boolean field_75286_m;
    038
    039    public EntityAITempt(EntityCreature par1EntityCreature, float par2, int par3, boolean par4)
    040    {
    041        this.temptedEntity = par1EntityCreature;
    042        this.field_75282_b = par2;
    043        this.breedingFood = par3;
    044        this.scaredByPlayerMovement = par4;
    045        this.setMutexBits(3);
    046    }
    047
    048    /**
    049     * Returns whether the EntityAIBase should begin execution.
    050     */
    051    public boolean shouldExecute()
    052    {
    053        if (this.delayTemptCounter > 0)
    054        {
    055            --this.delayTemptCounter;
    056            return false;
    057        }
    058        else
    059        {
    060            this.temptingPlayer = this.temptedEntity.worldObj.getClosestPlayerToEntity(this.temptedEntity, 10.0D);
    061
    062            if (this.temptingPlayer == null)
    063            {
    064                return false;
    065            }
    066            else
    067            {
    068                ItemStack itemstack = this.temptingPlayer.getCurrentEquippedItem();
    069                return itemstack == null ? false : itemstack.itemID == this.breedingFood;
    070            }
    071        }
    072    }
    073
    074    /**
    075     * Returns whether an in-progress EntityAIBase should continue executing
    076     */
    077    public boolean continueExecuting()
    078    {
    079        if (this.scaredByPlayerMovement)
    080        {
    081            if (this.temptedEntity.getDistanceSqToEntity(this.temptingPlayer) < 36.0D)
    082            {
    083                if (this.temptingPlayer.getDistanceSq(this.field_75283_c, this.field_75280_d, this.field_75281_e) > 0.010000000000000002D)
    084                {
    085                    return false;
    086                }
    087
    088                if (Math.abs((double)this.temptingPlayer.rotationPitch - this.field_75278_f) > 5.0D || Math.abs((double)this.temptingPlayer.rotationYaw - this.field_75279_g) > 5.0D)
    089                {
    090                    return false;
    091                }
    092            }
    093            else
    094            {
    095                this.field_75283_c = this.temptingPlayer.posX;
    096                this.field_75280_d = this.temptingPlayer.posY;
    097                this.field_75281_e = this.temptingPlayer.posZ;
    098            }
    099
    100            this.field_75278_f = (double)this.temptingPlayer.rotationPitch;
    101            this.field_75279_g = (double)this.temptingPlayer.rotationYaw;
    102        }
    103
    104        return this.shouldExecute();
    105    }
    106
    107    /**
    108     * Execute a one shot task or start executing a continuous task
    109     */
    110    public void startExecuting()
    111    {
    112        this.field_75283_c = this.temptingPlayer.posX;
    113        this.field_75280_d = this.temptingPlayer.posY;
    114        this.field_75281_e = this.temptingPlayer.posZ;
    115        this.field_75287_j = true;
    116        this.field_75286_m = this.temptedEntity.getNavigator().getAvoidsWater();
    117        this.temptedEntity.getNavigator().setAvoidsWater(false);
    118    }
    119
    120    /**
    121     * Resets the task
    122     */
    123    public void resetTask()
    124    {
    125        this.temptingPlayer = null;
    126        this.temptedEntity.getNavigator().clearPathEntity();
    127        this.delayTemptCounter = 100;
    128        this.field_75287_j = false;
    129        this.temptedEntity.getNavigator().setAvoidsWater(this.field_75286_m);
    130    }
    131
    132    /**
    133     * Updates the task
    134     */
    135    public void updateTask()
    136    {
    137        this.temptedEntity.getLookHelper().setLookPositionWithEntity(this.temptingPlayer, 30.0F, (float)this.temptedEntity.getVerticalFaceSpeed());
    138
    139        if (this.temptedEntity.getDistanceSqToEntity(this.temptingPlayer) < 6.25D)
    140        {
    141            this.temptedEntity.getNavigator().clearPathEntity();
    142        }
    143        else
    144        {
    145            this.temptedEntity.getNavigator().tryMoveToEntityLiving(this.temptingPlayer, this.field_75282_b);
    146        }
    147    }
    148
    149    public boolean func_75277_f()
    150    {
    151        return this.field_75287_j;
    152    }
    153}