| 1 | package net.minecraft.entity.passive;
|
| 2 |
|
| 3 | import com.google.common.base.Predicate;
|
| 4 | import net.minecraft.block.Block;
|
| 5 | import net.minecraft.block.material.Material;
|
| 6 | import net.minecraft.entity.Entity;
|
| 7 | import net.minecraft.entity.EntityAgeable;
|
| 8 | import net.minecraft.entity.IEntityLivingData;
|
| 9 | import net.minecraft.entity.SharedMonsterAttributes;
|
| 10 | import net.minecraft.entity.ai.EntityAIAvoidEntity;
|
| 11 | import net.minecraft.entity.ai.EntityAIFollowOwner;
|
| 12 | import net.minecraft.entity.ai.EntityAILeapAtTarget;
|
| 13 | import net.minecraft.entity.ai.EntityAIMate;
|
| 14 | import net.minecraft.entity.ai.EntityAIOcelotAttack;
|
| 15 | import net.minecraft.entity.ai.EntityAIOcelotSit;
|
| 16 | import net.minecraft.entity.ai.EntityAISwimming;
|
| 17 | import net.minecraft.entity.ai.EntityAITargetNonTamed;
|
| 18 | import net.minecraft.entity.ai.EntityAITempt;
|
| 19 | import net.minecraft.entity.ai.EntityAIWander;
|
| 20 | import net.minecraft.entity.ai.EntityAIWatchClosest;
|
| 21 | import net.minecraft.entity.player.EntityPlayer;
|
| 22 | import net.minecraft.init.Blocks;
|
| 23 | import net.minecraft.init.Items;
|
| 24 | import net.minecraft.item.Item;
|
| 25 | import net.minecraft.item.ItemStack;
|
| 26 | import net.minecraft.nbt.NBTTagCompound;
|
| 27 | import net.minecraft.pathfinding.PathNavigateGround;
|
| 28 | import net.minecraft.util.BlockPos;
|
| 29 | import net.minecraft.util.DamageSource;
|
| 30 | import net.minecraft.util.StatCollector;
|
| 31 | import net.minecraft.world.DifficultyInstance;
|
| 32 | import net.minecraft.world.World;
|
| 33 |
|
| 34 | public class EntityOcelot extends EntityTameable
|
| 35 | {
|
| 36 | private EntityAIAvoidEntity<EntityPlayer> avoidEntity;
|
| 37 |
|
| 38 | /**
|
| 39 | * The tempt AI task for this mob, used to prevent taming while it is fleeing.
|
| 40 | */
|
| 41 | private EntityAITempt aiTempt;
|
| 42 |
|
| 43 | public EntityOcelot(World worldIn)
|
| 44 | {
|
| 45 | super(worldIn);
|
| 46 | this.setSize(0.6F, 0.7F);
|
| 47 | ((PathNavigateGround)this.getNavigator()).setAvoidsWater(true);
|
| 48 | this.tasks.addTask(1, new EntityAISwimming(this));
|
| 49 | this.tasks.addTask(2, this.aiSit);
|
| 50 | this.tasks.addTask(3, this.aiTempt = new EntityAITempt(this, 0.6D, Items.fish, true));
|
| 51 | this.tasks.addTask(5, new EntityAIFollowOwner(this, 1.0D, 10.0F, 5.0F));
|
| 52 | this.tasks.addTask(6, new EntityAIOcelotSit(this, 0.8D));
|
| 53 | this.tasks.addTask(7, new EntityAILeapAtTarget(this, 0.3F));
|
| 54 | this.tasks.addTask(8, new EntityAIOcelotAttack(this));
|
| 55 | this.tasks.addTask(9, new EntityAIMate(this, 0.8D));
|
| 56 | this.tasks.addTask(10, new EntityAIWander(this, 0.8D));
|
| 57 | this.tasks.addTask(11, new EntityAIWatchClosest(this, EntityPlayer.class, 10.0F));
|
| 58 | this.targetTasks.addTask(1, new EntityAITargetNonTamed(this, EntityChicken.class, false, (Predicate)null));
|
| 59 | }
|
| 60 |
|
| 61 | protected void entityInit()
|
| 62 | {
|
| 63 | super.entityInit();
|
| 64 | this.dataWatcher.addObject(18, Byte.valueOf((byte)0));
|
| 65 | }
|
| 66 |
|
| 67 | public void updateAITasks()
|
| 68 | {
|
| 69 | if (this.getMoveHelper().isUpdating())
|
| 70 | {
|
| 71 | double d0 = this.getMoveHelper().getSpeed();
|
| 72 |
|
| 73 | if (d0 == 0.6D)
|
| 74 | {
|
| 75 | this.setSneaking(true);
|
| 76 | this.setSprinting(false);
|
| 77 | }
|
| 78 | else if (d0 == 1.33D)
|
| 79 | {
|
| 80 | this.setSneaking(false);
|
| 81 | this.setSprinting(true);
|
| 82 | }
|
| 83 | else
|
| 84 | {
|
| 85 | this.setSneaking(false);
|
| 86 | this.setSprinting(false);
|
| 87 | }
|
| 88 | }
|
| 89 | else
|
| 90 | {
|
| 91 | this.setSneaking(false);
|
| 92 | this.setSprinting(false);
|
| 93 | }
|
| 94 | }
|
| 95 |
|
| 96 | /**
|
| 97 | * Determines if an entity can be despawned, used on idle far away entities
|
| 98 | */
|
| 99 | protected boolean canDespawn()
|
| 100 | {
|
| 101 | return !this.isTamed() && this.ticksExisted > 2400;
|
| 102 | }
|
| 103 |
|
| 104 | protected void applyEntityAttributes()
|
| 105 | {
|
| 106 | super.applyEntityAttributes();
|
| 107 | this.getEntityAttribute(SharedMonsterAttributes.maxHealth).setBaseValue(10.0D);
|
| 108 | this.getEntityAttribute(SharedMonsterAttributes.movementSpeed).setBaseValue(0.30000001192092896D);
|
| 109 | }
|
| 110 |
|
| 111 | public void fall(float distance, float damageMultiplier)
|
| 112 | {
|
| 113 | }
|
| 114 |
|
| 115 | /**
|
| 116 | * (abstract) Protected helper method to write subclass entity data to NBT.
|
| 117 | */
|
| 118 | public void writeEntityToNBT(NBTTagCompound tagCompound)
|
| 119 | {
|
| 120 | super.writeEntityToNBT(tagCompound);
|
| 121 | tagCompound.setInteger("CatType", this.getTameSkin());
|
| 122 | }
|
| 123 |
|
| 124 | /**
|
| 125 | * (abstract) Protected helper method to read subclass entity data from NBT.
|
| 126 | */
|
| 127 | public void readEntityFromNBT(NBTTagCompound tagCompund)
|
| 128 | {
|
| 129 | super.readEntityFromNBT(tagCompund);
|
| 130 | this.setTameSkin(tagCompund.getInteger("CatType"));
|
| 131 | }
|
| 132 |
|
| 133 | /**
|
| 134 | * Returns the sound this mob makes while it's alive.
|
| 135 | */
|
| 136 | protected String getLivingSound()
|
| 137 | {
|
| 138 | return this.isTamed() ? (this.isInLove() ? "mob.cat.purr" : (this.rand.nextInt(4) == 0 ? "mob.cat.purreow" : "mob.cat.meow")) : "";
|
| 139 | }
|
| 140 |
|
| 141 | /**
|
| 142 | * Returns the sound this mob makes when it is hurt.
|
| 143 | */
|
| 144 | protected String getHurtSound()
|
| 145 | {
|
| 146 | return "mob.cat.hitt";
|
| 147 | }
|
| 148 |
|
| 149 | /**
|
| 150 | * Returns the sound this mob makes on death.
|
| 151 | */
|
| 152 | protected String getDeathSound()
|
| 153 | {
|
| 154 | return "mob.cat.hitt";
|
| 155 | }
|
| 156 |
|
| 157 | /**
|
| 158 | * Returns the volume for the sounds this mob makes.
|
| 159 | */
|
| 160 | protected float getSoundVolume()
|
| 161 | {
|
| 162 | return 0.4F;
|
| 163 | }
|
| 164 |
|
| 165 | protected Item getDropItem()
|
| 166 | {
|
| 167 | return Items.leather;
|
| 168 | }
|
| 169 |
|
| 170 | public boolean attackEntityAsMob(Entity entityIn)
|
| 171 | {
|
| 172 | return entityIn.attackEntityFrom(DamageSource.causeMobDamage(this), 3.0F);
|
| 173 | }
|
| 174 |
|
| 175 | /**
|
| 176 | * Called when the entity is attacked.
|
| 177 | */
|
| 178 | public boolean attackEntityFrom(DamageSource source, float amount)
|
| 179 | {
|
| 180 | if (this.isEntityInvulnerable(source))
|
| 181 | {
|
| 182 | return false;
|
| 183 | }
|
| 184 | else
|
| 185 | {
|
| 186 | this.aiSit.setSitting(false);
|
| 187 | return super.attackEntityFrom(source, amount);
|
| 188 | }
|
| 189 | }
|
| 190 |
|
| 191 | /**
|
| 192 | * Drop 0-2 items of this living's type
|
| 193 | *
|
| 194 | * @param wasRecentlyHit true if this this entity was recently hit by appropriate entity (generally only if player
|
| 195 | * or tameable)
|
| 196 | * @param lootingModifier level of enchanment to be applied to this drop
|
| 197 | */
|
| 198 | protected void dropFewItems(boolean wasRecentlyHit, int lootingModifier)
|
| 199 | {
|
| 200 | }
|
| 201 |
|
| 202 | /**
|
| 203 | * Called when a player interacts with a mob. e.g. gets milk from a cow, gets into the saddle on a pig.
|
| 204 | */
|
| 205 | public boolean interact(EntityPlayer player)
|
| 206 | {
|
| 207 | ItemStack itemstack = player.inventory.getCurrentItem();
|
| 208 |
|
| 209 | if (this.isTamed())
|
| 210 | {
|
| 211 | if (this.isOwner(player) && !this.worldObj.isRemote && !this.isBreedingItem(itemstack))
|
| 212 | {
|
| 213 | this.aiSit.setSitting(!this.isSitting());
|
| 214 | }
|
| 215 | }
|
| 216 | else if (this.aiTempt.isRunning() && itemstack != null && itemstack.getItem() == Items.fish && player.getDistanceSqToEntity(this) < 9.0D)
|
| 217 | {
|
| 218 | if (!player.capabilities.isCreativeMode)
|
| 219 | {
|
| 220 | --itemstack.stackSize;
|
| 221 | }
|
| 222 |
|
| 223 | if (itemstack.stackSize <= 0)
|
| 224 | {
|
| 225 | player.inventory.setInventorySlotContents(player.inventory.currentItem, (ItemStack)null);
|
| 226 | }
|
| 227 |
|
| 228 | if (!this.worldObj.isRemote)
|
| 229 | {
|
| 230 | if (this.rand.nextInt(3) == 0)
|
| 231 | {
|
| 232 | this.setTamed(true);
|
| 233 | this.setTameSkin(1 + this.worldObj.rand.nextInt(3));
|
| 234 | this.setOwnerId(player.getUniqueID().toString());
|
| 235 | this.playTameEffect(true);
|
| 236 | this.aiSit.setSitting(true);
|
| 237 | this.worldObj.setEntityState(this, (byte)7);
|
| 238 | }
|
| 239 | else
|
| 240 | {
|
| 241 | this.playTameEffect(false);
|
| 242 | this.worldObj.setEntityState(this, (byte)6);
|
| 243 | }
|
| 244 | }
|
| 245 |
|
| 246 | return true;
|
| 247 | }
|
| 248 |
|
| 249 | return super.interact(player);
|
| 250 | }
|
| 251 |
|
| 252 | public EntityOcelot createChild(EntityAgeable ageable)
|
| 253 | {
|
| 254 | EntityOcelot entityocelot = new EntityOcelot(this.worldObj);
|
| 255 |
|
| 256 | if (this.isTamed())
|
| 257 | {
|
| 258 | entityocelot.setOwnerId(this.getOwnerId());
|
| 259 | entityocelot.setTamed(true);
|
| 260 | entityocelot.setTameSkin(this.getTameSkin());
|
| 261 | }
|
| 262 |
|
| 263 | return entityocelot;
|
| 264 | }
|
| 265 |
|
| 266 | /**
|
| 267 | * Checks if the parameter is an item which this animal can be fed to breed it (wheat, carrots or seeds depending on
|
| 268 | * the animal type)
|
| 269 | */
|
| 270 | public boolean isBreedingItem(ItemStack stack)
|
| 271 | {
|
| 272 | return stack != null && stack.getItem() == Items.fish;
|
| 273 | }
|
| 274 |
|
| 275 | /**
|
| 276 | * Returns true if the mob is currently able to mate with the specified mob.
|
| 277 | */
|
| 278 | public boolean canMateWith(EntityAnimal otherAnimal)
|
| 279 | {
|
| 280 | if (otherAnimal == this)
|
| 281 | {
|
| 282 | return false;
|
| 283 | }
|
| 284 | else if (!this.isTamed())
|
| 285 | {
|
| 286 | return false;
|
| 287 | }
|
| 288 | else if (!(otherAnimal instanceof EntityOcelot))
|
| 289 | {
|
| 290 | return false;
|
| 291 | }
|
| 292 | else
|
| 293 | {
|
| 294 | EntityOcelot entityocelot = (EntityOcelot)otherAnimal;
|
| 295 | return !entityocelot.isTamed() ? false : this.isInLove() && entityocelot.isInLove();
|
| 296 | }
|
| 297 | }
|
| 298 |
|
| 299 | public int getTameSkin()
|
| 300 | {
|
| 301 | return this.dataWatcher.getWatchableObjectByte(18);
|
| 302 | }
|
| 303 |
|
| 304 | public void setTameSkin(int skinId)
|
| 305 | {
|
| 306 | this.dataWatcher.updateObject(18, Byte.valueOf((byte)skinId));
|
| 307 | }
|
| 308 |
|
| 309 | /**
|
| 310 | * Checks if the entity's current position is a valid location to spawn this entity.
|
| 311 | */
|
| 312 | public boolean getCanSpawnHere()
|
| 313 | {
|
| 314 | return this.worldObj.rand.nextInt(3) != 0;
|
| 315 | }
|
| 316 |
|
| 317 | /**
|
| 318 | * Checks that the entity is not colliding with any blocks / liquids
|
| 319 | */
|
| 320 | public boolean isNotColliding()
|
| 321 | {
|
| 322 | if (this.worldObj.checkNoEntityCollision(this.getEntityBoundingBox(), this) && this.worldObj.getCollidingBoundingBoxes(this, this.getEntityBoundingBox()).isEmpty() && !this.worldObj.isAnyLiquid(this.getEntityBoundingBox()))
|
| 323 | {
|
| 324 | BlockPos blockpos = new BlockPos(this.posX, this.getEntityBoundingBox().minY, this.posZ);
|
| 325 |
|
| 326 | if (blockpos.getY() < this.worldObj.getSeaLevel())
|
| 327 | {
|
| 328 | return false;
|
| 329 | }
|
| 330 |
|
| 331 | Block block = this.worldObj.getBlockState(blockpos.down()).getBlock();
|
| 332 |
|
| 333 | if (block == Blocks.grass || block.getMaterial() == Material.leaves)
|
| 334 | {
|
| 335 | return true;
|
| 336 | }
|
| 337 | }
|
| 338 |
|
| 339 | return false;
|
| 340 | }
|
| 341 |
|
| 342 | /**
|
| 343 | * Get the name of this object. For players this returns their username
|
| 344 | */
|
| 345 | public String getName()
|
| 346 | {
|
| 347 | return this.hasCustomName() ? this.getCustomNameTag() : (this.isTamed() ? StatCollector.translateToLocal("entity.Cat.name") : super.getName());
|
| 348 | }
|
| 349 |
|
| 350 | public void setTamed(boolean tamed)
|
| 351 | {
|
| 352 | super.setTamed(tamed);
|
| 353 | }
|
| 354 |
|
| 355 | protected void setupTamedAI()
|
| 356 | {
|
| 357 | if (this.avoidEntity == null)
|
| 358 | {
|
| 359 | this.avoidEntity = new EntityAIAvoidEntity(this, EntityPlayer.class, 16.0F, 0.8D, 1.33D);
|
| 360 | }
|
| 361 |
|
| 362 | this.tasks.removeTask(this.avoidEntity);
|
| 363 |
|
| 364 | if (!this.isTamed())
|
| 365 | {
|
| 366 | this.tasks.addTask(4, this.avoidEntity);
|
| 367 | }
|
| 368 | }
|
| 369 |
|
| 370 | /**
|
| 371 | * Called only once on an entity when first time spawned, via egg, mob spawner, natural spawning etc, but not called
|
| 372 | * when entity is reloaded from nbt. Mainly used for initializing attributes and inventory
|
| 373 | */
|
| 374 | public IEntityLivingData onInitialSpawn(DifficultyInstance difficulty, IEntityLivingData livingdata)
|
| 375 | {
|
| 376 | livingdata = super.onInitialSpawn(difficulty, livingdata);
|
| 377 |
|
| 378 | if (this.worldObj.rand.nextInt(7) == 0)
|
| 379 | {
|
| 380 | for (int i = 0; i < 2; ++i)
|
| 381 | {
|
| 382 | EntityOcelot entityocelot = new EntityOcelot(this.worldObj);
|
| 383 | entityocelot.setLocationAndAngles(this.posX, this.posY, this.posZ, this.rotationYaw, 0.0F);
|
| 384 | entityocelot.setGrowingAge(-24000);
|
| 385 | this.worldObj.spawnEntityInWorld(entityocelot);
|
| 386 | }
|
| 387 | }
|
| 388 |
|
| 389 | return livingdata;
|
| 390 | }
|
| 391 | }
|
| 392 |
|