| 1 | package net.minecraft.entity.passive;
|
| 2 |
|
| 3 | import net.minecraft.block.Block;
|
| 4 | import net.minecraft.entity.EntityAgeable;
|
| 5 | import net.minecraft.entity.SharedMonsterAttributes;
|
| 6 | import net.minecraft.entity.ai.EntityAIFollowParent;
|
| 7 | import net.minecraft.entity.ai.EntityAILookIdle;
|
| 8 | import net.minecraft.entity.ai.EntityAIMate;
|
| 9 | import net.minecraft.entity.ai.EntityAIPanic;
|
| 10 | import net.minecraft.entity.ai.EntityAISwimming;
|
| 11 | import net.minecraft.entity.ai.EntityAITempt;
|
| 12 | import net.minecraft.entity.ai.EntityAIWander;
|
| 13 | import net.minecraft.entity.ai.EntityAIWatchClosest;
|
| 14 | import net.minecraft.entity.player.EntityPlayer;
|
| 15 | import net.minecraft.init.Items;
|
| 16 | import net.minecraft.item.Item;
|
| 17 | import net.minecraft.item.ItemStack;
|
| 18 | import net.minecraft.pathfinding.PathNavigateGround;
|
| 19 | import net.minecraft.util.BlockPos;
|
| 20 | import net.minecraft.world.World;
|
| 21 |
|
| 22 | public class EntityCow extends EntityAnimal
|
| 23 | {
|
| 24 | public EntityCow(World worldIn)
|
| 25 | {
|
| 26 | super(worldIn);
|
| 27 | this.setSize(0.9F, 1.3F);
|
| 28 | ((PathNavigateGround)this.getNavigator()).setAvoidsWater(true);
|
| 29 | this.tasks.addTask(0, new EntityAISwimming(this));
|
| 30 | this.tasks.addTask(1, new EntityAIPanic(this, 2.0D));
|
| 31 | this.tasks.addTask(2, new EntityAIMate(this, 1.0D));
|
| 32 | this.tasks.addTask(3, new EntityAITempt(this, 1.25D, Items.wheat, false));
|
| 33 | this.tasks.addTask(4, new EntityAIFollowParent(this, 1.25D));
|
| 34 | this.tasks.addTask(5, new EntityAIWander(this, 1.0D));
|
| 35 | this.tasks.addTask(6, new EntityAIWatchClosest(this, EntityPlayer.class, 6.0F));
|
| 36 | this.tasks.addTask(7, new EntityAILookIdle(this));
|
| 37 | }
|
| 38 |
|
| 39 | protected void applyEntityAttributes()
|
| 40 | {
|
| 41 | super.applyEntityAttributes();
|
| 42 | this.getEntityAttribute(SharedMonsterAttributes.maxHealth).setBaseValue(10.0D);
|
| 43 | this.getEntityAttribute(SharedMonsterAttributes.movementSpeed).setBaseValue(0.20000000298023224D);
|
| 44 | }
|
| 45 |
|
| 46 | /**
|
| 47 | * Returns the sound this mob makes while it's alive.
|
| 48 | */
|
| 49 | protected String getLivingSound()
|
| 50 | {
|
| 51 | return "mob.cow.say";
|
| 52 | }
|
| 53 |
|
| 54 | /**
|
| 55 | * Returns the sound this mob makes when it is hurt.
|
| 56 | */
|
| 57 | protected String getHurtSound()
|
| 58 | {
|
| 59 | return "mob.cow.hurt";
|
| 60 | }
|
| 61 |
|
| 62 | /**
|
| 63 | * Returns the sound this mob makes on death.
|
| 64 | */
|
| 65 | protected String getDeathSound()
|
| 66 | {
|
| 67 | return "mob.cow.hurt";
|
| 68 | }
|
| 69 |
|
| 70 | protected void playStepSound(BlockPos pos, Block blockIn)
|
| 71 | {
|
| 72 | this.playSound("mob.cow.step", 0.15F, 1.0F);
|
| 73 | }
|
| 74 |
|
| 75 | /**
|
| 76 | * Returns the volume for the sounds this mob makes.
|
| 77 | */
|
| 78 | protected float getSoundVolume()
|
| 79 | {
|
| 80 | return 0.4F;
|
| 81 | }
|
| 82 |
|
| 83 | protected Item getDropItem()
|
| 84 | {
|
| 85 | return Items.leather;
|
| 86 | }
|
| 87 |
|
| 88 | /**
|
| 89 | * Drop 0-2 items of this living's type
|
| 90 | *
|
| 91 | * @param wasRecentlyHit true if this this entity was recently hit by appropriate entity (generally only if player
|
| 92 | * or tameable)
|
| 93 | * @param lootingModifier level of enchanment to be applied to this drop
|
| 94 | */
|
| 95 | protected void dropFewItems(boolean wasRecentlyHit, int lootingModifier)
|
| 96 | {
|
| 97 | int i = this.rand.nextInt(3) + this.rand.nextInt(1 + lootingModifier);
|
| 98 |
|
| 99 | for (int j = 0; j < i; ++j)
|
| 100 | {
|
| 101 | this.dropItem(Items.leather, 1);
|
| 102 | }
|
| 103 |
|
| 104 | i = this.rand.nextInt(3) + 1 + this.rand.nextInt(1 + lootingModifier);
|
| 105 |
|
| 106 | for (int k = 0; k < i; ++k)
|
| 107 | {
|
| 108 | if (this.isBurning())
|
| 109 | {
|
| 110 | this.dropItem(Items.cooked_beef, 1);
|
| 111 | }
|
| 112 | else
|
| 113 | {
|
| 114 | this.dropItem(Items.beef, 1);
|
| 115 | }
|
| 116 | }
|
| 117 | }
|
| 118 |
|
| 119 | /**
|
| 120 | * Called when a player interacts with a mob. e.g. gets milk from a cow, gets into the saddle on a pig.
|
| 121 | */
|
| 122 | public boolean interact(EntityPlayer player)
|
| 123 | {
|
| 124 | ItemStack itemstack = player.inventory.getCurrentItem();
|
| 125 |
|
| 126 | if (itemstack != null && itemstack.getItem() == Items.bucket && !player.capabilities.isCreativeMode && !this.isChild())
|
| 127 | {
|
| 128 | if (itemstack.stackSize-- == 1)
|
| 129 | {
|
| 130 | player.inventory.setInventorySlotContents(player.inventory.currentItem, new ItemStack(Items.milk_bucket));
|
| 131 | }
|
| 132 | else if (!player.inventory.addItemStackToInventory(new ItemStack(Items.milk_bucket)))
|
| 133 | {
|
| 134 | player.dropPlayerItemWithRandomChoice(new ItemStack(Items.milk_bucket, 1, 0), false);
|
| 135 | }
|
| 136 |
|
| 137 | return true;
|
| 138 | }
|
| 139 | else
|
| 140 | {
|
| 141 | return super.interact(player);
|
| 142 | }
|
| 143 | }
|
| 144 |
|
| 145 | public EntityCow createChild(EntityAgeable ageable)
|
| 146 | {
|
| 147 | return new EntityCow(this.worldObj);
|
| 148 | }
|
| 149 |
|
| 150 | public float getEyeHeight()
|
| 151 | {
|
| 152 | return this.height;
|
| 153 | }
|
| 154 | }
|
| 155 |
|