use of org.terasology.engine.world.chunks.internal.ChunkImpl in project Terasology by MovingBlocks.
the class InternalLightGeneratorTest method testUnblockedSunlightRegenPropagation.
@Test
public void testUnblockedSunlightRegenPropagation() {
Chunk chunk = new ChunkImpl(0, 0, 0, blockManager, extraDataManager);
InternalLightProcessor.generateInternalLighting(chunk);
for (Vector3ic pos : new BlockRegion(0, 0, 0).setSize(Chunks.SIZE_X, Chunks.SIZE_Y, Chunks.SIZE_Z)) {
byte expectedRegen = (byte) Math.min(Chunks.SIZE_Y - pos.y() - 1, Chunks.MAX_SUNLIGHT_REGEN);
assertEquals(expectedRegen, chunk.getSunlightRegen(pos));
}
}
use of org.terasology.engine.world.chunks.internal.ChunkImpl in project Terasology by MovingBlocks.
the class BetweenChunkPropagationTest method testBetweenChunksSimple.
@Test
public void testBetweenChunksSimple() {
Chunk topChunk = new ChunkImpl(new Vector3i(0, 1, 0), blockManager, extraDataManager);
Chunk bottomChunk = new ChunkImpl(new Vector3i(0, 0, 0), blockManager, extraDataManager);
provider.addChunk(topChunk);
provider.addChunk(bottomChunk);
for (Vector3ic pos : new BlockRegion(0, 0, 0).setSize(Chunks.SIZE_X, 1, Chunks.SIZE_Z)) {
topChunk.setSunlight(pos, Chunks.MAX_SUNLIGHT);
topChunk.setSunlightRegen(pos, Chunks.MAX_SUNLIGHT_REGEN);
}
InternalLightProcessor.generateInternalLighting(bottomChunk);
propagator.propagateBetween(topChunk, bottomChunk, Side.BOTTOM, true);
propagator.process();
sunlightPropagator.process();
for (Vector3ic pos : Chunks.CHUNK_REGION) {
assertEquals(Chunks.MAX_SUNLIGHT, bottomChunk.getSunlight(pos), () -> "Incorrect at position " + pos);
assertEquals(Chunks.MAX_SUNLIGHT_REGEN, bottomChunk.getSunlightRegen(pos), () -> "Incorrect at position " + pos);
}
}
use of org.terasology.engine.world.chunks.internal.ChunkImpl in project Terasology by MovingBlocks.
the class MapWorldProvider method getBlock.
@Override
public Block getBlock(int x, int y, int z) {
Vector3i pos = new Vector3i(x, y, z);
Block block = blocks.get(pos);
if (block != null) {
return block;
}
// TODO block manager
Vector3i chunkPos = Chunks.toChunkPos(pos, new Vector3i());
Chunk chunk = chunks.get(chunkPos);
if (chunk == null && worldGenerator != null) {
chunk = new ChunkImpl(chunkPos, blockManager, extraDataManager);
worldGenerator.createChunk(chunk, entityBuffer);
chunks.put(chunkPos, chunk);
}
if (chunk != null) {
return chunk.getBlock(Chunks.toRelative(pos, pos));
}
return null;
}
use of org.terasology.engine.world.chunks.internal.ChunkImpl in project Terasology by MovingBlocks.
the class LocalChunkProvider method createOrLoadChunk.
protected ListenableFuture<Chunk> createOrLoadChunk(Vector3ic chunkPos) {
Vector3i pos = new Vector3i(chunkPos);
return loadingPipeline.invokeGeneratorTask(pos, () -> {
ChunkStore chunkStore = storageManager.loadChunkStore(pos);
Chunk chunk;
EntityBufferImpl buffer = new EntityBufferImpl();
if (chunkStore == null) {
chunk = new ChunkImpl(pos, blockManager, extraDataManager);
generator.createChunk(chunk, buffer);
generateQueuedEntities.put(chunk.getPosition(new Vector3i()), buffer.getAll());
} else {
chunk = chunkStore.getChunk();
}
return chunk;
});
}
use of org.terasology.engine.world.chunks.internal.ChunkImpl in project Terasology by MovingBlocks.
the class StorageManagerTest method testChunkSurvivesStorageSaveAndRestore.
@Test
public void testChunkSurvivesStorageSaveAndRestore() throws Exception {
Chunk chunk = new ChunkImpl(CHUNK_POS, blockManager, extraDataManager);
chunk.setBlock(0, 0, 0, testBlock);
chunk.setBlock(0, 4, 2, testBlock2);
chunk.markReady();
ChunkProvider chunkProvider = mock(ChunkProvider.class);
when(chunkProvider.getAllChunks()).thenReturn(Arrays.asList(chunk));
when(chunkProvider.getChunk(ArgumentMatchers.any(Vector3ic.class))).thenReturn(chunk);
CoreRegistry.put(ChunkProvider.class, chunkProvider);
boolean storeChunkInZips = true;
esm.setStoreChunksInZips(storeChunkInZips);
esm.waitForCompletionOfPreviousSaveAndStartSaving();
esm.finishSavingAndShutdown();
EntitySystemSetupUtil.addReflectionBasedLibraries(context);
EntitySystemSetupUtil.addEntityManagementRelatedClasses(context);
EngineEntityManager newEntityManager = context.get(EngineEntityManager.class);
StorageManager newSM = new ReadWriteStorageManager(savePath, moduleEnvironment, newEntityManager, blockManager, extraDataManager, storeChunkInZips, recordAndReplaySerializer, recordAndReplayUtils, recordAndReplayCurrentStatus);
newSM.loadGlobalStore();
ChunkStore restored = newSM.loadChunkStore(CHUNK_POS);
assertNotNull(restored);
assertEquals(CHUNK_POS, restored.getChunkPosition());
assertNotNull(restored.getChunk());
assertEquals(testBlock, restored.getChunk().getBlock(0, 0, 0));
assertEquals(testBlock2, restored.getChunk().getBlock(0, 4, 2));
}
Aggregations