use of net.minecraft.entity.EntityTracker in project SpongeCommon by SpongePowered.
the class MixinEntity method spongeOnUpdate.
@Inject(method = "onUpdate", at = @At("RETURN"))
private void spongeOnUpdate(CallbackInfo callbackInfo) {
if (this.pendingVisibilityUpdate && !this.world.isRemote) {
final EntityTracker entityTracker = ((WorldServer) this.world).getEntityTracker();
final EntityTrackerEntry lookup = entityTracker.trackedEntityHashTable.lookup(this.getEntityId());
if (this.visibilityTicks % 4 == 0) {
if (this.isVanished) {
for (EntityPlayerMP entityPlayerMP : lookup.trackingPlayers) {
entityPlayerMP.connection.sendPacket(new SPacketDestroyEntities(this.getEntityId()));
if (((Object) this) instanceof EntityPlayerMP) {
entityPlayerMP.connection.sendPacket(new SPacketPlayerListItem(SPacketPlayerListItem.Action.REMOVE_PLAYER, (EntityPlayerMP) (Object) this));
}
}
} else {
this.visibilityTicks = 1;
this.pendingVisibilityUpdate = false;
for (EntityPlayerMP entityPlayerMP : SpongeImpl.getServer().getPlayerList().getPlayers()) {
if (((Object) this) == entityPlayerMP) {
continue;
}
if (((Object) this) instanceof EntityPlayerMP) {
Packet<?> packet = new SPacketPlayerListItem(SPacketPlayerListItem.Action.ADD_PLAYER, (EntityPlayerMP) (Object) this);
entityPlayerMP.connection.sendPacket(packet);
}
// creates the spawn packet for us
Packet<?> newPacket = lookup.createSpawnPacket();
entityPlayerMP.connection.sendPacket(newPacket);
}
}
}
if (this.visibilityTicks > 0) {
this.visibilityTicks--;
} else {
this.pendingVisibilityUpdate = false;
}
}
}
use of net.minecraft.entity.EntityTracker in project SpongeCommon by SpongePowered.
the class EntityUtil method refreshPainting.
public static boolean refreshPainting(EntityPainting painting, EntityPainting.EnumArt art) {
EntityPainting.EnumArt oldArt = painting.art;
painting.art = art;
painting.updateFacingWithBoundingBox(painting.facingDirection);
if (!painting.onValidSurface()) {
painting.art = oldArt;
painting.updateFacingWithBoundingBox(painting.facingDirection);
return false;
}
final EntityTracker paintingTracker = ((WorldServer) painting.world).getEntityTracker();
EntityTrackerEntry paintingEntry = paintingTracker.trackedEntityHashTable.lookup(painting.getEntityId());
List<EntityPlayerMP> playerMPs = new ArrayList<>();
for (EntityPlayerMP player : paintingEntry.trackingPlayers) {
SPacketDestroyEntities packet = new SPacketDestroyEntities(painting.getEntityId());
player.connection.sendPacket(packet);
playerMPs.add(player);
}
for (EntityPlayerMP playerMP : playerMPs) {
SpongeImpl.getGame().getScheduler().createTaskBuilder().delayTicks(SpongeImpl.getGlobalConfig().getConfig().getEntity().getPaintingRespawnDelaly()).execute(() -> {
final SPacketSpawnPainting packet = new SPacketSpawnPainting(painting);
playerMP.connection.sendPacket(packet);
}).submit(SpongeImpl.getPlugin());
}
return true;
}
use of net.minecraft.entity.EntityTracker in project Random-Things by lumien231.
the class EntityProjectedItem method onCollideWithPlayer.
/**
* Called by a player entity when they collide with an entity
*/
@Override
public void onCollideWithPlayer(EntityPlayer entityIn) {
if (!this.world.isRemote && this.canBePickedUp) {
ItemStack itemstack = this.getItem();
int i = itemstack.getCount();
if (i <= 0 || entityIn.inventory.addItemStackToInventory(itemstack)) {
if (!this.isSilent()) {
this.world.playSound((EntityPlayer) null, entityIn.posX, entityIn.posY, entityIn.posZ, SoundEvents.ENTITY_ITEM_PICKUP, SoundCategory.PLAYERS, 0.2F, ((this.rand.nextFloat() - this.rand.nextFloat()) * 0.7F + 1.0F) * 2.0F);
}
entityIn.onItemPickup(this, i);
if (!this.world.isRemote) {
EntityTracker entitytracker = ((WorldServer) this.world).getEntityTracker();
entitytracker.sendToTracking(this, new SPacketCollectItem(this.getEntityId(), entityIn.getEntityId(), this.getItem().getCount()));
}
if (itemstack.getCount() <= 0) {
this.setDead();
}
entityIn.addStat(StatList.getObjectsPickedUpStats(itemstack.getItem()), i);
}
}
}
Aggregations