| 1 | package net.minecraft.entity.passive;
|
| 2 |
|
| 3 | import net.minecraft.block.Block;
|
| 4 | import net.minecraft.entity.EntityAgeable;
|
| 5 | import net.minecraft.entity.EntityLivingBase;
|
| 6 | import net.minecraft.entity.SharedMonsterAttributes;
|
| 7 | import net.minecraft.entity.ai.EntityAIFollowParent;
|
| 8 | import net.minecraft.entity.ai.EntityAILookIdle;
|
| 9 | import net.minecraft.entity.ai.EntityAIMate;
|
| 10 | import net.minecraft.entity.ai.EntityAIPanic;
|
| 11 | import net.minecraft.entity.ai.EntityAISwimming;
|
| 12 | import net.minecraft.entity.ai.EntityAITempt;
|
| 13 | import net.minecraft.entity.ai.EntityAIWander;
|
| 14 | import net.minecraft.entity.ai.EntityAIWatchClosest;
|
| 15 | import net.minecraft.entity.player.EntityPlayer;
|
| 16 | import net.minecraft.init.Items;
|
| 17 | import net.minecraft.item.Item;
|
| 18 | import net.minecraft.item.ItemStack;
|
| 19 | import net.minecraft.nbt.NBTTagCompound;
|
| 20 | import net.minecraft.util.BlockPos;
|
| 21 | import net.minecraft.util.MathHelper;
|
| 22 | import net.minecraft.world.World;
|
| 23 |
|
| 24 | public class EntityChicken extends EntityAnimal
|
| 25 | {
|
| 26 | public float wingRotation;
|
| 27 | public float destPos;
|
| 28 | public float field_70884_g;
|
| 29 | public float field_70888_h;
|
| 30 | public float wingRotDelta = 1.0F;
|
| 31 |
|
| 32 | /** The time until the next egg is spawned. */
|
| 33 | public int timeUntilNextEgg;
|
| 34 | public boolean chickenJockey;
|
| 35 |
|
| 36 | public EntityChicken(World worldIn)
|
| 37 | {
|
| 38 | super(worldIn);
|
| 39 | this.setSize(0.4F, 0.7F);
|
| 40 | this.timeUntilNextEgg = this.rand.nextInt(6000) + 6000;
|
| 41 | this.tasks.addTask(0, new EntityAISwimming(this));
|
| 42 | this.tasks.addTask(1, new EntityAIPanic(this, 1.4D));
|
| 43 | this.tasks.addTask(2, new EntityAIMate(this, 1.0D));
|
| 44 | this.tasks.addTask(3, new EntityAITempt(this, 1.0D, Items.wheat_seeds, false));
|
| 45 | this.tasks.addTask(4, new EntityAIFollowParent(this, 1.1D));
|
| 46 | this.tasks.addTask(5, new EntityAIWander(this, 1.0D));
|
| 47 | this.tasks.addTask(6, new EntityAIWatchClosest(this, EntityPlayer.class, 6.0F));
|
| 48 | this.tasks.addTask(7, new EntityAILookIdle(this));
|
| 49 | }
|
| 50 |
|
| 51 | public float getEyeHeight()
|
| 52 | {
|
| 53 | return this.height;
|
| 54 | }
|
| 55 |
|
| 56 | protected void applyEntityAttributes()
|
| 57 | {
|
| 58 | super.applyEntityAttributes();
|
| 59 | this.getEntityAttribute(SharedMonsterAttributes.maxHealth).setBaseValue(4.0D);
|
| 60 | this.getEntityAttribute(SharedMonsterAttributes.movementSpeed).setBaseValue(0.25D);
|
| 61 | }
|
| 62 |
|
| 63 | /**
|
| 64 | * Called frequently so the entity can update its state every tick as required. For example, zombies and skeletons
|
| 65 | * use this to react to sunlight and start to burn.
|
| 66 | */
|
| 67 | public void onLivingUpdate()
|
| 68 | {
|
| 69 | super.onLivingUpdate();
|
| 70 | this.field_70888_h = this.wingRotation;
|
| 71 | this.field_70884_g = this.destPos;
|
| 72 | this.destPos = (float)((double)this.destPos + (double)(this.onGround ? -1 : 4) * 0.3D);
|
| 73 | this.destPos = MathHelper.clamp_float(this.destPos, 0.0F, 1.0F);
|
| 74 |
|
| 75 | if (!this.onGround && this.wingRotDelta < 1.0F)
|
| 76 | {
|
| 77 | this.wingRotDelta = 1.0F;
|
| 78 | }
|
| 79 |
|
| 80 | this.wingRotDelta = (float)((double)this.wingRotDelta * 0.9D);
|
| 81 |
|
| 82 | if (!this.onGround && this.motionY < 0.0D)
|
| 83 | {
|
| 84 | this.motionY *= 0.6D;
|
| 85 | }
|
| 86 |
|
| 87 | this.wingRotation += this.wingRotDelta * 2.0F;
|
| 88 |
|
| 89 | if (!this.worldObj.isRemote && !this.isChild() && !this.isChickenJockey() && --this.timeUntilNextEgg <= 0)
|
| 90 | {
|
| 91 | this.playSound("mob.chicken.plop", 1.0F, (this.rand.nextFloat() - this.rand.nextFloat()) * 0.2F + 1.0F);
|
| 92 | this.dropItem(Items.egg, 1);
|
| 93 | this.timeUntilNextEgg = this.rand.nextInt(6000) + 6000;
|
| 94 | }
|
| 95 | }
|
| 96 |
|
| 97 | public void fall(float distance, float damageMultiplier)
|
| 98 | {
|
| 99 | }
|
| 100 |
|
| 101 | /**
|
| 102 | * Returns the sound this mob makes while it's alive.
|
| 103 | */
|
| 104 | protected String getLivingSound()
|
| 105 | {
|
| 106 | return "mob.chicken.say";
|
| 107 | }
|
| 108 |
|
| 109 | /**
|
| 110 | * Returns the sound this mob makes when it is hurt.
|
| 111 | */
|
| 112 | protected String getHurtSound()
|
| 113 | {
|
| 114 | return "mob.chicken.hurt";
|
| 115 | }
|
| 116 |
|
| 117 | /**
|
| 118 | * Returns the sound this mob makes on death.
|
| 119 | */
|
| 120 | protected String getDeathSound()
|
| 121 | {
|
| 122 | return "mob.chicken.hurt";
|
| 123 | }
|
| 124 |
|
| 125 | protected void playStepSound(BlockPos pos, Block blockIn)
|
| 126 | {
|
| 127 | this.playSound("mob.chicken.step", 0.15F, 1.0F);
|
| 128 | }
|
| 129 |
|
| 130 | protected Item getDropItem()
|
| 131 | {
|
| 132 | return Items.feather;
|
| 133 | }
|
| 134 |
|
| 135 | /**
|
| 136 | * Drop 0-2 items of this living's type
|
| 137 | *
|
| 138 | * @param wasRecentlyHit true if this this entity was recently hit by appropriate entity (generally only if player
|
| 139 | * or tameable)
|
| 140 | * @param lootingModifier level of enchanment to be applied to this drop
|
| 141 | */
|
| 142 | protected void dropFewItems(boolean wasRecentlyHit, int lootingModifier)
|
| 143 | {
|
| 144 | int i = this.rand.nextInt(3) + this.rand.nextInt(1 + lootingModifier);
|
| 145 |
|
| 146 | for (int j = 0; j < i; ++j)
|
| 147 | {
|
| 148 | this.dropItem(Items.feather, 1);
|
| 149 | }
|
| 150 |
|
| 151 | if (this.isBurning())
|
| 152 | {
|
| 153 | this.dropItem(Items.cooked_chicken, 1);
|
| 154 | }
|
| 155 | else
|
| 156 | {
|
| 157 | this.dropItem(Items.chicken, 1);
|
| 158 | }
|
| 159 | }
|
| 160 |
|
| 161 | public EntityChicken createChild(EntityAgeable ageable)
|
| 162 | {
|
| 163 | return new EntityChicken(this.worldObj);
|
| 164 | }
|
| 165 |
|
| 166 | /**
|
| 167 | * Checks if the parameter is an item which this animal can be fed to breed it (wheat, carrots or seeds depending on
|
| 168 | * the animal type)
|
| 169 | */
|
| 170 | public boolean isBreedingItem(ItemStack stack)
|
| 171 | {
|
| 172 | return stack != null && stack.getItem() == Items.wheat_seeds;
|
| 173 | }
|
| 174 |
|
| 175 | /**
|
| 176 | * (abstract) Protected helper method to read subclass entity data from NBT.
|
| 177 | */
|
| 178 | public void readEntityFromNBT(NBTTagCompound tagCompund)
|
| 179 | {
|
| 180 | super.readEntityFromNBT(tagCompund);
|
| 181 | this.chickenJockey = tagCompund.getBoolean("IsChickenJockey");
|
| 182 |
|
| 183 | if (tagCompund.hasKey("EggLayTime"))
|
| 184 | {
|
| 185 | this.timeUntilNextEgg = tagCompund.getInteger("EggLayTime");
|
| 186 | }
|
| 187 | }
|
| 188 |
|
| 189 | /**
|
| 190 | * Get the experience points the entity currently has.
|
| 191 | */
|
| 192 | protected int getExperiencePoints(EntityPlayer player)
|
| 193 | {
|
| 194 | return this.isChickenJockey() ? 10 : super.getExperiencePoints(player);
|
| 195 | }
|
| 196 |
|
| 197 | /**
|
| 198 | * (abstract) Protected helper method to write subclass entity data to NBT.
|
| 199 | */
|
| 200 | public void writeEntityToNBT(NBTTagCompound tagCompound)
|
| 201 | {
|
| 202 | super.writeEntityToNBT(tagCompound);
|
| 203 | tagCompound.setBoolean("IsChickenJockey", this.chickenJockey);
|
| 204 | tagCompound.setInteger("EggLayTime", this.timeUntilNextEgg);
|
| 205 | }
|
| 206 |
|
| 207 | /**
|
| 208 | * Determines if an entity can be despawned, used on idle far away entities
|
| 209 | */
|
| 210 | protected boolean canDespawn()
|
| 211 | {
|
| 212 | return this.isChickenJockey() && this.riddenByEntity == null;
|
| 213 | }
|
| 214 |
|
| 215 | public void updateRiderPosition()
|
| 216 | {
|
| 217 | super.updateRiderPosition();
|
| 218 | float f = MathHelper.sin(this.renderYawOffset * (float)Math.PI / 180.0F);
|
| 219 | float f1 = MathHelper.cos(this.renderYawOffset * (float)Math.PI / 180.0F);
|
| 220 | float f2 = 0.1F;
|
| 221 | float f3 = 0.0F;
|
| 222 | this.riddenByEntity.setPosition(this.posX + (double)(f2 * f), this.posY + (double)(this.height * 0.5F) + this.riddenByEntity.getYOffset() + (double)f3, this.posZ - (double)(f2 * f1));
|
| 223 |
|
| 224 | if (this.riddenByEntity instanceof EntityLivingBase)
|
| 225 | {
|
| 226 | ((EntityLivingBase)this.riddenByEntity).renderYawOffset = this.renderYawOffset;
|
| 227 | }
|
| 228 | }
|
| 229 |
|
| 230 | /**
|
| 231 | * Determines if this chicken is a jokey with a zombie riding it.
|
| 232 | */
|
| 233 | public boolean isChickenJockey()
|
| 234 | {
|
| 235 | return this.chickenJockey;
|
| 236 | }
|
| 237 |
|
| 238 | /**
|
| 239 | * Sets whether this chicken is a jockey or not.
|
| 240 | */
|
| 241 | public void setChickenJockey(boolean jockey)
|
| 242 | {
|
| 243 | this.chickenJockey = jockey;
|
| 244 | }
|
| 245 | }
|
| 246 |
|