Search in sources :

Example 16 with ChunkImpl

use of org.terasology.world.chunks.internal.ChunkImpl in project Terasology by MovingBlocks.

the class InternalLightGeneratorTest method testUnblockedSunlightPropagationAfterHittingMaxRegen.

@Test
public void testUnblockedSunlightPropagationAfterHittingMaxRegen() {
    Chunk chunk = new ChunkImpl(0, 0, 0, blockManager, biomeManager);
    InternalLightProcessor.generateInternalLighting(chunk);
    for (Vector3i pos : Region3i.createFromMinAndSize(new Vector3i(0, 15, 0), new Vector3i(ChunkConstants.SIZE_X, ChunkConstants.SIZE_Y - 15, ChunkConstants.SIZE_Z))) {
        assertEquals(0, chunk.getSunlight(pos));
    }
    for (Vector3i pos : Region3i.createFromMinAndSize(Vector3i.zero(), new Vector3i(ChunkConstants.SIZE_X, ChunkConstants.SIZE_Y - ChunkConstants.MAX_SUNLIGHT_REGEN, ChunkConstants.SIZE_Z))) {
        byte expectedSunlight = (byte) Math.min(ChunkConstants.SIZE_Y - ChunkConstants.SUNLIGHT_REGEN_THRESHOLD - pos.y - 1, ChunkConstants.MAX_SUNLIGHT);
        assertEquals("Incorrect lighting at " + pos, expectedSunlight, chunk.getSunlight(pos));
    }
}
Also used : ChunkImpl(org.terasology.world.chunks.internal.ChunkImpl) Vector3i(org.terasology.math.geom.Vector3i) Chunk(org.terasology.world.chunks.Chunk) Test(org.junit.Test)

Example 17 with ChunkImpl

use of org.terasology.world.chunks.internal.ChunkImpl in project Terasology by MovingBlocks.

the class BetweenChunkPropagationTest method testBetweenChunksSimpleSunlightRegenOnly.

@Test
public void testBetweenChunksSimpleSunlightRegenOnly() {
    Chunk topChunk = new ChunkImpl(new Vector3i(0, 1, 0), blockManager, biomeManager);
    Chunk bottomChunk = new ChunkImpl(new Vector3i(0, 0, 0), blockManager, biomeManager);
    provider.addChunk(topChunk);
    provider.addChunk(bottomChunk);
    for (Vector3i pos : Region3i.createFromMinAndSize(new Vector3i(0, 0, 0), new Vector3i(ChunkConstants.SIZE_X, 1, ChunkConstants.SIZE_Z))) {
        topChunk.setSunlight(pos, ChunkConstants.MAX_SUNLIGHT);
        topChunk.setSunlightRegen(pos, ChunkConstants.MAX_SUNLIGHT_REGEN);
    }
    InternalLightProcessor.generateInternalLighting(bottomChunk);
    propagator.propagateBetween(topChunk, bottomChunk, Side.BOTTOM, true);
    propagator.process();
    for (Vector3i pos : ChunkConstants.CHUNK_REGION) {
        assertEquals("Incorrect at position " + pos, ChunkConstants.MAX_SUNLIGHT_REGEN, bottomChunk.getSunlightRegen(pos));
    }
}
Also used : ChunkImpl(org.terasology.world.chunks.internal.ChunkImpl) Vector3i(org.terasology.math.geom.Vector3i) Chunk(org.terasology.world.chunks.Chunk) Test(org.junit.Test)

Example 18 with ChunkImpl

use of org.terasology.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, biomeManager);
    Chunk bottomChunk = new ChunkImpl(new Vector3i(0, 0, 0), blockManager, biomeManager);
    provider.addChunk(topChunk);
    provider.addChunk(bottomChunk);
    for (Vector3i pos : Region3i.createFromMinAndSize(new Vector3i(0, 0, 0), new Vector3i(ChunkConstants.SIZE_X, 1, ChunkConstants.SIZE_Z))) {
        topChunk.setSunlight(pos, ChunkConstants.MAX_SUNLIGHT);
        topChunk.setSunlightRegen(pos, ChunkConstants.MAX_SUNLIGHT_REGEN);
    }
    InternalLightProcessor.generateInternalLighting(bottomChunk);
    propagator.propagateBetween(topChunk, bottomChunk, Side.BOTTOM, true);
    propagator.process();
    sunlightPropagator.process();
    for (Vector3i pos : ChunkConstants.CHUNK_REGION) {
        assertEquals("Incorrect at position " + pos, ChunkConstants.MAX_SUNLIGHT, bottomChunk.getSunlight(pos));
        assertEquals("Incorrect at position " + pos, ChunkConstants.MAX_SUNLIGHT_REGEN, bottomChunk.getSunlightRegen(pos));
    }
}
Also used : ChunkImpl(org.terasology.world.chunks.internal.ChunkImpl) Vector3i(org.terasology.math.geom.Vector3i) Chunk(org.terasology.world.chunks.Chunk) Test(org.junit.Test)

Example 19 with ChunkImpl

use of org.terasology.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, biomeManager);
    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(Matchers.any(Vector3i.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, biomeManager, storeChunkInZips);
    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));
}
Also used : EngineEntityManager(org.terasology.entitySystem.entity.internal.EngineEntityManager) ChunkImpl(org.terasology.world.chunks.internal.ChunkImpl) Vector3i(org.terasology.math.geom.Vector3i) StorageManager(org.terasology.persistence.StorageManager) Chunk(org.terasology.world.chunks.Chunk) ChunkProvider(org.terasology.world.chunks.ChunkProvider) ChunkStore(org.terasology.persistence.ChunkStore) Test(org.junit.Test)

Example 20 with ChunkImpl

use of org.terasology.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, biomeManager);
    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.world.chunks.internal.ChunkImpl) Chunk(org.terasology.world.chunks.Chunk) ChunkProvider(org.terasology.world.chunks.ChunkProvider) ChunkStore(org.terasology.persistence.ChunkStore) Test(org.junit.Test)

Aggregations

ChunkImpl (org.terasology.world.chunks.internal.ChunkImpl)22 Vector3i (org.terasology.math.geom.Vector3i)18 Chunk (org.terasology.world.chunks.Chunk)18 Test (org.junit.Test)15 ChunkStore (org.terasology.persistence.ChunkStore)4 EntityRef (org.terasology.entitySystem.entity.EntityRef)3 ChunkProvider (org.terasology.world.chunks.ChunkProvider)3 Map (java.util.Map)2 EngineEntityManager (org.terasology.entitySystem.entity.internal.EngineEntityManager)2 StorageManager (org.terasology.persistence.StorageManager)2 Block (org.terasology.world.block.Block)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 TShortObjectMap (gnu.trove.map.TShortObjectMap)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 ConcurrentMap (java.util.concurrent.ConcurrentMap)1 Before (org.junit.Before)1 ResourceUrn (org.terasology.assets.ResourceUrn)1 AssetManager (org.terasology.assets.management.AssetManager)1 LocationComponent (org.terasology.logic.location.LocationComponent)1