use of org.terasology.engine.persistence.ChunkStore in project Terasology by MovingBlocks.
the class LocalChunkProvider method processReadyChunk.
private void processReadyChunk(final Chunk chunk) {
Vector3ic chunkPos = chunk.getPosition();
if (chunkCache.get(chunkPos) != null) {
// TODO move it in pipeline;
return;
}
chunkCache.put(new Vector3i(chunkPos), chunk);
chunk.markReady();
// TODO, it is not clear if the activate/addedBlocks event logic is correct.
// See https://github.com/MovingBlocks/Terasology/issues/3244
ChunkStore store = this.storageManager.loadChunkStore(chunkPos);
TShortObjectMap<TIntList> mappings = createBatchBlockEventMappings(chunk);
if (store != null) {
store.restoreEntities();
PerformanceMonitor.startActivity("Sending OnAddedBlocks");
mappings.forEachEntry((id, positions) -> {
if (positions.size() > 0) {
blockManager.getBlock(id).getEntity().send(new OnAddedBlocks(positions, registry));
}
return true;
});
PerformanceMonitor.endActivity();
// send on activate
PerformanceMonitor.startActivity("Sending OnActivateBlocks");
mappings.forEachEntry((id, positions) -> {
if (positions.size() > 0) {
blockManager.getBlock(id).getEntity().send(new OnActivatedBlocks(positions, registry));
}
return true;
});
PerformanceMonitor.endActivity();
} else {
PerformanceMonitor.startActivity("Generating queued Entities");
generateQueuedEntities.remove(chunkPos).forEach(this::generateQueuedEntities);
PerformanceMonitor.endActivity();
// send on activate
PerformanceMonitor.startActivity("Sending OnActivateBlocks");
mappings.forEachEntry((id, positions) -> {
if (positions.size() > 0) {
blockManager.getBlock(id).getEntity().send(new OnActivatedBlocks(positions, registry));
}
return true;
});
PerformanceMonitor.endActivity();
worldEntity.send(new OnChunkGenerated(chunkPos));
}
worldEntity.send(new OnChunkLoaded(chunkPos));
}
Aggregations