| 1 | package net.minecraft.entity;
|
| 2 |
|
| 3 | import java.util.UUID;
|
| 4 | import net.minecraft.enchantment.EnchantmentHelper;
|
| 5 | import net.minecraft.entity.ai.EntityAITasks;
|
| 6 | import net.minecraft.entity.ai.EntityJumpHelper;
|
| 7 | import net.minecraft.entity.ai.EntityLookHelper;
|
| 8 | import net.minecraft.entity.ai.EntityMoveHelper;
|
| 9 | import net.minecraft.entity.ai.EntitySenses;
|
| 10 | import net.minecraft.entity.ai.attributes.AttributeModifier;
|
| 11 | import net.minecraft.entity.item.EntityItem;
|
| 12 | import net.minecraft.entity.monster.EntityGhast;
|
| 13 | import net.minecraft.entity.monster.IMob;
|
| 14 | import net.minecraft.entity.passive.EntityTameable;
|
| 15 | import net.minecraft.entity.player.EntityPlayer;
|
| 16 | import net.minecraft.init.Blocks;
|
| 17 | import net.minecraft.init.Items;
|
| 18 | import net.minecraft.item.Item;
|
| 19 | import net.minecraft.item.ItemArmor;
|
| 20 | import net.minecraft.item.ItemBlock;
|
| 21 | import net.minecraft.item.ItemBow;
|
| 22 | import net.minecraft.item.ItemStack;
|
| 23 | import net.minecraft.item.ItemSword;
|
| 24 | import net.minecraft.nbt.NBTTagCompound;
|
| 25 | import net.minecraft.nbt.NBTTagFloat;
|
| 26 | import net.minecraft.nbt.NBTTagList;
|
| 27 | import net.minecraft.network.play.server.S1BPacketEntityAttach;
|
| 28 | import net.minecraft.pathfinding.PathNavigate;
|
| 29 | import net.minecraft.pathfinding.PathNavigateGround;
|
| 30 | import net.minecraft.stats.AchievementList;
|
| 31 | import net.minecraft.util.BlockPos;
|
| 32 | import net.minecraft.util.EnumParticleTypes;
|
| 33 | import net.minecraft.util.MathHelper;
|
| 34 | import net.minecraft.world.DifficultyInstance;
|
| 35 | import net.minecraft.world.EnumDifficulty;
|
| 36 | import net.minecraft.world.World;
|
| 37 | import net.minecraft.world.WorldServer;
|
| 38 |
|
| 39 | public abstract class EntityLiving extends EntityLivingBase
|
| 40 | {
|
| 41 | /** Number of ticks since this EntityLiving last produced its sound */
|
| 42 | public int livingSoundTime;
|
| 43 |
|
| 44 | /** The experience points the Entity gives. */
|
| 45 | protected int experienceValue;
|
| 46 | private EntityLookHelper lookHelper;
|
| 47 | protected EntityMoveHelper moveHelper;
|
| 48 |
|
| 49 | /** Entity jumping helper */
|
| 50 | protected EntityJumpHelper jumpHelper;
|
| 51 | private EntityBodyHelper bodyHelper;
|
| 52 | protected PathNavigate navigator;
|
| 53 |
|
| 54 | /** Passive tasks (wandering, look, idle, ...) */
|
| 55 | protected final EntityAITasks tasks;
|
| 56 |
|
| 57 | /** Fighting tasks (used by monsters, wolves, ocelots) */
|
| 58 | protected final EntityAITasks targetTasks;
|
| 59 |
|
| 60 | /** The active target the Task system uses for tracking */
|
| 61 | private EntityLivingBase attackTarget;
|
| 62 | private EntitySenses senses;
|
| 63 |
|
| 64 | /** Equipment (armor and held item) for this entity. */
|
| 65 | private ItemStack[] equipment = new ItemStack[5];
|
| 66 |
|
| 67 | /** Chances for each equipment piece from dropping when this entity dies. */
|
| 68 | protected float[] equipmentDropChances = new float[5];
|
| 69 |
|
| 70 | /** Whether this entity can pick up items from the ground. */
|
| 71 | private boolean canPickUpLoot;
|
| 72 |
|
| 73 | /** Whether this entity should NOT despawn. */
|
| 74 | private boolean persistenceRequired;
|
| 75 | private boolean isLeashed;
|
| 76 | private Entity leashedToEntity;
|
| 77 | private NBTTagCompound leashNBTTag;
|
| 78 |
|
| 79 | public EntityLiving(World worldIn)
|
| 80 | {
|
| 81 | super(worldIn);
|
| 82 | this.tasks = new EntityAITasks(worldIn != null && worldIn.theProfiler != null ? worldIn.theProfiler : null);
|
| 83 | this.targetTasks = new EntityAITasks(worldIn != null && worldIn.theProfiler != null ? worldIn.theProfiler : null);
|
| 84 | this.lookHelper = new EntityLookHelper(this);
|
| 85 | this.moveHelper = new EntityMoveHelper(this);
|
| 86 | this.jumpHelper = new EntityJumpHelper(this);
|
| 87 | this.bodyHelper = new EntityBodyHelper(this);
|
| 88 | this.navigator = this.getNewNavigator(worldIn);
|
| 89 | this.senses = new EntitySenses(this);
|
| 90 |
|
| 91 | for (int i = 0; i < this.equipmentDropChances.length; ++i)
|
| 92 | {
|
| 93 | this.equipmentDropChances[i] = 0.085F;
|
| 94 | }
|
| 95 | }
|
| 96 |
|
| 97 | protected void applyEntityAttributes()
|
| 98 | {
|
| 99 | super.applyEntityAttributes();
|
| 100 | this.getAttributeMap().registerAttribute(SharedMonsterAttributes.followRange).setBaseValue(16.0D);
|
| 101 | }
|
| 102 |
|
| 103 | /**
|
| 104 | * Returns new PathNavigateGround instance
|
| 105 | */
|
| 106 | protected PathNavigate getNewNavigator(World worldIn)
|
| 107 | {
|
| 108 | return new PathNavigateGround(this, worldIn);
|
| 109 | }
|
| 110 |
|
| 111 | public EntityLookHelper getLookHelper()
|
| 112 | {
|
| 113 | return this.lookHelper;
|
| 114 | }
|
| 115 |
|
| 116 | public EntityMoveHelper getMoveHelper()
|
| 117 | {
|
| 118 | return this.moveHelper;
|
| 119 | }
|
| 120 |
|
| 121 | public EntityJumpHelper getJumpHelper()
|
| 122 | {
|
| 123 | return this.jumpHelper;
|
| 124 | }
|
| 125 |
|
| 126 | public PathNavigate getNavigator()
|
| 127 | {
|
| 128 | return this.navigator;
|
| 129 | }
|
| 130 |
|
| 131 | /**
|
| 132 | * returns the EntitySenses Object for the EntityLiving
|
| 133 | */
|
| 134 | public EntitySenses getEntitySenses()
|
| 135 | {
|
| 136 | return this.senses;
|
| 137 | }
|
| 138 |
|
| 139 | /**
|
| 140 | * Gets the active target the Task system uses for tracking
|
| 141 | */
|
| 142 | public EntityLivingBase getAttackTarget()
|
| 143 | {
|
| 144 | return this.attackTarget;
|
| 145 | }
|
| 146 |
|
| 147 | /**
|
| 148 | * Sets the active target the Task system uses for tracking
|
| 149 | */
|
| 150 | public void setAttackTarget(EntityLivingBase entitylivingbaseIn)
|
| 151 | {
|
| 152 | this.attackTarget = entitylivingbaseIn;
|
| 153 | }
|
| 154 |
|
| 155 | /**
|
| 156 | * Returns true if this entity can attack entities of the specified class.
|
| 157 | */
|
| 158 | public boolean canAttackClass(Class <? extends EntityLivingBase > cls)
|
| 159 | {
|
| 160 | return cls != EntityGhast.class;
|
| 161 | }
|
| 162 |
|
| 163 | /**
|
| 164 | * This function applies the benefits of growing back wool and faster growing up to the acting entity. (This
|
| 165 | * function is used in the AIEatGrass)
|
| 166 | */
|
| 167 | public void eatGrassBonus()
|
| 168 | {
|
| 169 | }
|
| 170 |
|
| 171 | protected void entityInit()
|
| 172 | {
|
| 173 | super.entityInit();
|
| 174 | this.dataWatcher.addObject(15, Byte.valueOf((byte)0));
|
| 175 | }
|
| 176 |
|
| 177 | /**
|
| 178 | * Get number of ticks, at least during which the living entity will be silent.
|
| 179 | */
|
| 180 | public int getTalkInterval()
|
| 181 | {
|
| 182 | return 80;
|
| 183 | }
|
| 184 |
|
| 185 | /**
|
| 186 | * Plays living's sound at its position
|
| 187 | */
|
| 188 | public void playLivingSound()
|
| 189 | {
|
| 190 | String s = this.getLivingSound();
|
| 191 |
|
| 192 | if (s != null)
|
| 193 | {
|
| 194 | this.playSound(s, this.getSoundVolume(), this.getSoundPitch());
|
| 195 | }
|
| 196 | }
|
| 197 |
|
| 198 | /**
|
| 199 | * Gets called every tick from main Entity class
|
| 200 | */
|
| 201 | public void onEntityUpdate()
|
| 202 | {
|
| 203 | super.onEntityUpdate();
|
| 204 | this.worldObj.theProfiler.startSection("mobBaseTick");
|
| 205 |
|
| 206 | if (this.isEntityAlive() && this.rand.nextInt(1000) < this.livingSoundTime++)
|
| 207 | {
|
| 208 | this.livingSoundTime = -this.getTalkInterval();
|
| 209 | this.playLivingSound();
|
| 210 | }
|
| 211 |
|
| 212 | this.worldObj.theProfiler.endSection();
|
| 213 | }
|
| 214 |
|
| 215 | /**
|
| 216 | * Get the experience points the entity currently has.
|
| 217 | */
|
| 218 | protected int getExperiencePoints(EntityPlayer player)
|
| 219 | {
|
| 220 | if (this.experienceValue > 0)
|
| 221 | {
|
| 222 | int i = this.experienceValue;
|
| 223 | ItemStack[] aitemstack = this.getInventory();
|
| 224 |
|
| 225 | for (int j = 0; j < aitemstack.length; ++j)
|
| 226 | {
|
| 227 | if (aitemstack[j] != null && this.equipmentDropChances[j] <= 1.0F)
|
| 228 | {
|
| 229 | i += 1 + this.rand.nextInt(3);
|
| 230 | }
|
| 231 | }
|
| 232 |
|
| 233 | return i;
|
| 234 | }
|
| 235 | else
|
| 236 | {
|
| 237 | return this.experienceValue;
|
| 238 | }
|
| 239 | }
|
| 240 |
|
| 241 | /**
|
| 242 | * Spawns an explosion particle around the Entity's location
|
| 243 | */
|
| 244 | public void spawnExplosionParticle()
|
| 245 | {
|
| 246 | if (this.worldObj.isRemote)
|
| 247 | {
|
| 248 | for (int i = 0; i < 20; ++i)
|
| 249 | {
|
| 250 | double d0 = this.rand.nextGaussian() * 0.02D;
|
| 251 | double d1 = this.rand.nextGaussian() * 0.02D;
|
| 252 | double d2 = this.rand.nextGaussian() * 0.02D;
|
| 253 | double d3 = 10.0D;
|
| 254 | this.worldObj.spawnParticle(EnumParticleTypes.EXPLOSION_NORMAL, this.posX + (double)(this.rand.nextFloat() * this.width * 2.0F) - (double)this.width - d0 * d3, this.posY + (double)(this.rand.nextFloat() * this.height) - d1 * d3, this.posZ + (double)(this.rand.nextFloat() * this.width * 2.0F) - (double)this.width - d2 * d3, d0, d1, d2, new int[0]);
|
| 255 | }
|
| 256 | }
|
| 257 | else
|
| 258 | {
|
| 259 | this.worldObj.setEntityState(this, (byte)20);
|
| 260 | }
|
| 261 | }
|
| 262 |
|
| 263 | public void handleStatusUpdate(byte id)
|
| 264 | {
|
| 265 | if (id == 20)
|
| 266 | {
|
| 267 | this.spawnExplosionParticle();
|
| 268 | }
|
| 269 | else
|
| 270 | {
|
| 271 | super.handleStatusUpdate(id);
|
| 272 | }
|
| 273 | }
|
| 274 |
|
| 275 | /**
|
| 276 | * Called to update the entity's position/logic.
|
| 277 | */
|
| 278 | public void onUpdate()
|
| 279 | {
|
| 280 | super.onUpdate();
|
| 281 |
|
| 282 | if (!this.worldObj.isRemote)
|
| 283 | {
|
| 284 | this.updateLeashedState();
|
| 285 | }
|
| 286 | }
|
| 287 |
|
| 288 | protected float updateDistance(float p_110146_1_, float p_110146_2_)
|
| 289 | {
|
| 290 | this.bodyHelper.updateRenderAngles();
|
| 291 | return p_110146_2_;
|
| 292 | }
|
| 293 |
|
| 294 | /**
|
| 295 | * Returns the sound this mob makes while it's alive.
|
| 296 | */
|
| 297 | protected String getLivingSound()
|
| 298 | {
|
| 299 | return null;
|
| 300 | }
|
| 301 |
|
| 302 | protected Item getDropItem()
|
| 303 | {
|
| 304 | return null;
|
| 305 | }
|
| 306 |
|
| 307 | /**
|
| 308 | * Drop 0-2 items of this living's type
|
| 309 | *
|
| 310 | * @param wasRecentlyHit true if this this entity was recently hit by appropriate entity (generally only if player
|
| 311 | * or tameable)
|
| 312 | * @param lootingModifier level of enchanment to be applied to this drop
|
| 313 | */
|
| 314 | protected void dropFewItems(boolean wasRecentlyHit, int lootingModifier)
|
| 315 | {
|
| 316 | Item item = this.getDropItem();
|
| 317 |
|
| 318 | if (item != null)
|
| 319 | {
|
| 320 | int i = this.rand.nextInt(3);
|
| 321 |
|
| 322 | if (lootingModifier > 0)
|
| 323 | {
|
| 324 | i += this.rand.nextInt(lootingModifier + 1);
|
| 325 | }
|
| 326 |
|
| 327 | for (int j = 0; j < i; ++j)
|
| 328 | {
|
| 329 | this.dropItem(item, 1);
|
| 330 | }
|
| 331 | }
|
| 332 | }
|
| 333 |
|
| 334 | /**
|
| 335 | * (abstract) Protected helper method to write subclass entity data to NBT.
|
| 336 | */
|
| 337 | public void writeEntityToNBT(NBTTagCompound tagCompound)
|
| 338 | {
|
| 339 | super.writeEntityToNBT(tagCompound);
|
| 340 | tagCompound.setBoolean("CanPickUpLoot", this.canPickUpLoot());
|
| 341 | tagCompound.setBoolean("PersistenceRequired", this.persistenceRequired);
|
| 342 | NBTTagList nbttaglist = new NBTTagList();
|
| 343 |
|
| 344 | for (int i = 0; i < this.equipment.length; ++i)
|
| 345 | {
|
| 346 | NBTTagCompound nbttagcompound = new NBTTagCompound();
|
| 347 |
|
| 348 | if (this.equipment[i] != null)
|
| 349 | {
|
| 350 | this.equipment[i].writeToNBT(nbttagcompound);
|
| 351 | }
|
| 352 |
|
| 353 | nbttaglist.appendTag(nbttagcompound);
|
| 354 | }
|
| 355 |
|
| 356 | tagCompound.setTag("Equipment", nbttaglist);
|
| 357 | NBTTagList nbttaglist1 = new NBTTagList();
|
| 358 |
|
| 359 | for (int j = 0; j < this.equipmentDropChances.length; ++j)
|
| 360 | {
|
| 361 | nbttaglist1.appendTag(new NBTTagFloat(this.equipmentDropChances[j]));
|
| 362 | }
|
| 363 |
|
| 364 | tagCompound.setTag("DropChances", nbttaglist1);
|
| 365 | tagCompound.setBoolean("Leashed", this.isLeashed);
|
| 366 |
|
| 367 | if (this.leashedToEntity != null)
|
| 368 | {
|
| 369 | NBTTagCompound nbttagcompound1 = new NBTTagCompound();
|
| 370 |
|
| 371 | if (this.leashedToEntity instanceof EntityLivingBase)
|
| 372 | {
|
| 373 | nbttagcompound1.setLong("UUIDMost", this.leashedToEntity.getUniqueID().getMostSignificantBits());
|
| 374 | nbttagcompound1.setLong("UUIDLeast", this.leashedToEntity.getUniqueID().getLeastSignificantBits());
|
| 375 | }
|
| 376 | else if (this.leashedToEntity instanceof EntityHanging)
|
| 377 | {
|
| 378 | BlockPos blockpos = ((EntityHanging)this.leashedToEntity).getHangingPosition();
|
| 379 | nbttagcompound1.setInteger("X", blockpos.getX());
|
| 380 | nbttagcompound1.setInteger("Y", blockpos.getY());
|
| 381 | nbttagcompound1.setInteger("Z", blockpos.getZ());
|
| 382 | }
|
| 383 |
|
| 384 | tagCompound.setTag("Leash", nbttagcompound1);
|
| 385 | }
|
| 386 |
|
| 387 | if (this.isAIDisabled())
|
| 388 | {
|
| 389 | tagCompound.setBoolean("NoAI", this.isAIDisabled());
|
| 390 | }
|
| 391 | }
|
| 392 |
|
| 393 | /**
|
| 394 | * (abstract) Protected helper method to read subclass entity data from NBT.
|
| 395 | */
|
| 396 | public void readEntityFromNBT(NBTTagCompound tagCompund)
|
| 397 | {
|
| 398 | super.readEntityFromNBT(tagCompund);
|
| 399 |
|
| 400 | if (tagCompund.hasKey("CanPickUpLoot", 1))
|
| 401 | {
|
| 402 | this.setCanPickUpLoot(tagCompund.getBoolean("CanPickUpLoot"));
|
| 403 | }
|
| 404 |
|
| 405 | this.persistenceRequired = tagCompund.getBoolean("PersistenceRequired");
|
| 406 |
|
| 407 | if (tagCompund.hasKey("Equipment", 9))
|
| 408 | {
|
| 409 | NBTTagList nbttaglist = tagCompund.getTagList("Equipment", 10);
|
| 410 |
|
| 411 | for (int i = 0; i < this.equipment.length; ++i)
|
| 412 | {
|
| 413 | this.equipment[i] = ItemStack.loadItemStackFromNBT(nbttaglist.getCompoundTagAt(i));
|
| 414 | }
|
| 415 | }
|
| 416 |
|
| 417 | if (tagCompund.hasKey("DropChances", 9))
|
| 418 | {
|
| 419 | NBTTagList nbttaglist1 = tagCompund.getTagList("DropChances", 5);
|
| 420 |
|
| 421 | for (int j = 0; j < nbttaglist1.tagCount(); ++j)
|
| 422 | {
|
| 423 | this.equipmentDropChances[j] = nbttaglist1.getFloatAt(j);
|
| 424 | }
|
| 425 | }
|
| 426 |
|
| 427 | this.isLeashed = tagCompund.getBoolean("Leashed");
|
| 428 |
|
| 429 | if (this.isLeashed && tagCompund.hasKey("Leash", 10))
|
| 430 | {
|
| 431 | this.leashNBTTag = tagCompund.getCompoundTag("Leash");
|
| 432 | }
|
| 433 |
|
| 434 | this.setNoAI(tagCompund.getBoolean("NoAI"));
|
| 435 | }
|
| 436 |
|
| 437 | public void setMoveForward(float p_70657_1_)
|
| 438 | {
|
| 439 | this.moveForward = p_70657_1_;
|
| 440 | }
|
| 441 |
|
| 442 | /**
|
| 443 | * set the movespeed used for the new AI system
|
| 444 | */
|
| 445 | public void setAIMoveSpeed(float speedIn)
|
| 446 | {
|
| 447 | super.setAIMoveSpeed(speedIn);
|
| 448 | this.setMoveForward(speedIn);
|
| 449 | }
|
| 450 |
|
| 451 | /**
|
| 452 | * Called frequently so the entity can update its state every tick as required. For example, zombies and skeletons
|
| 453 | * use this to react to sunlight and start to burn.
|
| 454 | */
|
| 455 | public void onLivingUpdate()
|
| 456 | {
|
| 457 | super.onLivingUpdate();
|
| 458 | this.worldObj.theProfiler.startSection("looting");
|
| 459 |
|
| 460 | if (!this.worldObj.isRemote && this.canPickUpLoot() && !this.dead && this.worldObj.getGameRules().getBoolean("mobGriefing"))
|
| 461 | {
|
| 462 | for (EntityItem entityitem : this.worldObj.getEntitiesWithinAABB(EntityItem.class, this.getEntityBoundingBox().expand(1.0D, 0.0D, 1.0D)))
|
| 463 | {
|
| 464 | if (!entityitem.isDead && entityitem.getEntityItem() != null && !entityitem.cannotPickup())
|
| 465 | {
|
| 466 | this.updateEquipmentIfNeeded(entityitem);
|
| 467 | }
|
| 468 | }
|
| 469 | }
|
| 470 |
|
| 471 | this.worldObj.theProfiler.endSection();
|
| 472 | }
|
| 473 |
|
| 474 | /**
|
| 475 | * Tests if this entity should pickup a weapon or an armor. Entity drops current weapon or armor if the new one is
|
| 476 | * better.
|
| 477 | */
|
| 478 | protected void updateEquipmentIfNeeded(EntityItem itemEntity)
|
| 479 | {
|
| 480 | ItemStack itemstack = itemEntity.getEntityItem();
|
| 481 | int i = getArmorPosition(itemstack);
|
| 482 |
|
| 483 | if (i > -1)
|
| 484 | {
|
| 485 | boolean flag = true;
|
| 486 | ItemStack itemstack1 = this.getEquipmentInSlot(i);
|
| 487 |
|
| 488 | if (itemstack1 != null)
|
| 489 | {
|
| 490 | if (i == 0)
|
| 491 | {
|
| 492 | if (itemstack.getItem() instanceof ItemSword && !(itemstack1.getItem() instanceof ItemSword))
|
| 493 | {
|
| 494 | flag = true;
|
| 495 | }
|
| 496 | else if (itemstack.getItem() instanceof ItemSword && itemstack1.getItem() instanceof ItemSword)
|
| 497 | {
|
| 498 | ItemSword itemsword = (ItemSword)itemstack.getItem();
|
| 499 | ItemSword itemsword1 = (ItemSword)itemstack1.getItem();
|
| 500 |
|
| 501 | if (itemsword.getDamageVsEntity() != itemsword1.getDamageVsEntity())
|
| 502 | {
|
| 503 | flag = itemsword.getDamageVsEntity() > itemsword1.getDamageVsEntity();
|
| 504 | }
|
| 505 | else
|
| 506 | {
|
| 507 | flag = itemstack.getMetadata() > itemstack1.getMetadata() || itemstack.hasTagCompound() && !itemstack1.hasTagCompound();
|
| 508 | }
|
| 509 | }
|
| 510 | else if (itemstack.getItem() instanceof ItemBow && itemstack1.getItem() instanceof ItemBow)
|
| 511 | {
|
| 512 | flag = itemstack.hasTagCompound() && !itemstack1.hasTagCompound();
|
| 513 | }
|
| 514 | else
|
| 515 | {
|
| 516 | flag = false;
|
| 517 | }
|
| 518 | }
|
| 519 | else if (itemstack.getItem() instanceof ItemArmor && !(itemstack1.getItem() instanceof ItemArmor))
|
| 520 | {
|
| 521 | flag = true;
|
| 522 | }
|
| 523 | else if (itemstack.getItem() instanceof ItemArmor && itemstack1.getItem() instanceof ItemArmor)
|
| 524 | {
|
| 525 | ItemArmor itemarmor = (ItemArmor)itemstack.getItem();
|
| 526 | ItemArmor itemarmor1 = (ItemArmor)itemstack1.getItem();
|
| 527 |
|
| 528 | if (itemarmor.damageReduceAmount != itemarmor1.damageReduceAmount)
|
| 529 | {
|
| 530 | flag = itemarmor.damageReduceAmount > itemarmor1.damageReduceAmount;
|
| 531 | }
|
| 532 | else
|
| 533 | {
|
| 534 | flag = itemstack.getMetadata() > itemstack1.getMetadata() || itemstack.hasTagCompound() && !itemstack1.hasTagCompound();
|
| 535 | }
|
| 536 | }
|
| 537 | else
|
| 538 | {
|
| 539 | flag = false;
|
| 540 | }
|
| 541 | }
|
| 542 |
|
| 543 | if (flag && this.func_175448_a(itemstack))
|
| 544 | {
|
| 545 | if (itemstack1 != null && this.rand.nextFloat() - 0.1F < this.equipmentDropChances[i])
|
| 546 | {
|
| 547 | this.entityDropItem(itemstack1, 0.0F);
|
| 548 | }
|
| 549 |
|
| 550 | if (itemstack.getItem() == Items.diamond && itemEntity.getThrower() != null)
|
| 551 | {
|
| 552 | EntityPlayer entityplayer = this.worldObj.getPlayerEntityByName(itemEntity.getThrower());
|
| 553 |
|
| 554 | if (entityplayer != null)
|
| 555 | {
|
| 556 | entityplayer.triggerAchievement(AchievementList.diamondsToYou);
|
| 557 | }
|
| 558 | }
|
| 559 |
|
| 560 | this.setCurrentItemOrArmor(i, itemstack);
|
| 561 | this.equipmentDropChances[i] = 2.0F;
|
| 562 | this.persistenceRequired = true;
|
| 563 | this.onItemPickup(itemEntity, 1);
|
| 564 | itemEntity.setDead();
|
| 565 | }
|
| 566 | }
|
| 567 | }
|
| 568 |
|
| 569 | protected boolean func_175448_a(ItemStack stack)
|
| 570 | {
|
| 571 | return true;
|
| 572 | }
|
| 573 |
|
| 574 | /**
|
| 575 | * Determines if an entity can be despawned, used on idle far away entities
|
| 576 | */
|
| 577 | protected boolean canDespawn()
|
| 578 | {
|
| 579 | return true;
|
| 580 | }
|
| 581 |
|
| 582 | /**
|
| 583 | * Makes the entity despawn if requirements are reached
|
| 584 | */
|
| 585 | protected void despawnEntity()
|
| 586 | {
|
| 587 | if (this.persistenceRequired)
|
| 588 | {
|
| 589 | this.entityAge = 0;
|
| 590 | }
|
| 591 | else
|
| 592 | {
|
| 593 | Entity entity = this.worldObj.getClosestPlayerToEntity(this, -1.0D);
|
| 594 |
|
| 595 | if (entity != null)
|
| 596 | {
|
| 597 | double d0 = entity.posX - this.posX;
|
| 598 | double d1 = entity.posY - this.posY;
|
| 599 | double d2 = entity.posZ - this.posZ;
|
| 600 | double d3 = d0 * d0 + d1 * d1 + d2 * d2;
|
| 601 |
|
| 602 | if (this.canDespawn() && d3 > 16384.0D)
|
| 603 | {
|
| 604 | this.setDead();
|
| 605 | }
|
| 606 |
|
| 607 | if (this.entityAge > 600 && this.rand.nextInt(800) == 0 && d3 > 1024.0D && this.canDespawn())
|
| 608 | {
|
| 609 | this.setDead();
|
| 610 | }
|
| 611 | else if (d3 < 1024.0D)
|
| 612 | {
|
| 613 | this.entityAge = 0;
|
| 614 | }
|
| 615 | }
|
| 616 | }
|
| 617 | }
|
| 618 |
|
| 619 | protected final void updateEntityActionState()
|
| 620 | {
|
| 621 | ++this.entityAge;
|
| 622 | this.worldObj.theProfiler.startSection("checkDespawn");
|
| 623 | this.despawnEntity();
|
| 624 | this.worldObj.theProfiler.endSection();
|
| 625 | this.worldObj.theProfiler.startSection("sensing");
|
| 626 | this.senses.clearSensingCache();
|
| 627 | this.worldObj.theProfiler.endSection();
|
| 628 | this.worldObj.theProfiler.startSection("targetSelector");
|
| 629 | this.targetTasks.onUpdateTasks();
|
| 630 | this.worldObj.theProfiler.endSection();
|
| 631 | this.worldObj.theProfiler.startSection("goalSelector");
|
| 632 | this.tasks.onUpdateTasks();
|
| 633 | this.worldObj.theProfiler.endSection();
|
| 634 | this.worldObj.theProfiler.startSection("navigation");
|
| 635 | this.navigator.onUpdateNavigation();
|
| 636 | this.worldObj.theProfiler.endSection();
|
| 637 | this.worldObj.theProfiler.startSection("mob tick");
|
| 638 | this.updateAITasks();
|
| 639 | this.worldObj.theProfiler.endSection();
|
| 640 | this.worldObj.theProfiler.startSection("controls");
|
| 641 | this.worldObj.theProfiler.startSection("move");
|
| 642 | this.moveHelper.onUpdateMoveHelper();
|
| 643 | this.worldObj.theProfiler.endStartSection("look");
|
| 644 | this.lookHelper.onUpdateLook();
|
| 645 | this.worldObj.theProfiler.endStartSection("jump");
|
| 646 | this.jumpHelper.doJump();
|
| 647 | this.worldObj.theProfiler.endSection();
|
| 648 | this.worldObj.theProfiler.endSection();
|
| 649 | }
|
| 650 |
|
| 651 | protected void updateAITasks()
|
| 652 | {
|
| 653 | }
|
| 654 |
|
| 655 | /**
|
| 656 | * The speed it takes to move the entityliving's rotationPitch through the faceEntity method. This is only currently
|
| 657 | * use in wolves.
|
| 658 | */
|
| 659 | public int getVerticalFaceSpeed()
|
| 660 | {
|
| 661 | return 40;
|
| 662 | }
|
| 663 |
|
| 664 | /**
|
| 665 | * Changes pitch and yaw so that the entity calling the function is facing the entity provided as an argument.
|
| 666 | */
|
| 667 | public void faceEntity(Entity entityIn, float p_70625_2_, float p_70625_3_)
|
| 668 | {
|
| 669 | double d0 = entityIn.posX - this.posX;
|
| 670 | double d2 = entityIn.posZ - this.posZ;
|
| 671 | double d1;
|
| 672 |
|
| 673 | if (entityIn instanceof EntityLivingBase)
|
| 674 | {
|
| 675 | EntityLivingBase entitylivingbase = (EntityLivingBase)entityIn;
|
| 676 | d1 = entitylivingbase.posY + (double)entitylivingbase.getEyeHeight() - (this.posY + (double)this.getEyeHeight());
|
| 677 | }
|
| 678 | else
|
| 679 | {
|
| 680 | d1 = (entityIn.getEntityBoundingBox().minY + entityIn.getEntityBoundingBox().maxY) / 2.0D - (this.posY + (double)this.getEyeHeight());
|
| 681 | }
|
| 682 |
|
| 683 | double d3 = (double)MathHelper.sqrt_double(d0 * d0 + d2 * d2);
|
| 684 | float f = (float)(MathHelper.atan2(d2, d0) * 180.0D / Math.PI) - 90.0F;
|
| 685 | float f1 = (float)(-(MathHelper.atan2(d1, d3) * 180.0D / Math.PI));
|
| 686 | this.rotationPitch = this.updateRotation(this.rotationPitch, f1, p_70625_3_);
|
| 687 | this.rotationYaw = this.updateRotation(this.rotationYaw, f, p_70625_2_);
|
| 688 | }
|
| 689 |
|
| 690 | /**
|
| 691 | * Arguments: current rotation, intended rotation, max increment.
|
| 692 | */
|
| 693 | private float updateRotation(float p_70663_1_, float p_70663_2_, float p_70663_3_)
|
| 694 | {
|
| 695 | float f = MathHelper.wrapAngleTo180_float(p_70663_2_ - p_70663_1_);
|
| 696 |
|
| 697 | if (f > p_70663_3_)
|
| 698 | {
|
| 699 | f = p_70663_3_;
|
| 700 | }
|
| 701 |
|
| 702 | if (f < -p_70663_3_)
|
| 703 | {
|
| 704 | f = -p_70663_3_;
|
| 705 | }
|
| 706 |
|
| 707 | return p_70663_1_ + f;
|
| 708 | }
|
| 709 |
|
| 710 | /**
|
| 711 | * Checks if the entity's current position is a valid location to spawn this entity.
|
| 712 | */
|
| 713 | public boolean getCanSpawnHere()
|
| 714 | {
|
| 715 | return true;
|
| 716 | }
|
| 717 |
|
| 718 | /**
|
| 719 | * Checks that the entity is not colliding with any blocks / liquids
|
| 720 | */
|
| 721 | public boolean isNotColliding()
|
| 722 | {
|
| 723 | return this.worldObj.checkNoEntityCollision(this.getEntityBoundingBox(), this) && this.worldObj.getCollidingBoundingBoxes(this, this.getEntityBoundingBox()).isEmpty() && !this.worldObj.isAnyLiquid(this.getEntityBoundingBox());
|
| 724 | }
|
| 725 |
|
| 726 | /**
|
| 727 | * Returns render size modifier
|
| 728 | */
|
| 729 | public float getRenderSizeModifier()
|
| 730 | {
|
| 731 | return 1.0F;
|
| 732 | }
|
| 733 |
|
| 734 | /**
|
| 735 | * Will return how many at most can spawn in a chunk at once.
|
| 736 | */
|
| 737 | public int getMaxSpawnedInChunk()
|
| 738 | {
|
| 739 | return 4;
|
| 740 | }
|
| 741 |
|
| 742 | /**
|
| 743 | * The maximum height from where the entity is alowed to jump (used in pathfinder)
|
| 744 | */
|
| 745 | public int getMaxFallHeight()
|
| 746 | {
|
| 747 | if (this.getAttackTarget() == null)
|
| 748 | {
|
| 749 | return 3;
|
| 750 | }
|
| 751 | else
|
| 752 | {
|
| 753 | int i = (int)(this.getHealth() - this.getMaxHealth() * 0.33F);
|
| 754 | i = i - (3 - this.worldObj.getDifficulty().getDifficultyId()) * 4;
|
| 755 |
|
| 756 | if (i < 0)
|
| 757 | {
|
| 758 | i = 0;
|
| 759 | }
|
| 760 |
|
| 761 | return i + 3;
|
| 762 | }
|
| 763 | }
|
| 764 |
|
| 765 | /**
|
| 766 | * Returns the item that this EntityLiving is holding, if any.
|
| 767 | */
|
| 768 | public ItemStack getHeldItem()
|
| 769 | {
|
| 770 | return this.equipment[0];
|
| 771 | }
|
| 772 |
|
| 773 | /**
|
| 774 | * 0: Tool in Hand; 1-4: Armor
|
| 775 | */
|
| 776 | public ItemStack getEquipmentInSlot(int slotIn)
|
| 777 | {
|
| 778 | return this.equipment[slotIn];
|
| 779 | }
|
| 780 |
|
| 781 | public ItemStack getCurrentArmor(int slotIn)
|
| 782 | {
|
| 783 | return this.equipment[slotIn + 1];
|
| 784 | }
|
| 785 |
|
| 786 | /**
|
| 787 | * Sets the held item, or an armor slot. Slot 0 is held item. Slot 1-4 is armor. Params: Item, slot
|
| 788 | */
|
| 789 | public void setCurrentItemOrArmor(int slotIn, ItemStack stack)
|
| 790 | {
|
| 791 | this.equipment[slotIn] = stack;
|
| 792 | }
|
| 793 |
|
| 794 | /**
|
| 795 | * returns the inventory of this entity (only used in EntityPlayerMP it seems)
|
| 796 | */
|
| 797 | public ItemStack[] getInventory()
|
| 798 | {
|
| 799 | return this.equipment;
|
| 800 | }
|
| 801 |
|
| 802 | /**
|
| 803 | * Drop the equipment for this entity.
|
| 804 | *
|
| 805 | * @param wasRecentlyHit true if this this entity was recently hit by appropriate entity (generally only if player
|
| 806 | * or tameable)
|
| 807 | * @param lootingModifier level of enchanment to be applied to this drop
|
| 808 | */
|
| 809 | protected void dropEquipment(boolean wasRecentlyHit, int lootingModifier)
|
| 810 | {
|
| 811 | for (int i = 0; i < this.getInventory().length; ++i)
|
| 812 | {
|
| 813 | ItemStack itemstack = this.getEquipmentInSlot(i);
|
| 814 | boolean flag = this.equipmentDropChances[i] > 1.0F;
|
| 815 |
|
| 816 | if (itemstack != null && (wasRecentlyHit || flag) && this.rand.nextFloat() - (float)lootingModifier * 0.01F < this.equipmentDropChances[i])
|
| 817 | {
|
| 818 | if (!flag && itemstack.isItemStackDamageable())
|
| 819 | {
|
| 820 | int j = Math.max(itemstack.getMaxDamage() - 25, 1);
|
| 821 | int k = itemstack.getMaxDamage() - this.rand.nextInt(this.rand.nextInt(j) + 1);
|
| 822 |
|
| 823 | if (k > j)
|
| 824 | {
|
| 825 | k = j;
|
| 826 | }
|
| 827 |
|
| 828 | if (k < 1)
|
| 829 | {
|
| 830 | k = 1;
|
| 831 | }
|
| 832 |
|
| 833 | itemstack.setItemDamage(k);
|
| 834 | }
|
| 835 |
|
| 836 | this.entityDropItem(itemstack, 0.0F);
|
| 837 | }
|
| 838 | }
|
| 839 | }
|
| 840 |
|
| 841 | /**
|
| 842 | * Gives armor or weapon for entity based on given DifficultyInstance
|
| 843 | */
|
| 844 | protected void setEquipmentBasedOnDifficulty(DifficultyInstance difficulty)
|
| 845 | {
|
| 846 | if (this.rand.nextFloat() < 0.15F * difficulty.getClampedAdditionalDifficulty())
|
| 847 | {
|
| 848 | int i = this.rand.nextInt(2);
|
| 849 | float f = this.worldObj.getDifficulty() == EnumDifficulty.HARD ? 0.1F : 0.25F;
|
| 850 |
|
| 851 | if (this.rand.nextFloat() < 0.095F)
|
| 852 | {
|
| 853 | ++i;
|
| 854 | }
|
| 855 |
|
| 856 | if (this.rand.nextFloat() < 0.095F)
|
| 857 | {
|
| 858 | ++i;
|
| 859 | }
|
| 860 |
|
| 861 | if (this.rand.nextFloat() < 0.095F)
|
| 862 | {
|
| 863 | ++i;
|
| 864 | }
|
| 865 |
|
| 866 | for (int j = 3; j >= 0; --j)
|
| 867 | {
|
| 868 | ItemStack itemstack = this.getCurrentArmor(j);
|
| 869 |
|
| 870 | if (j < 3 && this.rand.nextFloat() < f)
|
| 871 | {
|
| 872 | break;
|
| 873 | }
|
| 874 |
|
| 875 | if (itemstack == null)
|
| 876 | {
|
| 877 | Item item = getArmorItemForSlot(j + 1, i);
|
| 878 |
|
| 879 | if (item != null)
|
| 880 | {
|
| 881 | this.setCurrentItemOrArmor(j + 1, new ItemStack(item));
|
| 882 | }
|
| 883 | }
|
| 884 | }
|
| 885 | }
|
| 886 | }
|
| 887 |
|
| 888 | public static int getArmorPosition(ItemStack stack)
|
| 889 | {
|
| 890 | if (stack.getItem() != Item.getItemFromBlock(Blocks.pumpkin) && stack.getItem() != Items.skull)
|
| 891 | {
|
| 892 | if (stack.getItem() instanceof ItemArmor)
|
| 893 | {
|
| 894 | switch (((ItemArmor)stack.getItem()).armorType)
|
| 895 | {
|
| 896 | case 0:
|
| 897 | return 4;
|
| 898 |
|
| 899 | case 1:
|
| 900 | return 3;
|
| 901 |
|
| 902 | case 2:
|
| 903 | return 2;
|
| 904 |
|
| 905 | case 3:
|
| 906 | return 1;
|
| 907 | }
|
| 908 | }
|
| 909 |
|
| 910 | return 0;
|
| 911 | }
|
| 912 | else
|
| 913 | {
|
| 914 | return 4;
|
| 915 | }
|
| 916 | }
|
| 917 |
|
| 918 | /**
|
| 919 | * Gets the vanilla armor Item that can go in the slot specified for the given tier.
|
| 920 | */
|
| 921 | public static Item getArmorItemForSlot(int armorSlot, int itemTier)
|
| 922 | {
|
| 923 | switch (armorSlot)
|
| 924 | {
|
| 925 | case 4:
|
| 926 | if (itemTier == 0)
|
| 927 | {
|
| 928 | return Items.leather_helmet;
|
| 929 | }
|
| 930 | else if (itemTier == 1)
|
| 931 | {
|
| 932 | return Items.golden_helmet;
|
| 933 | }
|
| 934 | else if (itemTier == 2)
|
| 935 | {
|
| 936 | return Items.chainmail_helmet;
|
| 937 | }
|
| 938 | else if (itemTier == 3)
|
| 939 | {
|
| 940 | return Items.iron_helmet;
|
| 941 | }
|
| 942 | else if (itemTier == 4)
|
| 943 | {
|
| 944 | return Items.diamond_helmet;
|
| 945 | }
|
| 946 |
|
| 947 | case 3:
|
| 948 | if (itemTier == 0)
|
| 949 | {
|
| 950 | return Items.leather_chestplate;
|
| 951 | }
|
| 952 | else if (itemTier == 1)
|
| 953 | {
|
| 954 | return Items.golden_chestplate;
|
| 955 | }
|
| 956 | else if (itemTier == 2)
|
| 957 | {
|
| 958 | return Items.chainmail_chestplate;
|
| 959 | }
|
| 960 | else if (itemTier == 3)
|
| 961 | {
|
| 962 | return Items.iron_chestplate;
|
| 963 | }
|
| 964 | else if (itemTier == 4)
|
| 965 | {
|
| 966 | return Items.diamond_chestplate;
|
| 967 | }
|
| 968 |
|
| 969 | case 2:
|
| 970 | if (itemTier == 0)
|
| 971 | {
|
| 972 | return Items.leather_leggings;
|
| 973 | }
|
| 974 | else if (itemTier == 1)
|
| 975 | {
|
| 976 | return Items.golden_leggings;
|
| 977 | }
|
| 978 | else if (itemTier == 2)
|
| 979 | {
|
| 980 | return Items.chainmail_leggings;
|
| 981 | }
|
| 982 | else if (itemTier == 3)
|
| 983 | {
|
| 984 | return Items.iron_leggings;
|
| 985 | }
|
| 986 | else if (itemTier == 4)
|
| 987 | {
|
| 988 | return Items.diamond_leggings;
|
| 989 | }
|
| 990 |
|
| 991 | case 1:
|
| 992 | if (itemTier == 0)
|
| 993 | {
|
| 994 | return Items.leather_boots;
|
| 995 | }
|
| 996 | else if (itemTier == 1)
|
| 997 | {
|
| 998 | return Items.golden_boots;
|
| 999 | }
|
| 1000 | else if (itemTier == 2)
|
| 1001 | {
|
| 1002 | return Items.chainmail_boots;
|
| 1003 | }
|
| 1004 | else if (itemTier == 3)
|
| 1005 | {
|
| 1006 | return Items.iron_boots;
|
| 1007 | }
|
| 1008 | else if (itemTier == 4)
|
| 1009 | {
|
| 1010 | return Items.diamond_boots;
|
| 1011 | }
|
| 1012 |
|
| 1013 | default:
|
| 1014 | return null;
|
| 1015 | }
|
| 1016 | }
|
| 1017 |
|
| 1018 | /**
|
| 1019 | * Enchants Entity's current equipments based on given DifficultyInstance
|
| 1020 | */
|
| 1021 | protected void setEnchantmentBasedOnDifficulty(DifficultyInstance difficulty)
|
| 1022 | {
|
| 1023 | float f = difficulty.getClampedAdditionalDifficulty();
|
| 1024 |
|
| 1025 | if (this.getHeldItem() != null && this.rand.nextFloat() < 0.25F * f)
|
| 1026 | {
|
| 1027 | EnchantmentHelper.addRandomEnchantment(this.rand, this.getHeldItem(), (int)(5.0F + f * (float)this.rand.nextInt(18)));
|
| 1028 | }
|
| 1029 |
|
| 1030 | for (int i = 0; i < 4; ++i)
|
| 1031 | {
|
| 1032 | ItemStack itemstack = this.getCurrentArmor(i);
|
| 1033 |
|
| 1034 | if (itemstack != null && this.rand.nextFloat() < 0.5F * f)
|
| 1035 | {
|
| 1036 | EnchantmentHelper.addRandomEnchantment(this.rand, itemstack, (int)(5.0F + f * (float)this.rand.nextInt(18)));
|
| 1037 | }
|
| 1038 | }
|
| 1039 | }
|
| 1040 |
|
| 1041 | /**
|
| 1042 | * Called only once on an entity when first time spawned, via egg, mob spawner, natural spawning etc, but not called
|
| 1043 | * when entity is reloaded from nbt. Mainly used for initializing attributes and inventory
|
| 1044 | */
|
| 1045 | public IEntityLivingData onInitialSpawn(DifficultyInstance difficulty, IEntityLivingData livingdata)
|
| 1046 | {
|
| 1047 | this.getEntityAttribute(SharedMonsterAttributes.followRange).applyModifier(new AttributeModifier("Random spawn bonus", this.rand.nextGaussian() * 0.05D, 1));
|
| 1048 | return livingdata;
|
| 1049 | }
|
| 1050 |
|
| 1051 | /**
|
| 1052 | * returns true if all the conditions for steering the entity are met. For pigs, this is true if it is being ridden
|
| 1053 | * by a player and the player is holding a carrot-on-a-stick
|
| 1054 | */
|
| 1055 | public boolean canBeSteered()
|
| 1056 | {
|
| 1057 | return false;
|
| 1058 | }
|
| 1059 |
|
| 1060 | /**
|
| 1061 | * Enable the Entity persistence
|
| 1062 | */
|
| 1063 | public void enablePersistence()
|
| 1064 | {
|
| 1065 | this.persistenceRequired = true;
|
| 1066 | }
|
| 1067 |
|
| 1068 | public void setEquipmentDropChance(int slotIn, float chance)
|
| 1069 | {
|
| 1070 | this.equipmentDropChances[slotIn] = chance;
|
| 1071 | }
|
| 1072 |
|
| 1073 | public boolean canPickUpLoot()
|
| 1074 | {
|
| 1075 | return this.canPickUpLoot;
|
| 1076 | }
|
| 1077 |
|
| 1078 | public void setCanPickUpLoot(boolean canPickup)
|
| 1079 | {
|
| 1080 | this.canPickUpLoot = canPickup;
|
| 1081 | }
|
| 1082 |
|
| 1083 | public boolean isNoDespawnRequired()
|
| 1084 | {
|
| 1085 | return this.persistenceRequired;
|
| 1086 | }
|
| 1087 |
|
| 1088 | /**
|
| 1089 | * First layer of player interaction
|
| 1090 | */
|
| 1091 | public final boolean interactFirst(EntityPlayer playerIn)
|
| 1092 | {
|
| 1093 | if (this.getLeashed() && this.getLeashedToEntity() == playerIn)
|
| 1094 | {
|
| 1095 | this.clearLeashed(true, !playerIn.capabilities.isCreativeMode);
|
| 1096 | return true;
|
| 1097 | }
|
| 1098 | else
|
| 1099 | {
|
| 1100 | ItemStack itemstack = playerIn.inventory.getCurrentItem();
|
| 1101 |
|
| 1102 | if (itemstack != null && itemstack.getItem() == Items.lead && this.allowLeashing())
|
| 1103 | {
|
| 1104 | if (!(this instanceof EntityTameable) || !((EntityTameable)this).isTamed())
|
| 1105 | {
|
| 1106 | this.setLeashedToEntity(playerIn, true);
|
| 1107 | --itemstack.stackSize;
|
| 1108 | return true;
|
| 1109 | }
|
| 1110 |
|
| 1111 | if (((EntityTameable)this).isOwner(playerIn))
|
| 1112 | {
|
| 1113 | this.setLeashedToEntity(playerIn, true);
|
| 1114 | --itemstack.stackSize;
|
| 1115 | return true;
|
| 1116 | }
|
| 1117 | }
|
| 1118 |
|
| 1119 | if (this.interact(playerIn))
|
| 1120 | {
|
| 1121 | return true;
|
| 1122 | }
|
| 1123 | else
|
| 1124 | {
|
| 1125 | return super.interactFirst(playerIn);
|
| 1126 | }
|
| 1127 | }
|
| 1128 | }
|
| 1129 |
|
| 1130 | /**
|
| 1131 | * Called when a player interacts with a mob. e.g. gets milk from a cow, gets into the saddle on a pig.
|
| 1132 | */
|
| 1133 | protected boolean interact(EntityPlayer player)
|
| 1134 | {
|
| 1135 | return false;
|
| 1136 | }
|
| 1137 |
|
| 1138 | /**
|
| 1139 | * Applies logic related to leashes, for example dragging the entity or breaking the leash.
|
| 1140 | */
|
| 1141 | protected void updateLeashedState()
|
| 1142 | {
|
| 1143 | if (this.leashNBTTag != null)
|
| 1144 | {
|
| 1145 | this.recreateLeash();
|
| 1146 | }
|
| 1147 |
|
| 1148 | if (this.isLeashed)
|
| 1149 | {
|
| 1150 | if (!this.isEntityAlive())
|
| 1151 | {
|
| 1152 | this.clearLeashed(true, true);
|
| 1153 | }
|
| 1154 |
|
| 1155 | if (this.leashedToEntity == null || this.leashedToEntity.isDead)
|
| 1156 | {
|
| 1157 | this.clearLeashed(true, true);
|
| 1158 | }
|
| 1159 | }
|
| 1160 | }
|
| 1161 |
|
| 1162 | /**
|
| 1163 | * Removes the leash from this entity
|
| 1164 | */
|
| 1165 | public void clearLeashed(boolean sendPacket, boolean dropLead)
|
| 1166 | {
|
| 1167 | if (this.isLeashed)
|
| 1168 | {
|
| 1169 | this.isLeashed = false;
|
| 1170 | this.leashedToEntity = null;
|
| 1171 |
|
| 1172 | if (!this.worldObj.isRemote && dropLead)
|
| 1173 | {
|
| 1174 | this.dropItem(Items.lead, 1);
|
| 1175 | }
|
| 1176 |
|
| 1177 | if (!this.worldObj.isRemote && sendPacket && this.worldObj instanceof WorldServer)
|
| 1178 | {
|
| 1179 | ((WorldServer)this.worldObj).getEntityTracker().sendToAllTrackingEntity(this, new S1BPacketEntityAttach(1, this, (Entity)null));
|
| 1180 | }
|
| 1181 | }
|
| 1182 | }
|
| 1183 |
|
| 1184 | public boolean allowLeashing()
|
| 1185 | {
|
| 1186 | return !this.getLeashed() && !(this instanceof IMob);
|
| 1187 | }
|
| 1188 |
|
| 1189 | public boolean getLeashed()
|
| 1190 | {
|
| 1191 | return this.isLeashed;
|
| 1192 | }
|
| 1193 |
|
| 1194 | public Entity getLeashedToEntity()
|
| 1195 | {
|
| 1196 | return this.leashedToEntity;
|
| 1197 | }
|
| 1198 |
|
| 1199 | /**
|
| 1200 | * Sets the entity to be leashed to.
|
| 1201 | */
|
| 1202 | public void setLeashedToEntity(Entity entityIn, boolean sendAttachNotification)
|
| 1203 | {
|
| 1204 | this.isLeashed = true;
|
| 1205 | this.leashedToEntity = entityIn;
|
| 1206 |
|
| 1207 | if (!this.worldObj.isRemote && sendAttachNotification && this.worldObj instanceof WorldServer)
|
| 1208 | {
|
| 1209 | ((WorldServer)this.worldObj).getEntityTracker().sendToAllTrackingEntity(this, new S1BPacketEntityAttach(1, this, this.leashedToEntity));
|
| 1210 | }
|
| 1211 | }
|
| 1212 |
|
| 1213 | private void recreateLeash()
|
| 1214 | {
|
| 1215 | if (this.isLeashed && this.leashNBTTag != null)
|
| 1216 | {
|
| 1217 | if (this.leashNBTTag.hasKey("UUIDMost", 4) && this.leashNBTTag.hasKey("UUIDLeast", 4))
|
| 1218 | {
|
| 1219 | UUID uuid = new UUID(this.leashNBTTag.getLong("UUIDMost"), this.leashNBTTag.getLong("UUIDLeast"));
|
| 1220 |
|
| 1221 | for (EntityLivingBase entitylivingbase : this.worldObj.getEntitiesWithinAABB(EntityLivingBase.class, this.getEntityBoundingBox().expand(10.0D, 10.0D, 10.0D)))
|
| 1222 | {
|
| 1223 | if (entitylivingbase.getUniqueID().equals(uuid))
|
| 1224 | {
|
| 1225 | this.leashedToEntity = entitylivingbase;
|
| 1226 | break;
|
| 1227 | }
|
| 1228 | }
|
| 1229 | }
|
| 1230 | else if (this.leashNBTTag.hasKey("X", 99) && this.leashNBTTag.hasKey("Y", 99) && this.leashNBTTag.hasKey("Z", 99))
|
| 1231 | {
|
| 1232 | BlockPos blockpos = new BlockPos(this.leashNBTTag.getInteger("X"), this.leashNBTTag.getInteger("Y"), this.leashNBTTag.getInteger("Z"));
|
| 1233 | EntityLeashKnot entityleashknot = EntityLeashKnot.getKnotForPosition(this.worldObj, blockpos);
|
| 1234 |
|
| 1235 | if (entityleashknot == null)
|
| 1236 | {
|
| 1237 | entityleashknot = EntityLeashKnot.createKnot(this.worldObj, blockpos);
|
| 1238 | }
|
| 1239 |
|
| 1240 | this.leashedToEntity = entityleashknot;
|
| 1241 | }
|
| 1242 | else
|
| 1243 | {
|
| 1244 | this.clearLeashed(false, true);
|
| 1245 | }
|
| 1246 | }
|
| 1247 |
|
| 1248 | this.leashNBTTag = null;
|
| 1249 | }
|
| 1250 |
|
| 1251 | public boolean replaceItemInInventory(int inventorySlot, ItemStack itemStackIn)
|
| 1252 | {
|
| 1253 | int i;
|
| 1254 |
|
| 1255 | if (inventorySlot == 99)
|
| 1256 | {
|
| 1257 | i = 0;
|
| 1258 | }
|
| 1259 | else
|
| 1260 | {
|
| 1261 | i = inventorySlot - 100 + 1;
|
| 1262 |
|
| 1263 | if (i < 0 || i >= this.equipment.length)
|
| 1264 | {
|
| 1265 | return false;
|
| 1266 | }
|
| 1267 | }
|
| 1268 |
|
| 1269 | if (itemStackIn != null && getArmorPosition(itemStackIn) != i && (i != 4 || !(itemStackIn.getItem() instanceof ItemBlock)))
|
| 1270 | {
|
| 1271 | return false;
|
| 1272 | }
|
| 1273 | else
|
| 1274 | {
|
| 1275 | this.setCurrentItemOrArmor(i, itemStackIn);
|
| 1276 | return true;
|
| 1277 | }
|
| 1278 | }
|
| 1279 |
|
| 1280 | /**
|
| 1281 | * Returns whether the entity is in a server world
|
| 1282 | */
|
| 1283 | public boolean isServerWorld()
|
| 1284 | {
|
| 1285 | return super.isServerWorld() && !this.isAIDisabled();
|
| 1286 | }
|
| 1287 |
|
| 1288 | /**
|
| 1289 | * Set whether this Entity's AI is disabled
|
| 1290 | */
|
| 1291 | public void setNoAI(boolean disable)
|
| 1292 | {
|
| 1293 | this.dataWatcher.updateObject(15, Byte.valueOf((byte)(disable ? 1 : 0)));
|
| 1294 | }
|
| 1295 |
|
| 1296 | /**
|
| 1297 | * Get whether this Entity's AI is disabled
|
| 1298 | */
|
| 1299 | public boolean isAIDisabled()
|
| 1300 | {
|
| 1301 | return this.dataWatcher.getWatchableObjectByte(15) != 0;
|
| 1302 | }
|
| 1303 |
|
| 1304 | public static enum SpawnPlacementType
|
| 1305 | {
|
| 1306 | ON_GROUND,
|
| 1307 | IN_AIR,
|
| 1308 | IN_WATER;
|
| 1309 | }
|
| 1310 | }
|
| 1311 |
|