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