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