Search in sources :

Example 11 with ChunkImpl

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));
}
Also used : ChunkImpl(org.terasology.engine.world.chunks.internal.ChunkImpl) Chunk(org.terasology.engine.world.chunks.Chunk) ChunkProvider(org.terasology.engine.world.chunks.ChunkProvider) ChunkStore(org.terasology.engine.persistence.ChunkStore) Test(org.junit.jupiter.api.Test)

Example 12 with ChunkImpl

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");
}
Also used : OnChunkLoaded(org.terasology.engine.world.chunks.event.OnChunkLoaded) ChunkImpl(org.terasology.engine.world.chunks.internal.ChunkImpl) Vector3i(org.joml.Vector3i) Event(org.terasology.engine.entitySystem.event.Event) Chunk(org.terasology.engine.world.chunks.Chunk) Test(org.junit.jupiter.api.Test)

Example 13 with ChunkImpl

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");
    });
}
Also used : OnChunkLoaded(org.terasology.engine.world.chunks.event.OnChunkLoaded) OnActivatedBlocks(org.terasology.engine.world.block.OnActivatedBlocks) ChunkImpl(org.terasology.engine.world.chunks.internal.ChunkImpl) Vector3i(org.joml.Vector3i) Event(org.terasology.engine.entitySystem.event.Event) OnAddedBlocks(org.terasology.engine.world.block.OnAddedBlocks) Chunk(org.terasology.engine.world.chunks.Chunk) EntityRef(org.terasology.engine.entitySystem.entity.EntityRef) Test(org.junit.jupiter.api.Test)

Example 14 with ChunkImpl

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));
    }
}
Also used : ChunkImpl(org.terasology.engine.world.chunks.internal.ChunkImpl) Vector3ic(org.joml.Vector3ic) BlockRegion(org.terasology.engine.world.block.BlockRegion) Chunk(org.terasology.engine.world.chunks.Chunk) Test(org.junit.jupiter.api.Test)

Example 15 with ChunkImpl

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);
    }
}
Also used : ChunkImpl(org.terasology.engine.world.chunks.internal.ChunkImpl) Vector3ic(org.joml.Vector3ic) BlockRegion(org.terasology.engine.world.block.BlockRegion) Chunk(org.terasology.engine.world.chunks.Chunk) Test(org.junit.jupiter.api.Test)

Aggregations

ChunkImpl (org.terasology.engine.world.chunks.internal.ChunkImpl)23 Chunk (org.terasology.engine.world.chunks.Chunk)19 Test (org.junit.jupiter.api.Test)17 Vector3i (org.joml.Vector3i)14 Vector3ic (org.joml.Vector3ic)14 BlockRegion (org.terasology.engine.world.block.BlockRegion)11 EntityRef (org.terasology.engine.entitySystem.entity.EntityRef)4 ChunkStore (org.terasology.engine.persistence.ChunkStore)4 ChunkProvider (org.terasology.engine.world.chunks.ChunkProvider)3 Map (java.util.Map)2 EngineEntityManager (org.terasology.engine.entitySystem.entity.internal.EngineEntityManager)2 Event (org.terasology.engine.entitySystem.event.Event)2 StorageManager (org.terasology.engine.persistence.StorageManager)2 OnChunkLoaded (org.terasology.engine.world.chunks.event.OnChunkLoaded)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 Collection (java.util.Collection)1 ConcurrentMap (java.util.concurrent.ConcurrentMap)1 Vector3f (org.joml.Vector3f)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1 LocationComponent (org.terasology.engine.logic.location.LocationComponent)1