Search in sources :

Example 41 with Chunk

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

the class InternalLightGeneratorTest method testHorizontalSunlightPropagation.

@Test
public void testHorizontalSunlightPropagation() {
    Chunk chunk = new ChunkImpl(0, 0, 0, blockManager, biomeManager);
    for (Vector3i pos : Region3i.createFromMinAndSize(new Vector3i(0, 4, 0), new Vector3i(ChunkConstants.SIZE_X, 1, ChunkConstants.SIZE_Z))) {
        chunk.setBlock(pos, solidBlock);
    }
    chunk.setBlock(new Vector3i(16, 4, 16), airBlock);
    InternalLightProcessor.generateInternalLighting(chunk);
    assertEquals(12, chunk.getSunlight(16, 3, 16));
    assertEquals(11, chunk.getSunlight(15, 3, 16));
    assertEquals(11, chunk.getSunlight(17, 3, 16));
    assertEquals(11, chunk.getSunlight(16, 3, 15));
    assertEquals(11, chunk.getSunlight(16, 3, 17));
    assertEquals(12, chunk.getSunlight(15, 2, 16));
    assertEquals(12, chunk.getSunlight(17, 2, 16));
    assertEquals(12, chunk.getSunlight(16, 2, 15));
    assertEquals(12, chunk.getSunlight(16, 2, 17));
}
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 42 with Chunk

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

the class InternalLightGeneratorTest method testLightPropagation.

@Test
public void testLightPropagation() {
    Chunk chunk = new ChunkImpl(0, 0, 0, blockManager, biomeManager);
    chunk.setBlock(16, 32, 16, fullLight);
    InternalLightProcessor.generateInternalLighting(chunk);
    assertEquals(fullLight.getLuminance(), chunk.getLight(16, 32, 16));
    assertEquals(fullLight.getLuminance() - 1, chunk.getLight(new Vector3i(16, 33, 16)));
    for (int i = 1; i < fullLight.getLuminance(); ++i) {
        for (Vector3i pos : Diamond3iIterator.iterateAtDistance(new Vector3i(16, 32, 16), i)) {
            assertEquals(fullLight.getLuminance() - i, chunk.getLight(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 43 with Chunk

use of org.terasology.world.chunks.Chunk 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 44 with Chunk

use of org.terasology.world.chunks.Chunk 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 45 with Chunk

use of org.terasology.world.chunks.Chunk 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)

Aggregations

Chunk (org.terasology.world.chunks.Chunk)50 Vector3i (org.terasology.math.geom.Vector3i)31 Test (org.junit.Test)28 ChunkImpl (org.terasology.world.chunks.internal.ChunkImpl)18 ReadyChunkInfo (org.terasology.world.chunks.internal.ReadyChunkInfo)9 ManagedChunk (org.terasology.world.chunks.ManagedChunk)8 ChunkViewCoreImpl (org.terasology.world.internal.ChunkViewCoreImpl)8 ChunkStore (org.terasology.persistence.ChunkStore)7 EntityRef (org.terasology.entitySystem.entity.EntityRef)5 ChunkViewCore (org.terasology.world.internal.ChunkViewCore)5 ChunkProvider (org.terasology.world.chunks.ChunkProvider)3 TIntList (gnu.trove.list.TIntList)2 TShortObjectHashMap (gnu.trove.map.hash.TShortObjectHashMap)2 EntityStore (org.terasology.entitySystem.entity.EntityStore)2 EngineEntityManager (org.terasology.entitySystem.entity.internal.EngineEntityManager)2 Event (org.terasology.entitySystem.event.Event)2 LocationComponent (org.terasology.logic.location.LocationComponent)2 Side (org.terasology.math.Side)2 StorageManager (org.terasology.persistence.StorageManager)2 Block (org.terasology.world.block.Block)2