use of pneumaticCraft.common.network.PacketSetSemiBlock 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.PacketSetSemiBlock in project PneumaticCraft by MineMaarten.
the class SemiBlockLogistics method onRightClickWithConfigurator.
@Override
public boolean onRightClickWithConfigurator(EntityPlayer player) {
if (getGuiID() != null) {
NetworkHandler.sendTo(new PacketSetSemiBlock(pos, this), (EntityPlayerMP) player);
player.openGui(PneumaticCraft.instance, getGuiID().ordinal(), world, pos.chunkPosX, pos.chunkPosY, pos.chunkPosZ);
}
return true;
}
use of pneumaticCraft.common.network.PacketSetSemiBlock 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();
}
}
}
}
use of pneumaticCraft.common.network.PacketSetSemiBlock in project PneumaticCraft by MineMaarten.
the class SemiBlockManager method setSemiBlock.
private void setSemiBlock(World world, int x, int y, int z, ISemiBlock semiBlock, Chunk chunk) {
if (semiBlock != null && !registeredTypes.containsValue(semiBlock.getClass()))
throw new IllegalStateException("ISemiBlock \"" + semiBlock + "\" was not registered!");
ChunkPosition pos = new ChunkPosition(x, y, z);
if (semiBlock != null) {
semiBlock.initialize(world, pos);
addingBlocks.add(semiBlock);
} else {
ISemiBlock removedBlock = getOrCreateMap(chunk).get(pos);
if (removedBlock != null) {
removedBlock.invalidate();
for (EntityPlayerMP player : syncList.get(chunk)) {
NetworkHandler.sendTo(new PacketSetSemiBlock(pos, null), player);
}
}
}
chunk.setChunkModified();
}
Aggregations