| 1 | package net.minecraft.entity.item;
|
| 2 |
|
| 3 | import java.util.List;
|
| 4 | import net.minecraft.block.Block;
|
| 5 | import net.minecraft.entity.Entity;
|
| 6 | import net.minecraft.entity.EntityLiving;
|
| 7 | import net.minecraft.entity.EntityLivingBase;
|
| 8 | import net.minecraft.entity.player.EntityPlayer;
|
| 9 | import net.minecraft.entity.projectile.EntityArrow;
|
| 10 | import net.minecraft.init.Blocks;
|
| 11 | import net.minecraft.init.Items;
|
| 12 | import net.minecraft.item.Item;
|
| 13 | import net.minecraft.item.ItemArmor;
|
| 14 | import net.minecraft.item.ItemBlock;
|
| 15 | import net.minecraft.item.ItemStack;
|
| 16 | import net.minecraft.nbt.NBTTagCompound;
|
| 17 | import net.minecraft.nbt.NBTTagList;
|
| 18 | import net.minecraft.util.BlockPos;
|
| 19 | import net.minecraft.util.DamageSource;
|
| 20 | import net.minecraft.util.EnumParticleTypes;
|
| 21 | import net.minecraft.util.Rotations;
|
| 22 | import net.minecraft.util.Vec3;
|
| 23 | import net.minecraft.world.World;
|
| 24 | import net.minecraft.world.WorldServer;
|
| 25 |
|
| 26 | public class EntityArmorStand extends EntityLivingBase
|
| 27 | {
|
| 28 | private static final Rotations DEFAULT_HEAD_ROTATION = new Rotations(0.0F, 0.0F, 0.0F);
|
| 29 | private static final Rotations DEFAULT_BODY_ROTATION = new Rotations(0.0F, 0.0F, 0.0F);
|
| 30 | private static final Rotations DEFAULT_LEFTARM_ROTATION = new Rotations(-10.0F, 0.0F, -10.0F);
|
| 31 | private static final Rotations DEFAULT_RIGHTARM_ROTATION = new Rotations(-15.0F, 0.0F, 10.0F);
|
| 32 | private static final Rotations DEFAULT_LEFTLEG_ROTATION = new Rotations(-1.0F, 0.0F, -1.0F);
|
| 33 | private static final Rotations DEFAULT_RIGHTLEG_ROTATION = new Rotations(1.0F, 0.0F, 1.0F);
|
| 34 | private final ItemStack[] contents;
|
| 35 | private boolean canInteract;
|
| 36 |
|
| 37 | /**
|
| 38 | * After punching the stand, the cooldown before you can punch it again without breaking it.
|
| 39 | */
|
| 40 | private long punchCooldown;
|
| 41 | private int disabledSlots;
|
| 42 | private boolean field_181028_bj;
|
| 43 | private Rotations headRotation;
|
| 44 | private Rotations bodyRotation;
|
| 45 | private Rotations leftArmRotation;
|
| 46 | private Rotations rightArmRotation;
|
| 47 | private Rotations leftLegRotation;
|
| 48 | private Rotations rightLegRotation;
|
| 49 |
|
| 50 | public EntityArmorStand(World worldIn)
|
| 51 | {
|
| 52 | super(worldIn);
|
| 53 | this.contents = new ItemStack[5];
|
| 54 | this.headRotation = DEFAULT_HEAD_ROTATION;
|
| 55 | this.bodyRotation = DEFAULT_BODY_ROTATION;
|
| 56 | this.leftArmRotation = DEFAULT_LEFTARM_ROTATION;
|
| 57 | this.rightArmRotation = DEFAULT_RIGHTARM_ROTATION;
|
| 58 | this.leftLegRotation = DEFAULT_LEFTLEG_ROTATION;
|
| 59 | this.rightLegRotation = DEFAULT_RIGHTLEG_ROTATION;
|
| 60 | this.setSilent(true);
|
| 61 | this.noClip = this.hasNoGravity();
|
| 62 | this.setSize(0.5F, 1.975F);
|
| 63 | }
|
| 64 |
|
| 65 | public EntityArmorStand(World worldIn, double posX, double posY, double posZ)
|
| 66 | {
|
| 67 | this(worldIn);
|
| 68 | this.setPosition(posX, posY, posZ);
|
| 69 | }
|
| 70 |
|
| 71 | /**
|
| 72 | * Returns whether the entity is in a server world
|
| 73 | */
|
| 74 | public boolean isServerWorld()
|
| 75 | {
|
| 76 | return super.isServerWorld() && !this.hasNoGravity();
|
| 77 | }
|
| 78 |
|
| 79 | protected void entityInit()
|
| 80 | {
|
| 81 | super.entityInit();
|
| 82 | this.dataWatcher.addObject(10, Byte.valueOf((byte)0));
|
| 83 | this.dataWatcher.addObject(11, DEFAULT_HEAD_ROTATION);
|
| 84 | this.dataWatcher.addObject(12, DEFAULT_BODY_ROTATION);
|
| 85 | this.dataWatcher.addObject(13, DEFAULT_LEFTARM_ROTATION);
|
| 86 | this.dataWatcher.addObject(14, DEFAULT_RIGHTARM_ROTATION);
|
| 87 | this.dataWatcher.addObject(15, DEFAULT_LEFTLEG_ROTATION);
|
| 88 | this.dataWatcher.addObject(16, DEFAULT_RIGHTLEG_ROTATION);
|
| 89 | }
|
| 90 |
|
| 91 | /**
|
| 92 | * Returns the item that this EntityLiving is holding, if any.
|
| 93 | */
|
| 94 | public ItemStack getHeldItem()
|
| 95 | {
|
| 96 | return this.contents[0];
|
| 97 | }
|
| 98 |
|
| 99 | /**
|
| 100 | * 0: Tool in Hand; 1-4: Armor
|
| 101 | */
|
| 102 | public ItemStack getEquipmentInSlot(int slotIn)
|
| 103 | {
|
| 104 | return this.contents[slotIn];
|
| 105 | }
|
| 106 |
|
| 107 | public ItemStack getCurrentArmor(int slotIn)
|
| 108 | {
|
| 109 | return this.contents[slotIn + 1];
|
| 110 | }
|
| 111 |
|
| 112 | /**
|
| 113 | * Sets the held item, or an armor slot. Slot 0 is held item. Slot 1-4 is armor. Params: Item, slot
|
| 114 | */
|
| 115 | public void setCurrentItemOrArmor(int slotIn, ItemStack stack)
|
| 116 | {
|
| 117 | this.contents[slotIn] = stack;
|
| 118 | }
|
| 119 |
|
| 120 | /**
|
| 121 | * returns the inventory of this entity (only used in EntityPlayerMP it seems)
|
| 122 | */
|
| 123 | public ItemStack[] getInventory()
|
| 124 | {
|
| 125 | return this.contents;
|
| 126 | }
|
| 127 |
|
| 128 | public boolean replaceItemInInventory(int inventorySlot, ItemStack itemStackIn)
|
| 129 | {
|
| 130 | int i;
|
| 131 |
|
| 132 | if (inventorySlot == 99)
|
| 133 | {
|
| 134 | i = 0;
|
| 135 | }
|
| 136 | else
|
| 137 | {
|
| 138 | i = inventorySlot - 100 + 1;
|
| 139 |
|
| 140 | if (i < 0 || i >= this.contents.length)
|
| 141 | {
|
| 142 | return false;
|
| 143 | }
|
| 144 | }
|
| 145 |
|
| 146 | if (itemStackIn != null && EntityLiving.getArmorPosition(itemStackIn) != i && (i != 4 || !(itemStackIn.getItem() instanceof ItemBlock)))
|
| 147 | {
|
| 148 | return false;
|
| 149 | }
|
| 150 | else
|
| 151 | {
|
| 152 | this.setCurrentItemOrArmor(i, itemStackIn);
|
| 153 | return true;
|
| 154 | }
|
| 155 | }
|
| 156 |
|
| 157 | /**
|
| 158 | * (abstract) Protected helper method to write subclass entity data to NBT.
|
| 159 | */
|
| 160 | public void writeEntityToNBT(NBTTagCompound tagCompound)
|
| 161 | {
|
| 162 | super.writeEntityToNBT(tagCompound);
|
| 163 | NBTTagList nbttaglist = new NBTTagList();
|
| 164 |
|
| 165 | for (int i = 0; i < this.contents.length; ++i)
|
| 166 | {
|
| 167 | NBTTagCompound nbttagcompound = new NBTTagCompound();
|
| 168 |
|
| 169 | if (this.contents[i] != null)
|
| 170 | {
|
| 171 | this.contents[i].writeToNBT(nbttagcompound);
|
| 172 | }
|
| 173 |
|
| 174 | nbttaglist.appendTag(nbttagcompound);
|
| 175 | }
|
| 176 |
|
| 177 | tagCompound.setTag("Equipment", nbttaglist);
|
| 178 |
|
| 179 | if (this.getAlwaysRenderNameTag() && (this.getCustomNameTag() == null || this.getCustomNameTag().length() == 0))
|
| 180 | {
|
| 181 | tagCompound.setBoolean("CustomNameVisible", this.getAlwaysRenderNameTag());
|
| 182 | }
|
| 183 |
|
| 184 | tagCompound.setBoolean("Invisible", this.isInvisible());
|
| 185 | tagCompound.setBoolean("Small", this.isSmall());
|
| 186 | tagCompound.setBoolean("ShowArms", this.getShowArms());
|
| 187 | tagCompound.setInteger("DisabledSlots", this.disabledSlots);
|
| 188 | tagCompound.setBoolean("NoGravity", this.hasNoGravity());
|
| 189 | tagCompound.setBoolean("NoBasePlate", this.hasNoBasePlate());
|
| 190 |
|
| 191 | if (this.hasMarker())
|
| 192 | {
|
| 193 | tagCompound.setBoolean("Marker", this.hasMarker());
|
| 194 | }
|
| 195 |
|
| 196 | tagCompound.setTag("Pose", this.readPoseFromNBT());
|
| 197 | }
|
| 198 |
|
| 199 | /**
|
| 200 | * (abstract) Protected helper method to read subclass entity data from NBT.
|
| 201 | */
|
| 202 | public void readEntityFromNBT(NBTTagCompound tagCompund)
|
| 203 | {
|
| 204 | super.readEntityFromNBT(tagCompund);
|
| 205 |
|
| 206 | if (tagCompund.hasKey("Equipment", 9))
|
| 207 | {
|
| 208 | NBTTagList nbttaglist = tagCompund.getTagList("Equipment", 10);
|
| 209 |
|
| 210 | for (int i = 0; i < this.contents.length; ++i)
|
| 211 | {
|
| 212 | this.contents[i] = ItemStack.loadItemStackFromNBT(nbttaglist.getCompoundTagAt(i));
|
| 213 | }
|
| 214 | }
|
| 215 |
|
| 216 | this.setInvisible(tagCompund.getBoolean("Invisible"));
|
| 217 | this.setSmall(tagCompund.getBoolean("Small"));
|
| 218 | this.setShowArms(tagCompund.getBoolean("ShowArms"));
|
| 219 | this.disabledSlots = tagCompund.getInteger("DisabledSlots");
|
| 220 | this.setNoGravity(tagCompund.getBoolean("NoGravity"));
|
| 221 | this.setNoBasePlate(tagCompund.getBoolean("NoBasePlate"));
|
| 222 | this.setMarker(tagCompund.getBoolean("Marker"));
|
| 223 | this.field_181028_bj = !this.hasMarker();
|
| 224 | this.noClip = this.hasNoGravity();
|
| 225 | NBTTagCompound nbttagcompound = tagCompund.getCompoundTag("Pose");
|
| 226 | this.writePoseToNBT(nbttagcompound);
|
| 227 | }
|
| 228 |
|
| 229 | /**
|
| 230 | * Saves the pose to an NBTTagCompound.
|
| 231 | */
|
| 232 | private void writePoseToNBT(NBTTagCompound tagCompound)
|
| 233 | {
|
| 234 | NBTTagList nbttaglist = tagCompound.getTagList("Head", 5);
|
| 235 |
|
| 236 | if (nbttaglist.tagCount() > 0)
|
| 237 | {
|
| 238 | this.setHeadRotation(new Rotations(nbttaglist));
|
| 239 | }
|
| 240 | else
|
| 241 | {
|
| 242 | this.setHeadRotation(DEFAULT_HEAD_ROTATION);
|
| 243 | }
|
| 244 |
|
| 245 | NBTTagList nbttaglist1 = tagCompound.getTagList("Body", 5);
|
| 246 |
|
| 247 | if (nbttaglist1.tagCount() > 0)
|
| 248 | {
|
| 249 | this.setBodyRotation(new Rotations(nbttaglist1));
|
| 250 | }
|
| 251 | else
|
| 252 | {
|
| 253 | this.setBodyRotation(DEFAULT_BODY_ROTATION);
|
| 254 | }
|
| 255 |
|
| 256 | NBTTagList nbttaglist2 = tagCompound.getTagList("LeftArm", 5);
|
| 257 |
|
| 258 | if (nbttaglist2.tagCount() > 0)
|
| 259 | {
|
| 260 | this.setLeftArmRotation(new Rotations(nbttaglist2));
|
| 261 | }
|
| 262 | else
|
| 263 | {
|
| 264 | this.setLeftArmRotation(DEFAULT_LEFTARM_ROTATION);
|
| 265 | }
|
| 266 |
|
| 267 | NBTTagList nbttaglist3 = tagCompound.getTagList("RightArm", 5);
|
| 268 |
|
| 269 | if (nbttaglist3.tagCount() > 0)
|
| 270 | {
|
| 271 | this.setRightArmRotation(new Rotations(nbttaglist3));
|
| 272 | }
|
| 273 | else
|
| 274 | {
|
| 275 | this.setRightArmRotation(DEFAULT_RIGHTARM_ROTATION);
|
| 276 | }
|
| 277 |
|
| 278 | NBTTagList nbttaglist4 = tagCompound.getTagList("LeftLeg", 5);
|
| 279 |
|
| 280 | if (nbttaglist4.tagCount() > 0)
|
| 281 | {
|
| 282 | this.setLeftLegRotation(new Rotations(nbttaglist4));
|
| 283 | }
|
| 284 | else
|
| 285 | {
|
| 286 | this.setLeftLegRotation(DEFAULT_LEFTLEG_ROTATION);
|
| 287 | }
|
| 288 |
|
| 289 | NBTTagList nbttaglist5 = tagCompound.getTagList("RightLeg", 5);
|
| 290 |
|
| 291 | if (nbttaglist5.tagCount() > 0)
|
| 292 | {
|
| 293 | this.setRightLegRotation(new Rotations(nbttaglist5));
|
| 294 | }
|
| 295 | else
|
| 296 | {
|
| 297 | this.setRightLegRotation(DEFAULT_RIGHTLEG_ROTATION);
|
| 298 | }
|
| 299 | }
|
| 300 |
|
| 301 | private NBTTagCompound readPoseFromNBT()
|
| 302 | {
|
| 303 | NBTTagCompound nbttagcompound = new NBTTagCompound();
|
| 304 |
|
| 305 | if (!DEFAULT_HEAD_ROTATION.equals(this.headRotation))
|
| 306 | {
|
| 307 | nbttagcompound.setTag("Head", this.headRotation.writeToNBT());
|
| 308 | }
|
| 309 |
|
| 310 | if (!DEFAULT_BODY_ROTATION.equals(this.bodyRotation))
|
| 311 | {
|
| 312 | nbttagcompound.setTag("Body", this.bodyRotation.writeToNBT());
|
| 313 | }
|
| 314 |
|
| 315 | if (!DEFAULT_LEFTARM_ROTATION.equals(this.leftArmRotation))
|
| 316 | {
|
| 317 | nbttagcompound.setTag("LeftArm", this.leftArmRotation.writeToNBT());
|
| 318 | }
|
| 319 |
|
| 320 | if (!DEFAULT_RIGHTARM_ROTATION.equals(this.rightArmRotation))
|
| 321 | {
|
| 322 | nbttagcompound.setTag("RightArm", this.rightArmRotation.writeToNBT());
|
| 323 | }
|
| 324 |
|
| 325 | if (!DEFAULT_LEFTLEG_ROTATION.equals(this.leftLegRotation))
|
| 326 | {
|
| 327 | nbttagcompound.setTag("LeftLeg", this.leftLegRotation.writeToNBT());
|
| 328 | }
|
| 329 |
|
| 330 | if (!DEFAULT_RIGHTLEG_ROTATION.equals(this.rightLegRotation))
|
| 331 | {
|
| 332 | nbttagcompound.setTag("RightLeg", this.rightLegRotation.writeToNBT());
|
| 333 | }
|
| 334 |
|
| 335 | return nbttagcompound;
|
| 336 | }
|
| 337 |
|
| 338 | /**
|
| 339 | * Returns true if this entity should push and be pushed by other entities when colliding.
|
| 340 | */
|
| 341 | public boolean canBePushed()
|
| 342 | {
|
| 343 | return false;
|
| 344 | }
|
| 345 |
|
| 346 | protected void collideWithEntity(Entity entityIn)
|
| 347 | {
|
| 348 | }
|
| 349 |
|
| 350 | protected void collideWithNearbyEntities()
|
| 351 | {
|
| 352 | List<Entity> list = this.worldObj.getEntitiesWithinAABBExcludingEntity(this, this.getEntityBoundingBox());
|
| 353 |
|
| 354 | if (list != null && !list.isEmpty())
|
| 355 | {
|
| 356 | for (int i = 0; i < list.size(); ++i)
|
| 357 | {
|
| 358 | Entity entity = (Entity)list.get(i);
|
| 359 |
|
| 360 | if (entity instanceof EntityMinecart && ((EntityMinecart)entity).getMinecartType() == EntityMinecart.EnumMinecartType.RIDEABLE && this.getDistanceSqToEntity(entity) <= 0.2D)
|
| 361 | {
|
| 362 | entity.applyEntityCollision(this);
|
| 363 | }
|
| 364 | }
|
| 365 | }
|
| 366 | }
|
| 367 |
|
| 368 | /**
|
| 369 | * New version of interactWith that includes vector information on where precisely the player targeted.
|
| 370 | */
|
| 371 | public boolean interactAt(EntityPlayer player, Vec3 targetVec3)
|
| 372 | {
|
| 373 | if (this.hasMarker())
|
| 374 | {
|
| 375 | return false;
|
| 376 | }
|
| 377 | else if (!this.worldObj.isRemote && !player.isSpectator())
|
| 378 | {
|
| 379 | int i = 0;
|
| 380 | ItemStack itemstack = player.getCurrentEquippedItem();
|
| 381 | boolean flag = itemstack != null;
|
| 382 |
|
| 383 | if (flag && itemstack.getItem() instanceof ItemArmor)
|
| 384 | {
|
| 385 | ItemArmor itemarmor = (ItemArmor)itemstack.getItem();
|
| 386 |
|
| 387 | if (itemarmor.armorType == 3)
|
| 388 | {
|
| 389 | i = 1;
|
| 390 | }
|
| 391 | else if (itemarmor.armorType == 2)
|
| 392 | {
|
| 393 | i = 2;
|
| 394 | }
|
| 395 | else if (itemarmor.armorType == 1)
|
| 396 | {
|
| 397 | i = 3;
|
| 398 | }
|
| 399 | else if (itemarmor.armorType == 0)
|
| 400 | {
|
| 401 | i = 4;
|
| 402 | }
|
| 403 | }
|
| 404 |
|
| 405 | if (flag && (itemstack.getItem() == Items.skull || itemstack.getItem() == Item.getItemFromBlock(Blocks.pumpkin)))
|
| 406 | {
|
| 407 | i = 4;
|
| 408 | }
|
| 409 |
|
| 410 | double d4 = 0.1D;
|
| 411 | double d0 = 0.9D;
|
| 412 | double d1 = 0.4D;
|
| 413 | double d2 = 1.6D;
|
| 414 | int j = 0;
|
| 415 | boolean flag1 = this.isSmall();
|
| 416 | double d3 = flag1 ? targetVec3.yCoord * 2.0D : targetVec3.yCoord;
|
| 417 |
|
| 418 | if (d3 >= 0.1D && d3 < 0.1D + (flag1 ? 0.8D : 0.45D) && this.contents[1] != null)
|
| 419 | {
|
| 420 | j = 1;
|
| 421 | }
|
| 422 | else if (d3 >= 0.9D + (flag1 ? 0.3D : 0.0D) && d3 < 0.9D + (flag1 ? 1.0D : 0.7D) && this.contents[3] != null)
|
| 423 | {
|
| 424 | j = 3;
|
| 425 | }
|
| 426 | else if (d3 >= 0.4D && d3 < 0.4D + (flag1 ? 1.0D : 0.8D) && this.contents[2] != null)
|
| 427 | {
|
| 428 | j = 2;
|
| 429 | }
|
| 430 | else if (d3 >= 1.6D && this.contents[4] != null)
|
| 431 | {
|
| 432 | j = 4;
|
| 433 | }
|
| 434 |
|
| 435 | boolean flag2 = this.contents[j] != null;
|
| 436 |
|
| 437 | if ((this.disabledSlots & 1 << j) != 0 || (this.disabledSlots & 1 << i) != 0)
|
| 438 | {
|
| 439 | j = i;
|
| 440 |
|
| 441 | if ((this.disabledSlots & 1 << i) != 0)
|
| 442 | {
|
| 443 | if ((this.disabledSlots & 1) != 0)
|
| 444 | {
|
| 445 | return true;
|
| 446 | }
|
| 447 |
|
| 448 | j = 0;
|
| 449 | }
|
| 450 | }
|
| 451 |
|
| 452 | if (flag && i == 0 && !this.getShowArms())
|
| 453 | {
|
| 454 | return true;
|
| 455 | }
|
| 456 | else
|
| 457 | {
|
| 458 | if (flag)
|
| 459 | {
|
| 460 | this.func_175422_a(player, i);
|
| 461 | }
|
| 462 | else if (flag2)
|
| 463 | {
|
| 464 | this.func_175422_a(player, j);
|
| 465 | }
|
| 466 |
|
| 467 | return true;
|
| 468 | }
|
| 469 | }
|
| 470 | else
|
| 471 | {
|
| 472 | return true;
|
| 473 | }
|
| 474 | }
|
| 475 |
|
| 476 | private void func_175422_a(EntityPlayer p_175422_1_, int p_175422_2_)
|
| 477 | {
|
| 478 | ItemStack itemstack = this.contents[p_175422_2_];
|
| 479 |
|
| 480 | if (itemstack == null || (this.disabledSlots & 1 << p_175422_2_ + 8) == 0)
|
| 481 | {
|
| 482 | if (itemstack != null || (this.disabledSlots & 1 << p_175422_2_ + 16) == 0)
|
| 483 | {
|
| 484 | int i = p_175422_1_.inventory.currentItem;
|
| 485 | ItemStack itemstack1 = p_175422_1_.inventory.getStackInSlot(i);
|
| 486 |
|
| 487 | if (p_175422_1_.capabilities.isCreativeMode && (itemstack == null || itemstack.getItem() == Item.getItemFromBlock(Blocks.air)) && itemstack1 != null)
|
| 488 | {
|
| 489 | ItemStack itemstack3 = itemstack1.copy();
|
| 490 | itemstack3.stackSize = 1;
|
| 491 | this.setCurrentItemOrArmor(p_175422_2_, itemstack3);
|
| 492 | }
|
| 493 | else if (itemstack1 != null && itemstack1.stackSize > 1)
|
| 494 | {
|
| 495 | if (itemstack == null)
|
| 496 | {
|
| 497 | ItemStack itemstack2 = itemstack1.copy();
|
| 498 | itemstack2.stackSize = 1;
|
| 499 | this.setCurrentItemOrArmor(p_175422_2_, itemstack2);
|
| 500 | --itemstack1.stackSize;
|
| 501 | }
|
| 502 | }
|
| 503 | else
|
| 504 | {
|
| 505 | this.setCurrentItemOrArmor(p_175422_2_, itemstack1);
|
| 506 | p_175422_1_.inventory.setInventorySlotContents(i, itemstack);
|
| 507 | }
|
| 508 | }
|
| 509 | }
|
| 510 | }
|
| 511 |
|
| 512 | /**
|
| 513 | * Called when the entity is attacked.
|
| 514 | */
|
| 515 | public boolean attackEntityFrom(DamageSource source, float amount)
|
| 516 | {
|
| 517 | if (this.worldObj.isRemote)
|
| 518 | {
|
| 519 | return false;
|
| 520 | }
|
| 521 | else if (DamageSource.outOfWorld.equals(source))
|
| 522 | {
|
| 523 | this.setDead();
|
| 524 | return false;
|
| 525 | }
|
| 526 | else if (!this.isEntityInvulnerable(source) && !this.canInteract && !this.hasMarker())
|
| 527 | {
|
| 528 | if (source.isExplosion())
|
| 529 | {
|
| 530 | this.dropContents();
|
| 531 | this.setDead();
|
| 532 | return false;
|
| 533 | }
|
| 534 | else if (DamageSource.inFire.equals(source))
|
| 535 | {
|
| 536 | if (!this.isBurning())
|
| 537 | {
|
| 538 | this.setFire(5);
|
| 539 | }
|
| 540 | else
|
| 541 | {
|
| 542 | this.damageArmorStand(0.15F);
|
| 543 | }
|
| 544 |
|
| 545 | return false;
|
| 546 | }
|
| 547 | else if (DamageSource.onFire.equals(source) && this.getHealth() > 0.5F)
|
| 548 | {
|
| 549 | this.damageArmorStand(4.0F);
|
| 550 | return false;
|
| 551 | }
|
| 552 | else
|
| 553 | {
|
| 554 | boolean flag = "arrow".equals(source.getDamageType());
|
| 555 | boolean flag1 = "player".equals(source.getDamageType());
|
| 556 |
|
| 557 | if (!flag1 && !flag)
|
| 558 | {
|
| 559 | return false;
|
| 560 | }
|
| 561 | else
|
| 562 | {
|
| 563 | if (source.getSourceOfDamage() instanceof EntityArrow)
|
| 564 | {
|
| 565 | source.getSourceOfDamage().setDead();
|
| 566 | }
|
| 567 |
|
| 568 | if (source.getEntity() instanceof EntityPlayer && !((EntityPlayer)source.getEntity()).capabilities.allowEdit)
|
| 569 | {
|
| 570 | return false;
|
| 571 | }
|
| 572 | else if (source.isCreativePlayer())
|
| 573 | {
|
| 574 | this.playParticles();
|
| 575 | this.setDead();
|
| 576 | return false;
|
| 577 | }
|
| 578 | else
|
| 579 | {
|
| 580 | long i = this.worldObj.getTotalWorldTime();
|
| 581 |
|
| 582 | if (i - this.punchCooldown > 5L && !flag)
|
| 583 | {
|
| 584 | this.punchCooldown = i;
|
| 585 | }
|
| 586 | else
|
| 587 | {
|
| 588 | this.dropBlock();
|
| 589 | this.playParticles();
|
| 590 | this.setDead();
|
| 591 | }
|
| 592 |
|
| 593 | return false;
|
| 594 | }
|
| 595 | }
|
| 596 | }
|
| 597 | }
|
| 598 | else
|
| 599 | {
|
| 600 | return false;
|
| 601 | }
|
| 602 | }
|
| 603 |
|
| 604 | /**
|
| 605 | * Checks if the entity is in range to render by using the past in distance and comparing it to its average edge
|
| 606 | * length * 64 * renderDistanceWeight Args: distance
|
| 607 | */
|
| 608 | public boolean isInRangeToRenderDist(double distance)
|
| 609 | {
|
| 610 | double d0 = this.getEntityBoundingBox().getAverageEdgeLength() * 4.0D;
|
| 611 |
|
| 612 | if (Double.isNaN(d0) || d0 == 0.0D)
|
| 613 | {
|
| 614 | d0 = 4.0D;
|
| 615 | }
|
| 616 |
|
| 617 | d0 = d0 * 64.0D;
|
| 618 | return distance < d0 * d0;
|
| 619 | }
|
| 620 |
|
| 621 | private void playParticles()
|
| 622 | {
|
| 623 | if (this.worldObj instanceof WorldServer)
|
| 624 | {
|
| 625 | ((WorldServer)this.worldObj).spawnParticle(EnumParticleTypes.BLOCK_DUST, this.posX, this.posY + (double)this.height / 1.5D, this.posZ, 10, (double)(this.width / 4.0F), (double)(this.height / 4.0F), (double)(this.width / 4.0F), 0.05D, new int[] {Block.getStateId(Blocks.planks.getDefaultState())});
|
| 626 | }
|
| 627 | }
|
| 628 |
|
| 629 | private void damageArmorStand(float p_175406_1_)
|
| 630 | {
|
| 631 | float f = this.getHealth();
|
| 632 | f = f - p_175406_1_;
|
| 633 |
|
| 634 | if (f <= 0.5F)
|
| 635 | {
|
| 636 | this.dropContents();
|
| 637 | this.setDead();
|
| 638 | }
|
| 639 | else
|
| 640 | {
|
| 641 | this.setHealth(f);
|
| 642 | }
|
| 643 | }
|
| 644 |
|
| 645 | private void dropBlock()
|
| 646 | {
|
| 647 | Block.spawnAsEntity(this.worldObj, new BlockPos(this), new ItemStack(Items.armor_stand));
|
| 648 | this.dropContents();
|
| 649 | }
|
| 650 |
|
| 651 | private void dropContents()
|
| 652 | {
|
| 653 | for (int i = 0; i < this.contents.length; ++i)
|
| 654 | {
|
| 655 | if (this.contents[i] != null && this.contents[i].stackSize > 0)
|
| 656 | {
|
| 657 | if (this.contents[i] != null)
|
| 658 | {
|
| 659 | Block.spawnAsEntity(this.worldObj, (new BlockPos(this)).up(), this.contents[i]);
|
| 660 | }
|
| 661 |
|
| 662 | this.contents[i] = null;
|
| 663 | }
|
| 664 | }
|
| 665 | }
|
| 666 |
|
| 667 | protected float updateDistance(float p_110146_1_, float p_110146_2_)
|
| 668 | {
|
| 669 | this.prevRenderYawOffset = this.prevRotationYaw;
|
| 670 | this.renderYawOffset = this.rotationYaw;
|
| 671 | return 0.0F;
|
| 672 | }
|
| 673 |
|
| 674 | public float getEyeHeight()
|
| 675 | {
|
| 676 | return this.isChild() ? this.height * 0.5F : this.height * 0.9F;
|
| 677 | }
|
| 678 |
|
| 679 | /**
|
| 680 | * Moves the entity based on the specified heading. Args: strafe, forward
|
| 681 | */
|
| 682 | public void moveEntityWithHeading(float strafe, float forward)
|
| 683 | {
|
| 684 | if (!this.hasNoGravity())
|
| 685 | {
|
| 686 | super.moveEntityWithHeading(strafe, forward);
|
| 687 | }
|
| 688 | }
|
| 689 |
|
| 690 | /**
|
| 691 | * Called to update the entity's position/logic.
|
| 692 | */
|
| 693 | public void onUpdate()
|
| 694 | {
|
| 695 | super.onUpdate();
|
| 696 | Rotations rotations = this.dataWatcher.getWatchableObjectRotations(11);
|
| 697 |
|
| 698 | if (!this.headRotation.equals(rotations))
|
| 699 | {
|
| 700 | this.setHeadRotation(rotations);
|
| 701 | }
|
| 702 |
|
| 703 | Rotations rotations1 = this.dataWatcher.getWatchableObjectRotations(12);
|
| 704 |
|
| 705 | if (!this.bodyRotation.equals(rotations1))
|
| 706 | {
|
| 707 | this.setBodyRotation(rotations1);
|
| 708 | }
|
| 709 |
|
| 710 | Rotations rotations2 = this.dataWatcher.getWatchableObjectRotations(13);
|
| 711 |
|
| 712 | if (!this.leftArmRotation.equals(rotations2))
|
| 713 | {
|
| 714 | this.setLeftArmRotation(rotations2);
|
| 715 | }
|
| 716 |
|
| 717 | Rotations rotations3 = this.dataWatcher.getWatchableObjectRotations(14);
|
| 718 |
|
| 719 | if (!this.rightArmRotation.equals(rotations3))
|
| 720 | {
|
| 721 | this.setRightArmRotation(rotations3);
|
| 722 | }
|
| 723 |
|
| 724 | Rotations rotations4 = this.dataWatcher.getWatchableObjectRotations(15);
|
| 725 |
|
| 726 | if (!this.leftLegRotation.equals(rotations4))
|
| 727 | {
|
| 728 | this.setLeftLegRotation(rotations4);
|
| 729 | }
|
| 730 |
|
| 731 | Rotations rotations5 = this.dataWatcher.getWatchableObjectRotations(16);
|
| 732 |
|
| 733 | if (!this.rightLegRotation.equals(rotations5))
|
| 734 | {
|
| 735 | this.setRightLegRotation(rotations5);
|
| 736 | }
|
| 737 |
|
| 738 | boolean flag = this.hasMarker();
|
| 739 |
|
| 740 | if (!this.field_181028_bj && flag)
|
| 741 | {
|
| 742 | this.func_181550_a(false);
|
| 743 | }
|
| 744 | else
|
| 745 | {
|
| 746 | if (!this.field_181028_bj || flag)
|
| 747 | {
|
| 748 | return;
|
| 749 | }
|
| 750 |
|
| 751 | this.func_181550_a(true);
|
| 752 | }
|
| 753 |
|
| 754 | this.field_181028_bj = flag;
|
| 755 | }
|
| 756 |
|
| 757 | private void func_181550_a(boolean p_181550_1_)
|
| 758 | {
|
| 759 | double d0 = this.posX;
|
| 760 | double d1 = this.posY;
|
| 761 | double d2 = this.posZ;
|
| 762 |
|
| 763 | if (p_181550_1_)
|
| 764 | {
|
| 765 | this.setSize(0.5F, 1.975F);
|
| 766 | }
|
| 767 | else
|
| 768 | {
|
| 769 | this.setSize(0.0F, 0.0F);
|
| 770 | }
|
| 771 |
|
| 772 | this.setPosition(d0, d1, d2);
|
| 773 | }
|
| 774 |
|
| 775 | /**
|
| 776 | * Clears potion metadata values if the entity has no potion effects. Otherwise, updates potion effect color,
|
| 777 | * ambience, and invisibility metadata values
|
| 778 | */
|
| 779 | protected void updatePotionMetadata()
|
| 780 | {
|
| 781 | this.setInvisible(this.canInteract);
|
| 782 | }
|
| 783 |
|
| 784 | public void setInvisible(boolean invisible)
|
| 785 | {
|
| 786 | this.canInteract = invisible;
|
| 787 | super.setInvisible(invisible);
|
| 788 | }
|
| 789 |
|
| 790 | /**
|
| 791 | * If Animal, checks if the age timer is negative
|
| 792 | */
|
| 793 | public boolean isChild()
|
| 794 | {
|
| 795 | return this.isSmall();
|
| 796 | }
|
| 797 |
|
| 798 | /**
|
| 799 | * Called by the /kill command.
|
| 800 | */
|
| 801 | public void onKillCommand()
|
| 802 | {
|
| 803 | this.setDead();
|
| 804 | }
|
| 805 |
|
| 806 | public boolean isImmuneToExplosions()
|
| 807 | {
|
| 808 | return this.isInvisible();
|
| 809 | }
|
| 810 |
|
| 811 | private void setSmall(boolean p_175420_1_)
|
| 812 | {
|
| 813 | byte b0 = this.dataWatcher.getWatchableObjectByte(10);
|
| 814 |
|
| 815 | if (p_175420_1_)
|
| 816 | {
|
| 817 | b0 = (byte)(b0 | 1);
|
| 818 | }
|
| 819 | else
|
| 820 | {
|
| 821 | b0 = (byte)(b0 & -2);
|
| 822 | }
|
| 823 |
|
| 824 | this.dataWatcher.updateObject(10, Byte.valueOf(b0));
|
| 825 | }
|
| 826 |
|
| 827 | public boolean isSmall()
|
| 828 | {
|
| 829 | return (this.dataWatcher.getWatchableObjectByte(10) & 1) != 0;
|
| 830 | }
|
| 831 |
|
| 832 | private void setNoGravity(boolean p_175425_1_)
|
| 833 | {
|
| 834 | byte b0 = this.dataWatcher.getWatchableObjectByte(10);
|
| 835 |
|
| 836 | if (p_175425_1_)
|
| 837 | {
|
| 838 | b0 = (byte)(b0 | 2);
|
| 839 | }
|
| 840 | else
|
| 841 | {
|
| 842 | b0 = (byte)(b0 & -3);
|
| 843 | }
|
| 844 |
|
| 845 | this.dataWatcher.updateObject(10, Byte.valueOf(b0));
|
| 846 | }
|
| 847 |
|
| 848 | public boolean hasNoGravity()
|
| 849 | {
|
| 850 | return (this.dataWatcher.getWatchableObjectByte(10) & 2) != 0;
|
| 851 | }
|
| 852 |
|
| 853 | private void setShowArms(boolean p_175413_1_)
|
| 854 | {
|
| 855 | byte b0 = this.dataWatcher.getWatchableObjectByte(10);
|
| 856 |
|
| 857 | if (p_175413_1_)
|
| 858 | {
|
| 859 | b0 = (byte)(b0 | 4);
|
| 860 | }
|
| 861 | else
|
| 862 | {
|
| 863 | b0 = (byte)(b0 & -5);
|
| 864 | }
|
| 865 |
|
| 866 | this.dataWatcher.updateObject(10, Byte.valueOf(b0));
|
| 867 | }
|
| 868 |
|
| 869 | public boolean getShowArms()
|
| 870 | {
|
| 871 | return (this.dataWatcher.getWatchableObjectByte(10) & 4) != 0;
|
| 872 | }
|
| 873 |
|
| 874 | private void setNoBasePlate(boolean p_175426_1_)
|
| 875 | {
|
| 876 | byte b0 = this.dataWatcher.getWatchableObjectByte(10);
|
| 877 |
|
| 878 | if (p_175426_1_)
|
| 879 | {
|
| 880 | b0 = (byte)(b0 | 8);
|
| 881 | }
|
| 882 | else
|
| 883 | {
|
| 884 | b0 = (byte)(b0 & -9);
|
| 885 | }
|
| 886 |
|
| 887 | this.dataWatcher.updateObject(10, Byte.valueOf(b0));
|
| 888 | }
|
| 889 |
|
| 890 | public boolean hasNoBasePlate()
|
| 891 | {
|
| 892 | return (this.dataWatcher.getWatchableObjectByte(10) & 8) != 0;
|
| 893 | }
|
| 894 |
|
| 895 | /**
|
| 896 | * Marker defines where if true, the size is 0 and will not be rendered or intractable.
|
| 897 | */
|
| 898 | private void setMarker(boolean p_181027_1_)
|
| 899 | {
|
| 900 | byte b0 = this.dataWatcher.getWatchableObjectByte(10);
|
| 901 |
|
| 902 | if (p_181027_1_)
|
| 903 | {
|
| 904 | b0 = (byte)(b0 | 16);
|
| 905 | }
|
| 906 | else
|
| 907 | {
|
| 908 | b0 = (byte)(b0 & -17);
|
| 909 | }
|
| 910 |
|
| 911 | this.dataWatcher.updateObject(10, Byte.valueOf(b0));
|
| 912 | }
|
| 913 |
|
| 914 | /**
|
| 915 | * Gets whether the armor stand has marker enabled. If true, the armor stand's bounding box is set to zero and
|
| 916 | * cannot be interacted with.
|
| 917 | */
|
| 918 | public boolean hasMarker()
|
| 919 | {
|
| 920 | return (this.dataWatcher.getWatchableObjectByte(10) & 16) != 0;
|
| 921 | }
|
| 922 |
|
| 923 | public void setHeadRotation(Rotations p_175415_1_)
|
| 924 | {
|
| 925 | this.headRotation = p_175415_1_;
|
| 926 | this.dataWatcher.updateObject(11, p_175415_1_);
|
| 927 | }
|
| 928 |
|
| 929 | public void setBodyRotation(Rotations p_175424_1_)
|
| 930 | {
|
| 931 | this.bodyRotation = p_175424_1_;
|
| 932 | this.dataWatcher.updateObject(12, p_175424_1_);
|
| 933 | }
|
| 934 |
|
| 935 | public void setLeftArmRotation(Rotations p_175405_1_)
|
| 936 | {
|
| 937 | this.leftArmRotation = p_175405_1_;
|
| 938 | this.dataWatcher.updateObject(13, p_175405_1_);
|
| 939 | }
|
| 940 |
|
| 941 | public void setRightArmRotation(Rotations p_175428_1_)
|
| 942 | {
|
| 943 | this.rightArmRotation = p_175428_1_;
|
| 944 | this.dataWatcher.updateObject(14, p_175428_1_);
|
| 945 | }
|
| 946 |
|
| 947 | public void setLeftLegRotation(Rotations p_175417_1_)
|
| 948 | {
|
| 949 | this.leftLegRotation = p_175417_1_;
|
| 950 | this.dataWatcher.updateObject(15, p_175417_1_);
|
| 951 | }
|
| 952 |
|
| 953 | public void setRightLegRotation(Rotations p_175427_1_)
|
| 954 | {
|
| 955 | this.rightLegRotation = p_175427_1_;
|
| 956 | this.dataWatcher.updateObject(16, p_175427_1_);
|
| 957 | }
|
| 958 |
|
| 959 | public Rotations getHeadRotation()
|
| 960 | {
|
| 961 | return this.headRotation;
|
| 962 | }
|
| 963 |
|
| 964 | public Rotations getBodyRotation()
|
| 965 | {
|
| 966 | return this.bodyRotation;
|
| 967 | }
|
| 968 |
|
| 969 | public Rotations getLeftArmRotation()
|
| 970 | {
|
| 971 | return this.leftArmRotation;
|
| 972 | }
|
| 973 |
|
| 974 | public Rotations getRightArmRotation()
|
| 975 | {
|
| 976 | return this.rightArmRotation;
|
| 977 | }
|
| 978 |
|
| 979 | public Rotations getLeftLegRotation()
|
| 980 | {
|
| 981 | return this.leftLegRotation;
|
| 982 | }
|
| 983 |
|
| 984 | public Rotations getRightLegRotation()
|
| 985 | {
|
| 986 | return this.rightLegRotation;
|
| 987 | }
|
| 988 |
|
| 989 | /**
|
| 990 | * Returns true if other Entities should be prevented from moving through this Entity.
|
| 991 | */
|
| 992 | public boolean canBeCollidedWith()
|
| 993 | {
|
| 994 | return super.canBeCollidedWith() && !this.hasMarker();
|
| 995 | }
|
| 996 | }
|
| 997 |
|