001    package net.minecraft.src;
002    
003    public class EntityCow extends EntityAnimal
004    {
005        public EntityCow(World par1World)
006        {
007            super(par1World);
008            this.texture = "/mob/cow.png";
009            this.setSize(0.9F, 1.3F);
010            this.getNavigator().setAvoidsWater(true);
011            this.tasks.addTask(0, new EntityAISwimming(this));
012            this.tasks.addTask(1, new EntityAIPanic(this, 0.38F));
013            this.tasks.addTask(2, new EntityAIMate(this, 0.2F));
014            this.tasks.addTask(3, new EntityAITempt(this, 0.25F, Item.wheat.shiftedIndex, false));
015            this.tasks.addTask(4, new EntityAIFollowParent(this, 0.25F));
016            this.tasks.addTask(5, new EntityAIWander(this, 0.2F));
017            this.tasks.addTask(6, new EntityAIWatchClosest(this, EntityPlayer.class, 6.0F));
018            this.tasks.addTask(7, new EntityAILookIdle(this));
019        }
020    
021        /**
022         * Returns true if the newer Entity AI code should be run
023         */
024        public boolean isAIEnabled()
025        {
026            return true;
027        }
028    
029        public int getMaxHealth()
030        {
031            return 10;
032        }
033    
034        /**
035         * Returns the sound this mob makes while it's alive.
036         */
037        protected String getLivingSound()
038        {
039            return "mob.cow";
040        }
041    
042        /**
043         * Returns the sound this mob makes when it is hurt.
044         */
045        protected String getHurtSound()
046        {
047            return "mob.cowhurt";
048        }
049    
050        /**
051         * Returns the sound this mob makes on death.
052         */
053        protected String getDeathSound()
054        {
055            return "mob.cowhurt";
056        }
057    
058        /**
059         * Returns the volume for the sounds this mob makes.
060         */
061        protected float getSoundVolume()
062        {
063            return 0.4F;
064        }
065    
066        /**
067         * Returns the item ID for the item the mob drops on death.
068         */
069        protected int getDropItemId()
070        {
071            return Item.leather.shiftedIndex;
072        }
073    
074        /**
075         * Drop 0-2 items of this living's type
076         */
077        protected void dropFewItems(boolean par1, int par2)
078        {
079            int var3 = this.rand.nextInt(3) + this.rand.nextInt(1 + par2);
080            int var4;
081    
082            for (var4 = 0; var4 < var3; ++var4)
083            {
084                this.dropItem(Item.leather.shiftedIndex, 1);
085            }
086    
087            var3 = this.rand.nextInt(3) + 1 + this.rand.nextInt(1 + par2);
088    
089            for (var4 = 0; var4 < var3; ++var4)
090            {
091                if (this.isBurning())
092                {
093                    this.dropItem(Item.beefCooked.shiftedIndex, 1);
094                }
095                else
096                {
097                    this.dropItem(Item.beefRaw.shiftedIndex, 1);
098                }
099            }
100        }
101    
102        /**
103         * Called when a player interacts with a mob. e.g. gets milk from a cow, gets into the saddle on a pig.
104         */
105        public boolean interact(EntityPlayer par1EntityPlayer)
106        {
107            ItemStack var2 = par1EntityPlayer.inventory.getCurrentItem();
108    
109            if (var2 != null && var2.itemID == Item.bucketEmpty.shiftedIndex)
110            {
111                if (--var2.stackSize <= 0)
112                {
113                    par1EntityPlayer.inventory.setInventorySlotContents(par1EntityPlayer.inventory.currentItem, new ItemStack(Item.bucketMilk));
114                }
115                else if (!par1EntityPlayer.inventory.addItemStackToInventory(new ItemStack(Item.bucketMilk)))
116                {
117                    par1EntityPlayer.dropPlayerItem(new ItemStack(Item.bucketMilk.shiftedIndex, 1, 0));
118                }
119    
120                return true;
121            }
122            else
123            {
124                return super.interact(par1EntityPlayer);
125            }
126        }
127    
128        /**
129         * This function is used when two same-species animals in 'love mode' breed to generate the new baby animal.
130         */
131        public EntityAnimal spawnBabyAnimal(EntityAnimal par1EntityAnimal)
132        {
133            return new EntityCow(this.worldObj);
134        }
135    }