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