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.itemID, 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.playSound("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.itemID; 094 } 095 096 /** 097 * Drop 0-2 items of this living's type. @param par1 - Whether this entity has recently been hit by a player. @param 098 * par2 - Level of Looting used to kill this mob. 099 */ 100 protected void dropFewItems(boolean par1, int par2) 101 { 102 int var3 = this.rand.nextInt(3) + this.rand.nextInt(1 + par2); 103 int var4; 104 105 for (var4 = 0; var4 < var3; ++var4) 106 { 107 this.dropItem(Item.leather.itemID, 1); 108 } 109 110 var3 = this.rand.nextInt(3) + 1 + this.rand.nextInt(1 + par2); 111 112 for (var4 = 0; var4 < var3; ++var4) 113 { 114 if (this.isBurning()) 115 { 116 this.dropItem(Item.beefCooked.itemID, 1); 117 } 118 else 119 { 120 this.dropItem(Item.beefRaw.itemID, 1); 121 } 122 } 123 } 124 125 /** 126 * Called when a player interacts with a mob. e.g. gets milk from a cow, gets into the saddle on a pig. 127 */ 128 public boolean interact(EntityPlayer par1EntityPlayer) 129 { 130 ItemStack var2 = par1EntityPlayer.inventory.getCurrentItem(); 131 132 if (var2 != null && var2.itemID == Item.bucketEmpty.itemID) 133 { 134 if (--var2.stackSize <= 0) 135 { 136 par1EntityPlayer.inventory.setInventorySlotContents(par1EntityPlayer.inventory.currentItem, new ItemStack(Item.bucketMilk)); 137 } 138 else if (!par1EntityPlayer.inventory.addItemStackToInventory(new ItemStack(Item.bucketMilk))) 139 { 140 par1EntityPlayer.dropPlayerItem(new ItemStack(Item.bucketMilk.itemID, 1, 0)); 141 } 142 143 return true; 144 } 145 else 146 { 147 return super.interact(par1EntityPlayer); 148 } 149 } 150 151 /** 152 * This function is used when two same-species animals in 'love mode' breed to generate the new baby animal. 153 */ 154 public EntityCow spawnBabyAnimal(EntityAgeable par1EntityAgeable) 155 { 156 return new EntityCow(this.worldObj); 157 } 158 159 public EntityAgeable createChild(EntityAgeable par1EntityAgeable) 160 { 161 return this.spawnBabyAnimal(par1EntityAgeable); 162 } 163 }