001    package net.minecraft.src;
002    
003    public class EntityAIEatGrass extends EntityAIBase
004    {
005        private EntityLiving theEntity;
006        private World theWorld;
007    
008        /** A decrementing tick used for the sheep's head offset and animation. */
009        int eatGrassTick = 0;
010    
011        public EntityAIEatGrass(EntityLiving par1EntityLiving)
012        {
013            this.theEntity = par1EntityLiving;
014            this.theWorld = par1EntityLiving.worldObj;
015            this.setMutexBits(7);
016        }
017    
018        /**
019         * Returns whether the EntityAIBase should begin execution.
020         */
021        public boolean shouldExecute()
022        {
023            if (this.theEntity.getRNG().nextInt(this.theEntity.isChild() ? 50 : 1000) != 0)
024            {
025                return false;
026            }
027            else
028            {
029                int var1 = MathHelper.floor_double(this.theEntity.posX);
030                int var2 = MathHelper.floor_double(this.theEntity.posY);
031                int var3 = MathHelper.floor_double(this.theEntity.posZ);
032                return this.theWorld.getBlockId(var1, var2, var3) == Block.tallGrass.blockID && this.theWorld.getBlockMetadata(var1, var2, var3) == 1 ? true : this.theWorld.getBlockId(var1, var2 - 1, var3) == Block.grass.blockID;
033            }
034        }
035    
036        /**
037         * Execute a one shot task or start executing a continuous task
038         */
039        public void startExecuting()
040        {
041            this.eatGrassTick = 40;
042            this.theWorld.setEntityState(this.theEntity, (byte)10);
043            this.theEntity.getNavigator().clearPathEntity();
044        }
045    
046        /**
047         * Resets the task
048         */
049        public void resetTask()
050        {
051            this.eatGrassTick = 0;
052        }
053    
054        /**
055         * Returns whether an in-progress EntityAIBase should continue executing
056         */
057        public boolean continueExecuting()
058        {
059            return this.eatGrassTick > 0;
060        }
061    
062        public int func_75362_f()
063        {
064            return this.eatGrassTick;
065        }
066    
067        /**
068         * Updates the task
069         */
070        public void updateTask()
071        {
072            this.eatGrassTick = Math.max(0, this.eatGrassTick - 1);
073    
074            if (this.eatGrassTick == 4)
075            {
076                int var1 = MathHelper.floor_double(this.theEntity.posX);
077                int var2 = MathHelper.floor_double(this.theEntity.posY);
078                int var3 = MathHelper.floor_double(this.theEntity.posZ);
079    
080                if (this.theWorld.getBlockId(var1, var2, var3) == Block.tallGrass.blockID)
081                {
082                    this.theWorld.playAuxSFX(2001, var1, var2, var3, Block.tallGrass.blockID + 4096);
083                    this.theWorld.setBlockWithNotify(var1, var2, var3, 0);
084                    this.theEntity.eatGrassBonus();
085                }
086                else if (this.theWorld.getBlockId(var1, var2 - 1, var3) == Block.grass.blockID)
087                {
088                    this.theWorld.playAuxSFX(2001, var1, var2 - 1, var3, Block.grass.blockID);
089                    this.theWorld.setBlockWithNotify(var1, var2 - 1, var3, Block.dirt.blockID);
090                    this.theEntity.eatGrassBonus();
091                }
092            }
093        }
094    }