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.say";
040 }
041
042 /**
043 * Returns the sound this mob makes when it is hurt.
044 */
045 protected String getHurtSound()
046 {
047 return "mob.cow.hurt";
048 }
049
050 /**
051 * Returns the sound this mob makes on death.
052 */
053 protected String getDeathSound()
054 {
055 return "mob.cow.hurt";
056 }
057
058 /**
059 * Plays step sound at given x, y, z for the entity
060 */
061 protected void playStepSound(int par1, int par2, int par3, int par4)
062 {
063 this.func_85030_a("mob.cow.step", 0.15F, 1.0F);
064 }
065
066 /**
067 * Returns the volume for the sounds this mob makes.
068 */
069 protected float getSoundVolume()
070 {
071 return 0.4F;
072 }
073
074 /**
075 * Returns the item ID for the item the mob drops on death.
076 */
077 protected int getDropItemId()
078 {
079 return Item.leather.shiftedIndex;
080 }
081
082 /**
083 * Drop 0-2 items of this living's type
084 */
085 protected void dropFewItems(boolean par1, int par2)
086 {
087 int var3 = this.rand.nextInt(3) + this.rand.nextInt(1 + par2);
088 int var4;
089
090 for (var4 = 0; var4 < var3; ++var4)
091 {
092 this.dropItem(Item.leather.shiftedIndex, 1);
093 }
094
095 var3 = this.rand.nextInt(3) + 1 + this.rand.nextInt(1 + par2);
096
097 for (var4 = 0; var4 < var3; ++var4)
098 {
099 if (this.isBurning())
100 {
101 this.dropItem(Item.beefCooked.shiftedIndex, 1);
102 }
103 else
104 {
105 this.dropItem(Item.beefRaw.shiftedIndex, 1);
106 }
107 }
108 }
109
110 /**
111 * Called when a player interacts with a mob. e.g. gets milk from a cow, gets into the saddle on a pig.
112 */
113 public boolean interact(EntityPlayer par1EntityPlayer)
114 {
115 ItemStack var2 = par1EntityPlayer.inventory.getCurrentItem();
116
117 if (var2 != null && var2.itemID == Item.bucketEmpty.shiftedIndex)
118 {
119 if (--var2.stackSize <= 0)
120 {
121 par1EntityPlayer.inventory.setInventorySlotContents(par1EntityPlayer.inventory.currentItem, new ItemStack(Item.bucketMilk));
122 }
123 else if (!par1EntityPlayer.inventory.addItemStackToInventory(new ItemStack(Item.bucketMilk)))
124 {
125 par1EntityPlayer.dropPlayerItem(new ItemStack(Item.bucketMilk.shiftedIndex, 1, 0));
126 }
127
128 return true;
129 }
130 else
131 {
132 return super.interact(par1EntityPlayer);
133 }
134 }
135
136 /**
137 * This function is used when two same-species animals in 'love mode' breed to generate the new baby animal.
138 */
139 public EntityAnimal spawnBabyAnimal(EntityAnimal par1EntityAnimal)
140 {
141 return new EntityCow(this.worldObj);
142 }
143 }