| 1 | package net.minecraft.entity;
|
| 2 |
|
| 3 | import com.google.common.collect.Sets;
|
| 4 | import java.util.Collection;
|
| 5 | import java.util.List;
|
| 6 | import java.util.Set;
|
| 7 | import net.minecraft.block.Block;
|
| 8 | import net.minecraft.entity.ai.attributes.IAttributeInstance;
|
| 9 | import net.minecraft.entity.ai.attributes.ServersideAttributeMap;
|
| 10 | import net.minecraft.entity.item.EntityArmorStand;
|
| 11 | import net.minecraft.entity.item.EntityBoat;
|
| 12 | import net.minecraft.entity.item.EntityEnderCrystal;
|
| 13 | import net.minecraft.entity.item.EntityEnderEye;
|
| 14 | import net.minecraft.entity.item.EntityEnderPearl;
|
| 15 | import net.minecraft.entity.item.EntityExpBottle;
|
| 16 | import net.minecraft.entity.item.EntityFallingBlock;
|
| 17 | import net.minecraft.entity.item.EntityFireworkRocket;
|
| 18 | import net.minecraft.entity.item.EntityItem;
|
| 19 | import net.minecraft.entity.item.EntityItemFrame;
|
| 20 | import net.minecraft.entity.item.EntityMinecart;
|
| 21 | import net.minecraft.entity.item.EntityPainting;
|
| 22 | import net.minecraft.entity.item.EntityTNTPrimed;
|
| 23 | import net.minecraft.entity.item.EntityXPOrb;
|
| 24 | import net.minecraft.entity.passive.IAnimals;
|
| 25 | import net.minecraft.entity.player.EntityPlayer;
|
| 26 | import net.minecraft.entity.player.EntityPlayerMP;
|
| 27 | import net.minecraft.entity.projectile.EntityArrow;
|
| 28 | import net.minecraft.entity.projectile.EntityEgg;
|
| 29 | import net.minecraft.entity.projectile.EntityFireball;
|
| 30 | import net.minecraft.entity.projectile.EntityFishHook;
|
| 31 | import net.minecraft.entity.projectile.EntityPotion;
|
| 32 | import net.minecraft.entity.projectile.EntitySmallFireball;
|
| 33 | import net.minecraft.entity.projectile.EntitySnowball;
|
| 34 | import net.minecraft.entity.projectile.EntityWitherSkull;
|
| 35 | import net.minecraft.init.Items;
|
| 36 | import net.minecraft.item.ItemMap;
|
| 37 | import net.minecraft.item.ItemStack;
|
| 38 | import net.minecraft.nbt.NBTTagCompound;
|
| 39 | import net.minecraft.network.Packet;
|
| 40 | import net.minecraft.network.play.server.S04PacketEntityEquipment;
|
| 41 | import net.minecraft.network.play.server.S0APacketUseBed;
|
| 42 | import net.minecraft.network.play.server.S0CPacketSpawnPlayer;
|
| 43 | import net.minecraft.network.play.server.S0EPacketSpawnObject;
|
| 44 | import net.minecraft.network.play.server.S0FPacketSpawnMob;
|
| 45 | import net.minecraft.network.play.server.S10PacketSpawnPainting;
|
| 46 | import net.minecraft.network.play.server.S11PacketSpawnExperienceOrb;
|
| 47 | import net.minecraft.network.play.server.S12PacketEntityVelocity;
|
| 48 | import net.minecraft.network.play.server.S14PacketEntity;
|
| 49 | import net.minecraft.network.play.server.S18PacketEntityTeleport;
|
| 50 | import net.minecraft.network.play.server.S19PacketEntityHeadLook;
|
| 51 | import net.minecraft.network.play.server.S1BPacketEntityAttach;
|
| 52 | import net.minecraft.network.play.server.S1CPacketEntityMetadata;
|
| 53 | import net.minecraft.network.play.server.S1DPacketEntityEffect;
|
| 54 | import net.minecraft.network.play.server.S20PacketEntityProperties;
|
| 55 | import net.minecraft.network.play.server.S49PacketUpdateEntityNBT;
|
| 56 | import net.minecraft.potion.PotionEffect;
|
| 57 | import net.minecraft.util.BlockPos;
|
| 58 | import net.minecraft.util.MathHelper;
|
| 59 | import net.minecraft.world.storage.MapData;
|
| 60 | import org.apache.logging.log4j.LogManager;
|
| 61 | import org.apache.logging.log4j.Logger;
|
| 62 |
|
| 63 | public class EntityTrackerEntry
|
| 64 | {
|
| 65 | private static final Logger logger = LogManager.getLogger();
|
| 66 |
|
| 67 | /** The entity that this EntityTrackerEntry tracks. */
|
| 68 | public Entity trackedEntity;
|
| 69 | public int trackingDistanceThreshold;
|
| 70 |
|
| 71 | /** check for sync when ticks % updateFrequency==0 */
|
| 72 | public int updateFrequency;
|
| 73 |
|
| 74 | /** The encoded entity X position. */
|
| 75 | public int encodedPosX;
|
| 76 |
|
| 77 | /** The encoded entity Y position. */
|
| 78 | public int encodedPosY;
|
| 79 |
|
| 80 | /** The encoded entity Z position. */
|
| 81 | public int encodedPosZ;
|
| 82 |
|
| 83 | /** The encoded entity yaw rotation. */
|
| 84 | public int encodedRotationYaw;
|
| 85 |
|
| 86 | /** The encoded entity pitch rotation. */
|
| 87 | public int encodedRotationPitch;
|
| 88 | public int lastHeadMotion;
|
| 89 | public double lastTrackedEntityMotionX;
|
| 90 | public double lastTrackedEntityMotionY;
|
| 91 | public double motionZ;
|
| 92 | public int updateCounter;
|
| 93 | private double lastTrackedEntityPosX;
|
| 94 | private double lastTrackedEntityPosY;
|
| 95 | private double lastTrackedEntityPosZ;
|
| 96 | private boolean firstUpdateDone;
|
| 97 | private boolean sendVelocityUpdates;
|
| 98 |
|
| 99 | /**
|
| 100 | * every 400 ticks a full teleport packet is sent, rather than just a "move me +x" command, so that position
|
| 101 | * remains fully synced.
|
| 102 | */
|
| 103 | private int ticksSinceLastForcedTeleport;
|
| 104 | private Entity field_85178_v;
|
| 105 | private boolean ridingEntity;
|
| 106 | private boolean onGround;
|
| 107 | public boolean playerEntitiesUpdated;
|
| 108 | public Set<EntityPlayerMP> trackingPlayers = Sets.<EntityPlayerMP>newHashSet();
|
| 109 |
|
| 110 | public EntityTrackerEntry(Entity trackedEntityIn, int trackingDistanceThresholdIn, int updateFrequencyIn, boolean sendVelocityUpdatesIn)
|
| 111 | {
|
| 112 | this.trackedEntity = trackedEntityIn;
|
| 113 | this.trackingDistanceThreshold = trackingDistanceThresholdIn;
|
| 114 | this.updateFrequency = updateFrequencyIn;
|
| 115 | this.sendVelocityUpdates = sendVelocityUpdatesIn;
|
| 116 | this.encodedPosX = MathHelper.floor_double(trackedEntityIn.posX * 32.0D);
|
| 117 | this.encodedPosY = MathHelper.floor_double(trackedEntityIn.posY * 32.0D);
|
| 118 | this.encodedPosZ = MathHelper.floor_double(trackedEntityIn.posZ * 32.0D);
|
| 119 | this.encodedRotationYaw = MathHelper.floor_float(trackedEntityIn.rotationYaw * 256.0F / 360.0F);
|
| 120 | this.encodedRotationPitch = MathHelper.floor_float(trackedEntityIn.rotationPitch * 256.0F / 360.0F);
|
| 121 | this.lastHeadMotion = MathHelper.floor_float(trackedEntityIn.getRotationYawHead() * 256.0F / 360.0F);
|
| 122 | this.onGround = trackedEntityIn.onGround;
|
| 123 | }
|
| 124 |
|
| 125 | public boolean equals(Object p_equals_1_)
|
| 126 | {
|
| 127 | return p_equals_1_ instanceof EntityTrackerEntry ? ((EntityTrackerEntry)p_equals_1_).trackedEntity.getEntityId() == this.trackedEntity.getEntityId() : false;
|
| 128 | }
|
| 129 |
|
| 130 | public int hashCode()
|
| 131 | {
|
| 132 | return this.trackedEntity.getEntityId();
|
| 133 | }
|
| 134 |
|
| 135 | public void updatePlayerList(List<EntityPlayer> players)
|
| 136 | {
|
| 137 | this.playerEntitiesUpdated = false;
|
| 138 |
|
| 139 | if (!this.firstUpdateDone || this.trackedEntity.getDistanceSq(this.lastTrackedEntityPosX, this.lastTrackedEntityPosY, this.lastTrackedEntityPosZ) > 16.0D)
|
| 140 | {
|
| 141 | this.lastTrackedEntityPosX = this.trackedEntity.posX;
|
| 142 | this.lastTrackedEntityPosY = this.trackedEntity.posY;
|
| 143 | this.lastTrackedEntityPosZ = this.trackedEntity.posZ;
|
| 144 | this.firstUpdateDone = true;
|
| 145 | this.playerEntitiesUpdated = true;
|
| 146 | this.updatePlayerEntities(players);
|
| 147 | }
|
| 148 |
|
| 149 | if (this.field_85178_v != this.trackedEntity.ridingEntity || this.trackedEntity.ridingEntity != null && this.updateCounter % 60 == 0)
|
| 150 | {
|
| 151 | this.field_85178_v = this.trackedEntity.ridingEntity;
|
| 152 | this.sendPacketToTrackedPlayers(new S1BPacketEntityAttach(0, this.trackedEntity, this.trackedEntity.ridingEntity));
|
| 153 | }
|
| 154 |
|
| 155 | if (this.trackedEntity instanceof EntityItemFrame && this.updateCounter % 10 == 0)
|
| 156 | {
|
| 157 | EntityItemFrame entityitemframe = (EntityItemFrame)this.trackedEntity;
|
| 158 | ItemStack itemstack = entityitemframe.getDisplayedItem();
|
| 159 |
|
| 160 | if (itemstack != null && itemstack.getItem() instanceof ItemMap)
|
| 161 | {
|
| 162 | MapData mapdata = Items.filled_map.getMapData(itemstack, this.trackedEntity.worldObj);
|
| 163 |
|
| 164 | for (EntityPlayer entityplayer : players)
|
| 165 | {
|
| 166 | EntityPlayerMP entityplayermp = (EntityPlayerMP)entityplayer;
|
| 167 | mapdata.updateVisiblePlayers(entityplayermp, itemstack);
|
| 168 | Packet packet = Items.filled_map.createMapDataPacket(itemstack, this.trackedEntity.worldObj, entityplayermp);
|
| 169 |
|
| 170 | if (packet != null)
|
| 171 | {
|
| 172 | entityplayermp.playerNetServerHandler.sendPacket(packet);
|
| 173 | }
|
| 174 | }
|
| 175 | }
|
| 176 |
|
| 177 | this.sendMetadataToAllAssociatedPlayers();
|
| 178 | }
|
| 179 |
|
| 180 | if (this.updateCounter % this.updateFrequency == 0 || this.trackedEntity.isAirBorne || this.trackedEntity.getDataWatcher().hasObjectChanged())
|
| 181 | {
|
| 182 | if (this.trackedEntity.ridingEntity == null)
|
| 183 | {
|
| 184 | ++this.ticksSinceLastForcedTeleport;
|
| 185 | int k = MathHelper.floor_double(this.trackedEntity.posX * 32.0D);
|
| 186 | int j1 = MathHelper.floor_double(this.trackedEntity.posY * 32.0D);
|
| 187 | int k1 = MathHelper.floor_double(this.trackedEntity.posZ * 32.0D);
|
| 188 | int l1 = MathHelper.floor_float(this.trackedEntity.rotationYaw * 256.0F / 360.0F);
|
| 189 | int i2 = MathHelper.floor_float(this.trackedEntity.rotationPitch * 256.0F / 360.0F);
|
| 190 | int j2 = k - this.encodedPosX;
|
| 191 | int k2 = j1 - this.encodedPosY;
|
| 192 | int i = k1 - this.encodedPosZ;
|
| 193 | Packet packet1 = null;
|
| 194 | boolean flag = Math.abs(j2) >= 4 || Math.abs(k2) >= 4 || Math.abs(i) >= 4 || this.updateCounter % 60 == 0;
|
| 195 | boolean flag1 = Math.abs(l1 - this.encodedRotationYaw) >= 4 || Math.abs(i2 - this.encodedRotationPitch) >= 4;
|
| 196 |
|
| 197 | if (this.updateCounter > 0 || this.trackedEntity instanceof EntityArrow)
|
| 198 | {
|
| 199 | if (j2 >= -128 && j2 < 128 && k2 >= -128 && k2 < 128 && i >= -128 && i < 128 && this.ticksSinceLastForcedTeleport <= 400 && !this.ridingEntity && this.onGround == this.trackedEntity.onGround)
|
| 200 | {
|
| 201 | if ((!flag || !flag1) && !(this.trackedEntity instanceof EntityArrow))
|
| 202 | {
|
| 203 | if (flag)
|
| 204 | {
|
| 205 | packet1 = new S14PacketEntity.S15PacketEntityRelMove(this.trackedEntity.getEntityId(), (byte)j2, (byte)k2, (byte)i, this.trackedEntity.onGround);
|
| 206 | }
|
| 207 | else if (flag1)
|
| 208 | {
|
| 209 | packet1 = new S14PacketEntity.S16PacketEntityLook(this.trackedEntity.getEntityId(), (byte)l1, (byte)i2, this.trackedEntity.onGround);
|
| 210 | }
|
| 211 | }
|
| 212 | else
|
| 213 | {
|
| 214 | packet1 = new S14PacketEntity.S17PacketEntityLookMove(this.trackedEntity.getEntityId(), (byte)j2, (byte)k2, (byte)i, (byte)l1, (byte)i2, this.trackedEntity.onGround);
|
| 215 | }
|
| 216 | }
|
| 217 | else
|
| 218 | {
|
| 219 | this.onGround = this.trackedEntity.onGround;
|
| 220 | this.ticksSinceLastForcedTeleport = 0;
|
| 221 | packet1 = new S18PacketEntityTeleport(this.trackedEntity.getEntityId(), k, j1, k1, (byte)l1, (byte)i2, this.trackedEntity.onGround);
|
| 222 | }
|
| 223 | }
|
| 224 |
|
| 225 | if (this.sendVelocityUpdates)
|
| 226 | {
|
| 227 | double d0 = this.trackedEntity.motionX - this.lastTrackedEntityMotionX;
|
| 228 | double d1 = this.trackedEntity.motionY - this.lastTrackedEntityMotionY;
|
| 229 | double d2 = this.trackedEntity.motionZ - this.motionZ;
|
| 230 | double d3 = 0.02D;
|
| 231 | double d4 = d0 * d0 + d1 * d1 + d2 * d2;
|
| 232 |
|
| 233 | if (d4 > d3 * d3 || d4 > 0.0D && this.trackedEntity.motionX == 0.0D && this.trackedEntity.motionY == 0.0D && this.trackedEntity.motionZ == 0.0D)
|
| 234 | {
|
| 235 | this.lastTrackedEntityMotionX = this.trackedEntity.motionX;
|
| 236 | this.lastTrackedEntityMotionY = this.trackedEntity.motionY;
|
| 237 | this.motionZ = this.trackedEntity.motionZ;
|
| 238 | this.sendPacketToTrackedPlayers(new S12PacketEntityVelocity(this.trackedEntity.getEntityId(), this.lastTrackedEntityMotionX, this.lastTrackedEntityMotionY, this.motionZ));
|
| 239 | }
|
| 240 | }
|
| 241 |
|
| 242 | if (packet1 != null)
|
| 243 | {
|
| 244 | this.sendPacketToTrackedPlayers(packet1);
|
| 245 | }
|
| 246 |
|
| 247 | this.sendMetadataToAllAssociatedPlayers();
|
| 248 |
|
| 249 | if (flag)
|
| 250 | {
|
| 251 | this.encodedPosX = k;
|
| 252 | this.encodedPosY = j1;
|
| 253 | this.encodedPosZ = k1;
|
| 254 | }
|
| 255 |
|
| 256 | if (flag1)
|
| 257 | {
|
| 258 | this.encodedRotationYaw = l1;
|
| 259 | this.encodedRotationPitch = i2;
|
| 260 | }
|
| 261 |
|
| 262 | this.ridingEntity = false;
|
| 263 | }
|
| 264 | else
|
| 265 | {
|
| 266 | int j = MathHelper.floor_float(this.trackedEntity.rotationYaw * 256.0F / 360.0F);
|
| 267 | int i1 = MathHelper.floor_float(this.trackedEntity.rotationPitch * 256.0F / 360.0F);
|
| 268 | boolean flag2 = Math.abs(j - this.encodedRotationYaw) >= 4 || Math.abs(i1 - this.encodedRotationPitch) >= 4;
|
| 269 |
|
| 270 | if (flag2)
|
| 271 | {
|
| 272 | this.sendPacketToTrackedPlayers(new S14PacketEntity.S16PacketEntityLook(this.trackedEntity.getEntityId(), (byte)j, (byte)i1, this.trackedEntity.onGround));
|
| 273 | this.encodedRotationYaw = j;
|
| 274 | this.encodedRotationPitch = i1;
|
| 275 | }
|
| 276 |
|
| 277 | this.encodedPosX = MathHelper.floor_double(this.trackedEntity.posX * 32.0D);
|
| 278 | this.encodedPosY = MathHelper.floor_double(this.trackedEntity.posY * 32.0D);
|
| 279 | this.encodedPosZ = MathHelper.floor_double(this.trackedEntity.posZ * 32.0D);
|
| 280 | this.sendMetadataToAllAssociatedPlayers();
|
| 281 | this.ridingEntity = true;
|
| 282 | }
|
| 283 |
|
| 284 | int l = MathHelper.floor_float(this.trackedEntity.getRotationYawHead() * 256.0F / 360.0F);
|
| 285 |
|
| 286 | if (Math.abs(l - this.lastHeadMotion) >= 4)
|
| 287 | {
|
| 288 | this.sendPacketToTrackedPlayers(new S19PacketEntityHeadLook(this.trackedEntity, (byte)l));
|
| 289 | this.lastHeadMotion = l;
|
| 290 | }
|
| 291 |
|
| 292 | this.trackedEntity.isAirBorne = false;
|
| 293 | }
|
| 294 |
|
| 295 | ++this.updateCounter;
|
| 296 |
|
| 297 | if (this.trackedEntity.velocityChanged)
|
| 298 | {
|
| 299 | this.func_151261_b(new S12PacketEntityVelocity(this.trackedEntity));
|
| 300 | this.trackedEntity.velocityChanged = false;
|
| 301 | }
|
| 302 | }
|
| 303 |
|
| 304 | /**
|
| 305 | * Sends the entity metadata (DataWatcher) and attributes to all players tracking this entity, including the entity
|
| 306 | * itself if a player.
|
| 307 | */
|
| 308 | private void sendMetadataToAllAssociatedPlayers()
|
| 309 | {
|
| 310 | DataWatcher datawatcher = this.trackedEntity.getDataWatcher();
|
| 311 |
|
| 312 | if (datawatcher.hasObjectChanged())
|
| 313 | {
|
| 314 | this.func_151261_b(new S1CPacketEntityMetadata(this.trackedEntity.getEntityId(), datawatcher, false));
|
| 315 | }
|
| 316 |
|
| 317 | if (this.trackedEntity instanceof EntityLivingBase)
|
| 318 | {
|
| 319 | ServersideAttributeMap serversideattributemap = (ServersideAttributeMap)((EntityLivingBase)this.trackedEntity).getAttributeMap();
|
| 320 | Set<IAttributeInstance> set = serversideattributemap.getAttributeInstanceSet();
|
| 321 |
|
| 322 | if (!set.isEmpty())
|
| 323 | {
|
| 324 | this.func_151261_b(new S20PacketEntityProperties(this.trackedEntity.getEntityId(), set));
|
| 325 | }
|
| 326 |
|
| 327 | set.clear();
|
| 328 | }
|
| 329 | }
|
| 330 |
|
| 331 | /**
|
| 332 | * Send the given packet to all players tracking this entity.
|
| 333 | */
|
| 334 | public void sendPacketToTrackedPlayers(Packet packetIn)
|
| 335 | {
|
| 336 | for (EntityPlayerMP entityplayermp : this.trackingPlayers)
|
| 337 | {
|
| 338 | entityplayermp.playerNetServerHandler.sendPacket(packetIn);
|
| 339 | }
|
| 340 | }
|
| 341 |
|
| 342 | public void func_151261_b(Packet packetIn)
|
| 343 | {
|
| 344 | this.sendPacketToTrackedPlayers(packetIn);
|
| 345 |
|
| 346 | if (this.trackedEntity instanceof EntityPlayerMP)
|
| 347 | {
|
| 348 | ((EntityPlayerMP)this.trackedEntity).playerNetServerHandler.sendPacket(packetIn);
|
| 349 | }
|
| 350 | }
|
| 351 |
|
| 352 | public void sendDestroyEntityPacketToTrackedPlayers()
|
| 353 | {
|
| 354 | for (EntityPlayerMP entityplayermp : this.trackingPlayers)
|
| 355 | {
|
| 356 | entityplayermp.removeEntity(this.trackedEntity);
|
| 357 | }
|
| 358 | }
|
| 359 |
|
| 360 | public void removeFromTrackedPlayers(EntityPlayerMP playerMP)
|
| 361 | {
|
| 362 | if (this.trackingPlayers.contains(playerMP))
|
| 363 | {
|
| 364 | playerMP.removeEntity(this.trackedEntity);
|
| 365 | this.trackingPlayers.remove(playerMP);
|
| 366 | }
|
| 367 | }
|
| 368 |
|
| 369 | public void updatePlayerEntity(EntityPlayerMP playerMP)
|
| 370 | {
|
| 371 | if (playerMP != this.trackedEntity)
|
| 372 | {
|
| 373 | if (this.func_180233_c(playerMP))
|
| 374 | {
|
| 375 | if (!this.trackingPlayers.contains(playerMP) && (this.isPlayerWatchingThisChunk(playerMP) || this.trackedEntity.forceSpawn))
|
| 376 | {
|
| 377 | this.trackingPlayers.add(playerMP);
|
| 378 | Packet packet = this.createSpawnPacket();
|
| 379 | playerMP.playerNetServerHandler.sendPacket(packet);
|
| 380 |
|
| 381 | if (!this.trackedEntity.getDataWatcher().getIsBlank())
|
| 382 | {
|
| 383 | playerMP.playerNetServerHandler.sendPacket(new S1CPacketEntityMetadata(this.trackedEntity.getEntityId(), this.trackedEntity.getDataWatcher(), true));
|
| 384 | }
|
| 385 |
|
| 386 | NBTTagCompound nbttagcompound = this.trackedEntity.getNBTTagCompound();
|
| 387 |
|
| 388 | if (nbttagcompound != null)
|
| 389 | {
|
| 390 | playerMP.playerNetServerHandler.sendPacket(new S49PacketUpdateEntityNBT(this.trackedEntity.getEntityId(), nbttagcompound));
|
| 391 | }
|
| 392 |
|
| 393 | if (this.trackedEntity instanceof EntityLivingBase)
|
| 394 | {
|
| 395 | ServersideAttributeMap serversideattributemap = (ServersideAttributeMap)((EntityLivingBase)this.trackedEntity).getAttributeMap();
|
| 396 | Collection<IAttributeInstance> collection = serversideattributemap.getWatchedAttributes();
|
| 397 |
|
| 398 | if (!collection.isEmpty())
|
| 399 | {
|
| 400 | playerMP.playerNetServerHandler.sendPacket(new S20PacketEntityProperties(this.trackedEntity.getEntityId(), collection));
|
| 401 | }
|
| 402 | }
|
| 403 |
|
| 404 | this.lastTrackedEntityMotionX = this.trackedEntity.motionX;
|
| 405 | this.lastTrackedEntityMotionY = this.trackedEntity.motionY;
|
| 406 | this.motionZ = this.trackedEntity.motionZ;
|
| 407 |
|
| 408 | if (this.sendVelocityUpdates && !(packet instanceof S0FPacketSpawnMob))
|
| 409 | {
|
| 410 | playerMP.playerNetServerHandler.sendPacket(new S12PacketEntityVelocity(this.trackedEntity.getEntityId(), this.trackedEntity.motionX, this.trackedEntity.motionY, this.trackedEntity.motionZ));
|
| 411 | }
|
| 412 |
|
| 413 | if (this.trackedEntity.ridingEntity != null)
|
| 414 | {
|
| 415 | playerMP.playerNetServerHandler.sendPacket(new S1BPacketEntityAttach(0, this.trackedEntity, this.trackedEntity.ridingEntity));
|
| 416 | }
|
| 417 |
|
| 418 | if (this.trackedEntity instanceof EntityLiving && ((EntityLiving)this.trackedEntity).getLeashedToEntity() != null)
|
| 419 | {
|
| 420 | playerMP.playerNetServerHandler.sendPacket(new S1BPacketEntityAttach(1, this.trackedEntity, ((EntityLiving)this.trackedEntity).getLeashedToEntity()));
|
| 421 | }
|
| 422 |
|
| 423 | if (this.trackedEntity instanceof EntityLivingBase)
|
| 424 | {
|
| 425 | for (int i = 0; i < 5; ++i)
|
| 426 | {
|
| 427 | ItemStack itemstack = ((EntityLivingBase)this.trackedEntity).getEquipmentInSlot(i);
|
| 428 |
|
| 429 | if (itemstack != null)
|
| 430 | {
|
| 431 | playerMP.playerNetServerHandler.sendPacket(new S04PacketEntityEquipment(this.trackedEntity.getEntityId(), i, itemstack));
|
| 432 | }
|
| 433 | }
|
| 434 | }
|
| 435 |
|
| 436 | if (this.trackedEntity instanceof EntityPlayer)
|
| 437 | {
|
| 438 | EntityPlayer entityplayer = (EntityPlayer)this.trackedEntity;
|
| 439 |
|
| 440 | if (entityplayer.isPlayerSleeping())
|
| 441 | {
|
| 442 | playerMP.playerNetServerHandler.sendPacket(new S0APacketUseBed(entityplayer, new BlockPos(this.trackedEntity)));
|
| 443 | }
|
| 444 | }
|
| 445 |
|
| 446 | if (this.trackedEntity instanceof EntityLivingBase)
|
| 447 | {
|
| 448 | EntityLivingBase entitylivingbase = (EntityLivingBase)this.trackedEntity;
|
| 449 |
|
| 450 | for (PotionEffect potioneffect : entitylivingbase.getActivePotionEffects())
|
| 451 | {
|
| 452 | playerMP.playerNetServerHandler.sendPacket(new S1DPacketEntityEffect(this.trackedEntity.getEntityId(), potioneffect));
|
| 453 | }
|
| 454 | }
|
| 455 | }
|
| 456 | }
|
| 457 | else if (this.trackingPlayers.contains(playerMP))
|
| 458 | {
|
| 459 | this.trackingPlayers.remove(playerMP);
|
| 460 | playerMP.removeEntity(this.trackedEntity);
|
| 461 | }
|
| 462 | }
|
| 463 | }
|
| 464 |
|
| 465 | public boolean func_180233_c(EntityPlayerMP playerMP)
|
| 466 | {
|
| 467 | double d0 = playerMP.posX - (double)(this.encodedPosX / 32);
|
| 468 | double d1 = playerMP.posZ - (double)(this.encodedPosZ / 32);
|
| 469 | return d0 >= (double)(-this.trackingDistanceThreshold) && d0 <= (double)this.trackingDistanceThreshold && d1 >= (double)(-this.trackingDistanceThreshold) && d1 <= (double)this.trackingDistanceThreshold && this.trackedEntity.isSpectatedByPlayer(playerMP);
|
| 470 | }
|
| 471 |
|
| 472 | private boolean isPlayerWatchingThisChunk(EntityPlayerMP playerMP)
|
| 473 | {
|
| 474 | return playerMP.getServerForPlayer().getPlayerManager().isPlayerWatchingChunk(playerMP, this.trackedEntity.chunkCoordX, this.trackedEntity.chunkCoordZ);
|
| 475 | }
|
| 476 |
|
| 477 | public void updatePlayerEntities(List<EntityPlayer> players)
|
| 478 | {
|
| 479 | for (int i = 0; i < players.size(); ++i)
|
| 480 | {
|
| 481 | this.updatePlayerEntity((EntityPlayerMP)players.get(i));
|
| 482 | }
|
| 483 | }
|
| 484 |
|
| 485 | /**
|
| 486 | * Creates a spawn packet for the entity managed by this entry.
|
| 487 | */
|
| 488 | private Packet createSpawnPacket()
|
| 489 | {
|
| 490 | if (this.trackedEntity.isDead)
|
| 491 | {
|
| 492 | logger.warn("Fetching addPacket for removed entity");
|
| 493 | }
|
| 494 |
|
| 495 | if (this.trackedEntity instanceof EntityItem)
|
| 496 | {
|
| 497 | return new S0EPacketSpawnObject(this.trackedEntity, 2, 1);
|
| 498 | }
|
| 499 | else if (this.trackedEntity instanceof EntityPlayerMP)
|
| 500 | {
|
| 501 | return new S0CPacketSpawnPlayer((EntityPlayer)this.trackedEntity);
|
| 502 | }
|
| 503 | else if (this.trackedEntity instanceof EntityMinecart)
|
| 504 | {
|
| 505 | EntityMinecart entityminecart = (EntityMinecart)this.trackedEntity;
|
| 506 | return new S0EPacketSpawnObject(this.trackedEntity, 10, entityminecart.getMinecartType().getNetworkID());
|
| 507 | }
|
| 508 | else if (this.trackedEntity instanceof EntityBoat)
|
| 509 | {
|
| 510 | return new S0EPacketSpawnObject(this.trackedEntity, 1);
|
| 511 | }
|
| 512 | else if (this.trackedEntity instanceof IAnimals)
|
| 513 | {
|
| 514 | this.lastHeadMotion = MathHelper.floor_float(this.trackedEntity.getRotationYawHead() * 256.0F / 360.0F);
|
| 515 | return new S0FPacketSpawnMob((EntityLivingBase)this.trackedEntity);
|
| 516 | }
|
| 517 | else if (this.trackedEntity instanceof EntityFishHook)
|
| 518 | {
|
| 519 | Entity entity1 = ((EntityFishHook)this.trackedEntity).angler;
|
| 520 | return new S0EPacketSpawnObject(this.trackedEntity, 90, entity1 != null ? entity1.getEntityId() : this.trackedEntity.getEntityId());
|
| 521 | }
|
| 522 | else if (this.trackedEntity instanceof EntityArrow)
|
| 523 | {
|
| 524 | Entity entity = ((EntityArrow)this.trackedEntity).shootingEntity;
|
| 525 | return new S0EPacketSpawnObject(this.trackedEntity, 60, entity != null ? entity.getEntityId() : this.trackedEntity.getEntityId());
|
| 526 | }
|
| 527 | else if (this.trackedEntity instanceof EntitySnowball)
|
| 528 | {
|
| 529 | return new S0EPacketSpawnObject(this.trackedEntity, 61);
|
| 530 | }
|
| 531 | else if (this.trackedEntity instanceof EntityPotion)
|
| 532 | {
|
| 533 | return new S0EPacketSpawnObject(this.trackedEntity, 73, ((EntityPotion)this.trackedEntity).getPotionDamage());
|
| 534 | }
|
| 535 | else if (this.trackedEntity instanceof EntityExpBottle)
|
| 536 | {
|
| 537 | return new S0EPacketSpawnObject(this.trackedEntity, 75);
|
| 538 | }
|
| 539 | else if (this.trackedEntity instanceof EntityEnderPearl)
|
| 540 | {
|
| 541 | return new S0EPacketSpawnObject(this.trackedEntity, 65);
|
| 542 | }
|
| 543 | else if (this.trackedEntity instanceof EntityEnderEye)
|
| 544 | {
|
| 545 | return new S0EPacketSpawnObject(this.trackedEntity, 72);
|
| 546 | }
|
| 547 | else if (this.trackedEntity instanceof EntityFireworkRocket)
|
| 548 | {
|
| 549 | return new S0EPacketSpawnObject(this.trackedEntity, 76);
|
| 550 | }
|
| 551 | else if (this.trackedEntity instanceof EntityFireball)
|
| 552 | {
|
| 553 | EntityFireball entityfireball = (EntityFireball)this.trackedEntity;
|
| 554 | S0EPacketSpawnObject s0epacketspawnobject2 = null;
|
| 555 | int i = 63;
|
| 556 |
|
| 557 | if (this.trackedEntity instanceof EntitySmallFireball)
|
| 558 | {
|
| 559 | i = 64;
|
| 560 | }
|
| 561 | else if (this.trackedEntity instanceof EntityWitherSkull)
|
| 562 | {
|
| 563 | i = 66;
|
| 564 | }
|
| 565 |
|
| 566 | if (entityfireball.shootingEntity != null)
|
| 567 | {
|
| 568 | s0epacketspawnobject2 = new S0EPacketSpawnObject(this.trackedEntity, i, ((EntityFireball)this.trackedEntity).shootingEntity.getEntityId());
|
| 569 | }
|
| 570 | else
|
| 571 | {
|
| 572 | s0epacketspawnobject2 = new S0EPacketSpawnObject(this.trackedEntity, i, 0);
|
| 573 | }
|
| 574 |
|
| 575 | s0epacketspawnobject2.setSpeedX((int)(entityfireball.accelerationX * 8000.0D));
|
| 576 | s0epacketspawnobject2.setSpeedY((int)(entityfireball.accelerationY * 8000.0D));
|
| 577 | s0epacketspawnobject2.setSpeedZ((int)(entityfireball.accelerationZ * 8000.0D));
|
| 578 | return s0epacketspawnobject2;
|
| 579 | }
|
| 580 | else if (this.trackedEntity instanceof EntityEgg)
|
| 581 | {
|
| 582 | return new S0EPacketSpawnObject(this.trackedEntity, 62);
|
| 583 | }
|
| 584 | else if (this.trackedEntity instanceof EntityTNTPrimed)
|
| 585 | {
|
| 586 | return new S0EPacketSpawnObject(this.trackedEntity, 50);
|
| 587 | }
|
| 588 | else if (this.trackedEntity instanceof EntityEnderCrystal)
|
| 589 | {
|
| 590 | return new S0EPacketSpawnObject(this.trackedEntity, 51);
|
| 591 | }
|
| 592 | else if (this.trackedEntity instanceof EntityFallingBlock)
|
| 593 | {
|
| 594 | EntityFallingBlock entityfallingblock = (EntityFallingBlock)this.trackedEntity;
|
| 595 | return new S0EPacketSpawnObject(this.trackedEntity, 70, Block.getStateId(entityfallingblock.getBlock()));
|
| 596 | }
|
| 597 | else if (this.trackedEntity instanceof EntityArmorStand)
|
| 598 | {
|
| 599 | return new S0EPacketSpawnObject(this.trackedEntity, 78);
|
| 600 | }
|
| 601 | else if (this.trackedEntity instanceof EntityPainting)
|
| 602 | {
|
| 603 | return new S10PacketSpawnPainting((EntityPainting)this.trackedEntity);
|
| 604 | }
|
| 605 | else if (this.trackedEntity instanceof EntityItemFrame)
|
| 606 | {
|
| 607 | EntityItemFrame entityitemframe = (EntityItemFrame)this.trackedEntity;
|
| 608 | S0EPacketSpawnObject s0epacketspawnobject1 = new S0EPacketSpawnObject(this.trackedEntity, 71, entityitemframe.facingDirection.getHorizontalIndex());
|
| 609 | BlockPos blockpos1 = entityitemframe.getHangingPosition();
|
| 610 | s0epacketspawnobject1.setX(MathHelper.floor_float((float)(blockpos1.getX() * 32)));
|
| 611 | s0epacketspawnobject1.setY(MathHelper.floor_float((float)(blockpos1.getY() * 32)));
|
| 612 | s0epacketspawnobject1.setZ(MathHelper.floor_float((float)(blockpos1.getZ() * 32)));
|
| 613 | return s0epacketspawnobject1;
|
| 614 | }
|
| 615 | else if (this.trackedEntity instanceof EntityLeashKnot)
|
| 616 | {
|
| 617 | EntityLeashKnot entityleashknot = (EntityLeashKnot)this.trackedEntity;
|
| 618 | S0EPacketSpawnObject s0epacketspawnobject = new S0EPacketSpawnObject(this.trackedEntity, 77);
|
| 619 | BlockPos blockpos = entityleashknot.getHangingPosition();
|
| 620 | s0epacketspawnobject.setX(MathHelper.floor_float((float)(blockpos.getX() * 32)));
|
| 621 | s0epacketspawnobject.setY(MathHelper.floor_float((float)(blockpos.getY() * 32)));
|
| 622 | s0epacketspawnobject.setZ(MathHelper.floor_float((float)(blockpos.getZ() * 32)));
|
| 623 | return s0epacketspawnobject;
|
| 624 | }
|
| 625 | else if (this.trackedEntity instanceof EntityXPOrb)
|
| 626 | {
|
| 627 | return new S11PacketSpawnExperienceOrb((EntityXPOrb)this.trackedEntity);
|
| 628 | }
|
| 629 | else
|
| 630 | {
|
| 631 | throw new IllegalArgumentException("Don\'t know how to add " + this.trackedEntity.getClass() + "!");
|
| 632 | }
|
| 633 | }
|
| 634 |
|
| 635 | /**
|
| 636 | * Remove a tracked player from our list and tell the tracked player to destroy us from their world.
|
| 637 | */
|
| 638 | public void removeTrackedPlayerSymmetric(EntityPlayerMP playerMP)
|
| 639 | {
|
| 640 | if (this.trackingPlayers.contains(playerMP))
|
| 641 | {
|
| 642 | this.trackingPlayers.remove(playerMP);
|
| 643 | playerMP.removeEntity(this.trackedEntity);
|
| 644 | }
|
| 645 | }
|
| 646 | }
|
| 647 |
|