001    package net.minecraft.entity.ai;
002    
003    import net.minecraft.entity.passive.EntityVillager;
004    import net.minecraft.entity.player.EntityPlayer;
005    import net.minecraft.inventory.Container;
006    
007    public class EntityAITradePlayer extends EntityAIBase
008    {
009        private EntityVillager villager;
010    
011        public EntityAITradePlayer(EntityVillager par1EntityVillager)
012        {
013            this.villager = par1EntityVillager;
014            this.setMutexBits(5);
015        }
016    
017        /**
018         * Returns whether the EntityAIBase should begin execution.
019         */
020        public boolean shouldExecute()
021        {
022            if (!this.villager.isEntityAlive())
023            {
024                return false;
025            }
026            else if (this.villager.isInWater())
027            {
028                return false;
029            }
030            else if (!this.villager.onGround)
031            {
032                return false;
033            }
034            else if (this.villager.velocityChanged)
035            {
036                return false;
037            }
038            else
039            {
040                EntityPlayer var1 = this.villager.getCustomer();
041                return var1 == null ? false : (this.villager.getDistanceSqToEntity(var1) > 16.0D ? false : var1.openContainer instanceof Container);
042            }
043        }
044    
045        /**
046         * Execute a one shot task or start executing a continuous task
047         */
048        public void startExecuting()
049        {
050            this.villager.getNavigator().clearPathEntity();
051        }
052    
053        /**
054         * Resets the task
055         */
056        public void resetTask()
057        {
058            this.villager.setCustomer((EntityPlayer)null);
059        }
060    }