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.ItemSeeds; 015 import net.minecraft.item.ItemStack; 016 import net.minecraft.world.World; 017 018 public class EntityChicken extends EntityAnimal 019 { 020 public boolean field_70885_d = false; 021 public float field_70886_e = 0.0F; 022 public float destPos = 0.0F; 023 public float field_70884_g; 024 public float field_70888_h; 025 public float field_70889_i = 1.0F; 026 027 /** The time until the next egg is spawned. */ 028 public int timeUntilNextEgg; 029 030 public EntityChicken(World par1World) 031 { 032 super(par1World); 033 this.texture = "/mob/chicken.png"; 034 this.setSize(0.3F, 0.7F); 035 this.timeUntilNextEgg = this.rand.nextInt(6000) + 6000; 036 float var2 = 0.25F; 037 this.tasks.addTask(0, new EntityAISwimming(this)); 038 this.tasks.addTask(1, new EntityAIPanic(this, 0.38F)); 039 this.tasks.addTask(2, new EntityAIMate(this, var2)); 040 this.tasks.addTask(3, new EntityAITempt(this, 0.25F, Item.seeds.itemID, false)); 041 this.tasks.addTask(4, new EntityAIFollowParent(this, 0.28F)); 042 this.tasks.addTask(5, new EntityAIWander(this, var2)); 043 this.tasks.addTask(6, new EntityAIWatchClosest(this, EntityPlayer.class, 6.0F)); 044 this.tasks.addTask(7, new EntityAILookIdle(this)); 045 } 046 047 /** 048 * Returns true if the newer Entity AI code should be run 049 */ 050 public boolean isAIEnabled() 051 { 052 return true; 053 } 054 055 public int getMaxHealth() 056 { 057 return 4; 058 } 059 060 /** 061 * Called frequently so the entity can update its state every tick as required. For example, zombies and skeletons 062 * use this to react to sunlight and start to burn. 063 */ 064 public void onLivingUpdate() 065 { 066 super.onLivingUpdate(); 067 this.field_70888_h = this.field_70886_e; 068 this.field_70884_g = this.destPos; 069 this.destPos = (float)((double)this.destPos + (double)(this.onGround ? -1 : 4) * 0.3D); 070 071 if (this.destPos < 0.0F) 072 { 073 this.destPos = 0.0F; 074 } 075 076 if (this.destPos > 1.0F) 077 { 078 this.destPos = 1.0F; 079 } 080 081 if (!this.onGround && this.field_70889_i < 1.0F) 082 { 083 this.field_70889_i = 1.0F; 084 } 085 086 this.field_70889_i = (float)((double)this.field_70889_i * 0.9D); 087 088 if (!this.onGround && this.motionY < 0.0D) 089 { 090 this.motionY *= 0.6D; 091 } 092 093 this.field_70886_e += this.field_70889_i * 2.0F; 094 095 if (!this.isChild() && !this.worldObj.isRemote && --this.timeUntilNextEgg <= 0) 096 { 097 this.playSound("mob.chicken.plop", 1.0F, (this.rand.nextFloat() - this.rand.nextFloat()) * 0.2F + 1.0F); 098 this.dropItem(Item.egg.itemID, 1); 099 this.timeUntilNextEgg = this.rand.nextInt(6000) + 6000; 100 } 101 } 102 103 /** 104 * Called when the mob is falling. Calculates and applies fall damage. 105 */ 106 protected void fall(float par1) {} 107 108 /** 109 * Returns the sound this mob makes while it's alive. 110 */ 111 protected String getLivingSound() 112 { 113 return "mob.chicken.say"; 114 } 115 116 /** 117 * Returns the sound this mob makes when it is hurt. 118 */ 119 protected String getHurtSound() 120 { 121 return "mob.chicken.hurt"; 122 } 123 124 /** 125 * Returns the sound this mob makes on death. 126 */ 127 protected String getDeathSound() 128 { 129 return "mob.chicken.hurt"; 130 } 131 132 /** 133 * Plays step sound at given x, y, z for the entity 134 */ 135 protected void playStepSound(int par1, int par2, int par3, int par4) 136 { 137 this.playSound("mob.chicken.step", 0.15F, 1.0F); 138 } 139 140 /** 141 * Returns the item ID for the item the mob drops on death. 142 */ 143 protected int getDropItemId() 144 { 145 return Item.feather.itemID; 146 } 147 148 /** 149 * Drop 0-2 items of this living's type. @param par1 - Whether this entity has recently been hit by a player. @param 150 * par2 - Level of Looting used to kill this mob. 151 */ 152 protected void dropFewItems(boolean par1, int par2) 153 { 154 int var3 = this.rand.nextInt(3) + this.rand.nextInt(1 + par2); 155 156 for (int var4 = 0; var4 < var3; ++var4) 157 { 158 this.dropItem(Item.feather.itemID, 1); 159 } 160 161 if (this.isBurning()) 162 { 163 this.dropItem(Item.chickenCooked.itemID, 1); 164 } 165 else 166 { 167 this.dropItem(Item.chickenRaw.itemID, 1); 168 } 169 } 170 171 /** 172 * This function is used when two same-species animals in 'love mode' breed to generate the new baby animal. 173 */ 174 public EntityChicken spawnBabyAnimal(EntityAgeable par1EntityAgeable) 175 { 176 return new EntityChicken(this.worldObj); 177 } 178 179 /** 180 * Checks if the parameter is an item which this animal can be fed to breed it (wheat, carrots or seeds depending on 181 * the animal type) 182 */ 183 public boolean isBreedingItem(ItemStack par1ItemStack) 184 { 185 return par1ItemStack != null && par1ItemStack.getItem() instanceof ItemSeeds; 186 } 187 188 public EntityAgeable createChild(EntityAgeable par1EntityAgeable) 189 { 190 return this.spawnBabyAnimal(par1EntityAgeable); 191 } 192 }