use of org.terasology.math.geom.Vector3i in project Terasology by MovingBlocks.
the class NetClient method sendChunkInvalidations.
private void sendChunkInvalidations(NetData.NetMessage.Builder message) {
Iterator<Vector3i> i = invalidatedChunks.iterator();
while (i.hasNext()) {
Vector3i pos = i.next();
i.remove();
relevantChunks.remove(pos);
message.addInvalidateChunk(NetData.InvalidateChunkMessage.newBuilder().setPos(NetMessageUtil.convert(pos)));
}
invalidatedChunks.clear();
}
use of org.terasology.math.geom.Vector3i in project Terasology by MovingBlocks.
the class ServerImpl method processBiomeChanges.
private void processBiomeChanges(NetData.NetMessage message) {
for (NetData.BiomeChangeMessage biomeChange : message.getBiomeChangeList()) {
logger.debug("Received block change to {}", blockManager.getBlock((short) biomeChange.getNewBiome()));
// TODO: Store changes to blocks that aren't ready to be modified (the surrounding chunks aren't available)
WorldProvider worldProvider = CoreRegistry.get(WorldProvider.class);
Vector3i pos = NetMessageUtil.convert(biomeChange.getPos());
if (worldProvider.isBlockRelevant(pos)) {
Biome newBiome = biomeManager.getBiomeByShortId((short) biomeChange.getNewBiome());
worldProvider.setBiome(pos, newBiome);
} else {
awaitingChunkReadyBiomeUpdates.put(ChunkMath.calcChunkPos(pos), biomeChange);
}
}
}
use of org.terasology.math.geom.Vector3i in project Terasology by MovingBlocks.
the class ServerImpl method processBlockChanges.
private void processBlockChanges(NetData.NetMessage message) {
for (NetData.BlockChangeMessage blockChange : message.getBlockChangeList()) {
Block newBlock = blockManager.getBlock((short) blockChange.getNewBlock());
logger.debug("Received block change to {}", newBlock);
// TODO: Store changes to blocks that aren't ready to be modified (the surrounding chunks aren't available)
WorldProvider worldProvider = CoreRegistry.get(WorldProvider.class);
Vector3i pos = NetMessageUtil.convert(blockChange.getPos());
if (worldProvider.isBlockRelevant(pos)) {
worldProvider.setBlock(pos, newBlock);
} else {
awaitingChunkReadyBlockUpdates.put(ChunkMath.calcChunkPos(pos), blockChange);
}
}
}
use of org.terasology.math.geom.Vector3i in project Terasology by MovingBlocks.
the class NetEntityRefTypeHandler method deserialize.
@Override
public EntityRef deserialize(PersistedData data, DeserializationContext context) {
if (data.isArray()) {
PersistedDataArray array = data.getAsArray();
if (array.isNumberArray() && array.size() == 3) {
TIntList items = data.getAsArray().getAsIntegerArray();
Vector3i pos = new Vector3i(items.get(0), items.get(1), items.get(2));
return blockEntityRegistry.getBlockEntityAt(pos);
}
}
if (data.isNumber()) {
return networkSystem.getEntity(data.getAsInteger());
}
return EntityRef.NULL;
}
use of org.terasology.math.geom.Vector3i in project Terasology by MovingBlocks.
the class NetEntityRefTypeHandler method serializeCollection.
@Override
public PersistedData serializeCollection(Collection<EntityRef> value, SerializationContext context) {
List<PersistedData> items = Lists.newArrayList();
for (EntityRef ref : value) {
BlockComponent blockComponent = ref.getComponent(BlockComponent.class);
if (blockComponent != null) {
Vector3i blockPos = blockComponent.getPosition();
items.add(context.create(blockPos.x, blockPos.y, blockPos.z));
} else {
NetworkComponent netComponent = ref.getComponent(NetworkComponent.class);
if (netComponent != null) {
items.add(context.create(netComponent.getNetworkId()));
} else {
items.add(context.createNull());
}
}
}
return context.create(items);
}
Aggregations