    001    package net.minecraft.src;
    002
    003    public class EntityAIBeg extends EntityAIBase
    004    {
    005        private EntityWolf theWolf;
    006        private EntityPlayer thePlayer;
    007        private World worldObject;
    008        private float minPlayerDistance;
    009        private int field_75384_e;
    010
    011        public EntityAIBeg(EntityWolf par1EntityWolf, float par2)
    012        {
    013            this.theWolf = par1EntityWolf;
    014            this.worldObject = par1EntityWolf.worldObj;
    015            this.minPlayerDistance = par2;
    016            this.setMutexBits(2);
    017        }
    018
    019        /**
    020         * Returns whether the EntityAIBase should begin execution.
    021         */
    022        public boolean shouldExecute()
    023        {
    024            this.thePlayer = this.worldObject.getClosestPlayerToEntity(this.theWolf, (double)this.minPlayerDistance);
    025            return this.thePlayer == null ? false : this.hasPlayerGotBoneInHand(this.thePlayer);
    026        }
    027
    028        /**
    029         * Returns whether an in-progress EntityAIBase should continue executing
    030         */
    031        public boolean continueExecuting()
    032        {
    033            return !this.thePlayer.isEntityAlive() ? false : (this.theWolf.getDistanceSqToEntity(this.thePlayer) > (double)(this.minPlayerDistance * this.minPlayerDistance) ? false : this.field_75384_e > 0 && this.hasPlayerGotBoneInHand(this.thePlayer));
    034        }
    035
    036        /**
    037         * Execute a one shot task or start executing a continuous task
    038         */
    039        public void startExecuting()
    040        {
    041            this.theWolf.func_70918_i(true);
    042            this.field_75384_e = 40 + this.theWolf.getRNG().nextInt(40);
    043        }
    044
    045        /**
    046         * Resets the task
    047         */
    048        public void resetTask()
    049        {
    050            this.theWolf.func_70918_i(false);
    051            this.thePlayer = null;
    052        }
    053
    054        /**
    055         * Updates the task
    056         */
    057        public void updateTask()
    058        {
    059            this.theWolf.getLookHelper().setLookPosition(this.thePlayer.posX, this.thePlayer.posY + (double)this.thePlayer.getEyeHeight(), this.thePlayer.posZ, 10.0F, (float)this.theWolf.getVerticalFaceSpeed());
    060            --this.field_75384_e;
    061        }
    062
    063        /**
    064         * Gets if the Player has the Bone in the hand.
    065         */
    066        private boolean hasPlayerGotBoneInHand(EntityPlayer par1EntityPlayer)
    067        {
    068            ItemStack var2 = par1EntityPlayer.inventory.getCurrentItem();
    069            return var2 == null ? false : (!this.theWolf.isTamed() && var2.itemID == Item.bone.shiftedIndex ? true : this.theWolf.isWheat(var2));
    070        }
    071    }