use of org.terasology.engine.world.chunks.internal.ChunkImpl in project Terasology by MovingBlocks.
the class StorageManagerTest method testStoreAndRestoreChunkStore.
@Test
public void testStoreAndRestoreChunkStore() {
Chunk chunk = new ChunkImpl(CHUNK_POS, blockManager, extraDataManager);
chunk.setBlock(0, 0, 0, testBlock);
chunk.markReady();
ChunkProvider chunkProvider = mock(ChunkProvider.class);
when(chunkProvider.getAllChunks()).thenReturn(Arrays.asList(chunk));
CoreRegistry.put(ChunkProvider.class, chunkProvider);
esm.waitForCompletionOfPreviousSaveAndStartSaving();
esm.finishSavingAndShutdown();
ChunkStore restored = esm.loadChunkStore(CHUNK_POS);
assertNotNull(restored);
assertEquals(CHUNK_POS, restored.getChunkPosition());
assertNotNull(restored.getChunk());
assertEquals(testBlock, restored.getChunk().getBlock(0, 0, 0));
}
use of org.terasology.engine.world.chunks.internal.ChunkImpl in project Terasology by MovingBlocks.
the class LocalChunkProviderTest method testLoadSingleChunk.
@Test
void testLoadSingleChunk() throws InterruptedException, ExecutionException, TimeoutException {
Vector3i chunkPosition = new Vector3i(0, 0, 0);
Chunk chunk = new ChunkImpl(chunkPosition, blockManager, extraDataManager);
generator.createChunk(chunk, null);
storageManager.add(chunk);
requestCreatingOrLoadingArea(chunkPosition).get(WAIT_CHUNK_IS_READY_IN_SECONDS, TimeUnit.SECONDS);
chunkProvider.update();
Assertions.assertTrue(((TestChunkStore) storageManager.loadChunkStore(chunkPosition)).isEntityRestored(), "Entities must be restored by loading");
final ArgumentCaptor<Event> eventArgumentCaptor = ArgumentCaptor.forClass(Event.class);
verify(worldEntity, atLeast(1)).send(eventArgumentCaptor.capture());
Event mustBeOnLoadedEvent = eventArgumentCaptor.getAllValues().get(0);
Assertions.assertTrue(mustBeOnLoadedEvent instanceof OnChunkLoaded, "Second world event must be OnChunkLoaded");
Assertions.assertEquals(chunkPosition, ((OnChunkLoaded) mustBeOnLoadedEvent).getChunkPos(), "Chunk position at event not expected");
}
use of org.terasology.engine.world.chunks.internal.ChunkImpl in project Terasology by MovingBlocks.
the class LocalChunkProviderTest method testLoadSingleChunkWithBlockLifecycle.
@Test
void testLoadSingleChunkWithBlockLifecycle() throws InterruptedException, ExecutionException, TimeoutException {
Vector3i chunkPosition = new Vector3i(0, 0, 0);
Chunk chunk = new ChunkImpl(chunkPosition, blockManager, extraDataManager);
generator.createChunk(chunk, null);
storageManager.add(chunk);
blockAtBlockManager.setLifecycleEventsRequired(true);
blockAtBlockManager.setEntity(mock(EntityRef.class));
requestCreatingOrLoadingArea(chunkPosition).get(WAIT_CHUNK_IS_READY_IN_SECONDS, TimeUnit.SECONDS);
chunkProvider.update();
Assertions.assertTrue(((TestChunkStore) storageManager.loadChunkStore(chunkPosition)).isEntityRestored(), "Entities must be restored by loading");
final ArgumentCaptor<Event> eventArgumentCaptor = ArgumentCaptor.forClass(Event.class);
verify(worldEntity, atLeast(1)).send(eventArgumentCaptor.capture());
Event mustBeOnLoadedEvent = eventArgumentCaptor.getAllValues().get(0);
Assertions.assertTrue(mustBeOnLoadedEvent instanceof OnChunkLoaded, "Second world event must be OnChunkLoaded");
Assertions.assertEquals(chunkPosition, ((OnChunkLoaded) mustBeOnLoadedEvent).getChunkPos(), "Chunk position at event not expected");
// TODO, it is not clear if the activate/addedBlocks event logic is correct.
// See https://github.com/MovingBlocks/Terasology/issues/3244
final ArgumentCaptor<Event> blockEventCaptor = ArgumentCaptor.forClass(Event.class);
verify(blockAtBlockManager.getEntity(), atLeast(2)).send(blockEventCaptor.capture());
Assertions.assertAll("Block events not valid", () -> {
Event mustBeOnAddedBlocks = blockEventCaptor.getAllValues().get(0);
Assertions.assertTrue(mustBeOnAddedBlocks instanceof OnAddedBlocks, "First block event must be OnAddedBlocks");
Assertions.assertTrue(((OnAddedBlocks) mustBeOnAddedBlocks).blockCount() > 0, "Block count on activate must be non zero");
}, () -> {
Event mustBeOnActivatedBlocks = blockEventCaptor.getAllValues().get(1);
Assertions.assertTrue(mustBeOnActivatedBlocks instanceof OnActivatedBlocks, "First block event must be OnActivatedBlocks");
Assertions.assertTrue(((OnActivatedBlocks) mustBeOnActivatedBlocks).blockCount() > 0, "Block count on activate must be non zero");
});
}
use of org.terasology.engine.world.chunks.internal.ChunkImpl in project Terasology by MovingBlocks.
the class InternalLightGeneratorTest method testBlockedAtTopSunlightRegenPropagationResets.
@Test
public void testBlockedAtTopSunlightRegenPropagationResets() {
Chunk chunk = new ChunkImpl(0, 0, 0, blockManager, extraDataManager);
for (Vector3ic pos : new BlockRegion(0, 63, 0).setSize(Chunks.SIZE_X, 1, Chunks.SIZE_Z)) {
chunk.setBlock(pos, solidBlock);
}
InternalLightProcessor.generateInternalLighting(chunk);
for (Vector3ic pos : new BlockRegion(0, 0, 0).setSize(Chunks.SIZE_X, Chunks.SIZE_Y - 1, Chunks.SIZE_Z)) {
byte expectedRegen = (byte) Math.min(Chunks.SIZE_Y - pos.y() - 2, 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 InternalLightGeneratorTest method testUnblockedSunlightPropagation.
@Test
public void testUnblockedSunlightPropagation() {
Chunk chunk = new ChunkImpl(0, 0, 0, blockManager, extraDataManager);
InternalLightProcessor.generateInternalLighting(chunk);
for (Vector3ic pos : new BlockRegion(0, 0, 0).setSize(Chunks.SIZE_X, 15, Chunks.SIZE_Z)) {
assertEquals(15 - pos.y(), chunk.getSunlight(pos), () -> "Incorrect lighting at " + pos);
}
}
Aggregations