use of org.terasology.world.chunks.Chunk in project Terasology by MovingBlocks.
the class RenderableWorldImpl method onChunkLoaded.
@Override
public void onChunkLoaded(Vector3i chunkCoordinates) {
if (renderableRegion.encompasses(chunkCoordinates)) {
Chunk chunk = chunkProvider.getChunk(chunkCoordinates);
if (chunk != null) {
chunksInProximityOfCamera.add(chunk);
Collections.sort(chunksInProximityOfCamera, new ChunkFrontToBackComparator());
} else {
logger.warn("Warning: onChunkLoaded called for a null chunk!");
}
}
}
use of org.terasology.world.chunks.Chunk in project Terasology by MovingBlocks.
the class ServerImpl method processReceivedChunks.
private void processReceivedChunks() {
if (remoteWorldProvider != null) {
List<Chunk> chunks = Lists.newArrayListWithExpectedSize(chunkQueue.size());
chunkQueue.drainTo(chunks);
for (Chunk chunk : chunks) {
remoteWorldProvider.receiveChunk(chunk);
}
}
}
use of org.terasology.world.chunks.Chunk in project Terasology by MovingBlocks.
the class LocalChunkProvider method createWorldView.
private ChunkViewCore createWorldView(Region3i region, Vector3i offset) {
Chunk[] chunks = new Chunk[region.sizeX() * region.sizeY() * region.sizeZ()];
for (Vector3i chunkPos : region) {
Chunk chunk = chunkCache.get(chunkPos);
if (chunk == null) {
return null;
}
chunkPos.sub(region.minX(), region.minY(), region.minZ());
int index = TeraMath.calculate3DArrayIndex(chunkPos, region.size());
chunks[index] = chunk;
}
return new ChunkViewCoreImpl(chunks, region, offset, blockManager.getBlock(BlockManager.AIR_ID));
}
use of org.terasology.world.chunks.Chunk in project Terasology by MovingBlocks.
the class LocalChunkProvider method createOrLoadChunk.
private void createOrLoadChunk(Vector3i chunkPos) {
Chunk chunk = chunkCache.get(chunkPos);
if (chunk == null && !preparingChunks.contains(chunkPos)) {
preparingChunks.add(chunkPos);
pipeline.doTask(new AbstractChunkTask(chunkPos) {
@Override
public String getName() {
return "Create or Load Chunk";
}
@Override
public void run() {
ChunkStore chunkStore = storageManager.loadChunkStore(getPosition());
Chunk chunk;
EntityBufferImpl buffer = new EntityBufferImpl();
if (chunkStore == null) {
chunk = new ChunkImpl(getPosition(), blockManager, biomeManager);
generator.createChunk(chunk, buffer);
} else {
chunk = chunkStore.getChunk();
}
InternalLightProcessor.generateInternalLighting(chunk);
chunk.deflate();
TShortObjectMap<TIntList> mappings = createBatchBlockEventMappings(chunk);
readyChunks.offer(new ReadyChunkInfo(chunk, mappings, chunkStore, buffer.getAll()));
}
});
}
}
use of org.terasology.world.chunks.Chunk in project Terasology by MovingBlocks.
the class LocalChunkProvider method dispose.
@Override
public void dispose() {
shutdown();
for (Chunk chunk : chunkCache.getAllChunks()) {
unloadChunkInternal(chunk.getPosition());
chunk.dispose();
}
chunkCache.clear();
/*
* The chunk monitor needs to clear chunk references, so it's important
* that no new chunk get created
*/
ChunkMonitor.fireChunkProviderDisposed(this);
}
Aggregations