use of pneumaticCraft.common.network.PacketDescription in project PneumaticCraft by MineMaarten.
the class SemiBlockManager method syncWithPlayers.
private void syncWithPlayers(World world) {
List<EntityPlayerMP> players = world.playerEntities;
for (Map.Entry<Chunk, Set<EntityPlayerMP>> entry : syncList.entrySet()) {
Chunk chunk = entry.getKey();
Set<EntityPlayerMP> syncedPlayers = entry.getValue();
int chunkX = chunk.xPosition * 16 - 8;
int chunkZ = chunk.zPosition * 16 - 8;
for (EntityPlayerMP player : players) {
if (chunk.worldObj == world) {
double dist = PneumaticCraftUtils.distBetween(player.posX, 0, player.posZ, chunkX, 0, chunkZ);
if (dist < SYNC_DISTANCE) {
if (syncedPlayers.add(player)) {
for (ISemiBlock semiBlock : semiBlocks.get(chunk).values()) {
if (!semiBlock.isInvalid()) {
NetworkHandler.sendTo(new PacketSetSemiBlock(semiBlock), player);
PacketDescription descPacket = semiBlock.getDescriptionPacket();
if (descPacket != null)
NetworkHandler.sendTo(descPacket, player);
}
}
}
} else if (dist > SYNC_DISTANCE + 5) {
syncedPlayers.remove(player);
}
} else {
syncedPlayers.remove(player);
}
}
}
}
use of pneumaticCraft.common.network.PacketDescription in project PneumaticCraft by MineMaarten.
the class SemiBlockManager method onServerTick.
@SubscribeEvent
public void onServerTick(TickEvent.ServerTickEvent event) {
for (ISemiBlock semiBlock : addingBlocks) {
Chunk chunk = semiBlock.getWorld().getChunkFromBlockCoords(semiBlock.getPos().chunkPosX, semiBlock.getPos().chunkPosZ);
getOrCreateMap(chunk).put(semiBlock.getPos(), semiBlock);
chunk.setChunkModified();
for (EntityPlayerMP player : syncList.get(chunk)) {
NetworkHandler.sendTo(new PacketSetSemiBlock(semiBlock), player);
PacketDescription descPacket = semiBlock.getDescriptionPacket();
if (descPacket != null)
NetworkHandler.sendTo(descPacket, player);
}
}
addingBlocks.clear();
for (Chunk removingChunk : chunksMarkedForRemoval) {
if (!removingChunk.isChunkLoaded) {
semiBlocks.remove(removingChunk);
syncList.remove(removingChunk);
}
}
chunksMarkedForRemoval.clear();
for (Map<ChunkPosition, ISemiBlock> map : semiBlocks.values()) {
for (ISemiBlock semiBlock : map.values()) {
if (!semiBlock.isInvalid())
semiBlock.update();
}
Iterator<ISemiBlock> iterator = map.values().iterator();
while (iterator.hasNext()) {
if (iterator.next().isInvalid()) {
iterator.remove();
}
}
}
}
Aggregations