Search in sources :

Example 96 with Vector3i

use of org.terasology.math.geom.Vector3i in project Terasology by MovingBlocks.

the class BetweenChunkPropagationTest method testPropagateSunlightAppearingMidChunk.

@Test
public void testPropagateSunlightAppearingMidChunk() {
    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, (byte) 0);
        topChunk.setSunlightRegen(pos, (byte) 0);
    }
    for (Vector3i pos : Region3i.createFromMinAndSize(new Vector3i(8, 0, 8), new Vector3i(ChunkConstants.SIZE_X - 16, 1, ChunkConstants.SIZE_Z - 16))) {
        topChunk.setSunlight(pos, (byte) 0);
        topChunk.setSunlightRegen(pos, (byte) 32);
    }
    InternalLightProcessor.generateInternalLighting(bottomChunk);
    propagator.propagateBetween(topChunk, bottomChunk, Side.BOTTOM, false);
    propagator.process();
    sunlightPropagator.process();
    for (int i = 0; i < 15; ++i) {
        assertEquals("Incorrect value at " + (33 + i), 14 - i, bottomChunk.getSunlight(7, 33 + i, 16));
    }
    for (int i = 2; i < 33; ++i) {
        assertEquals("Incorrect value at " + i, 14, bottomChunk.getSunlight(7, i, 16));
    }
}
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 97 with Vector3i

use of org.terasology.math.geom.Vector3i in project Terasology by MovingBlocks.

the class BetweenChunkPropagationTest method testBetweenChunksWithOverhang.

@Test
public void testBetweenChunksWithOverhang() {
    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);
    }
    for (Vector3i pos : Region3i.createFromMinMax(new Vector3i(16, 48, 0), new Vector3i(31, 48, 31))) {
        bottomChunk.setBlock(pos, solid);
    }
    InternalLightProcessor.generateInternalLighting(bottomChunk);
    propagator.propagateBetween(topChunk, bottomChunk, Side.BOTTOM, false);
    propagator.process();
    sunlightPropagator.process();
    for (int z = 0; z < ChunkConstants.SIZE_Z; ++z) {
        assertEquals(14, bottomChunk.getSunlight(16, 47, z));
    }
    for (int z = 0; z < ChunkConstants.SIZE_Z; ++z) {
        assertEquals(13, bottomChunk.getSunlight(17, 47, z));
    }
}
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 98 with Vector3i

use of org.terasology.math.geom.Vector3i in project Terasology by MovingBlocks.

the class BulkLightPropagationTest method testRemoveOverlappingLight.

@Test
public void testRemoveOverlappingLight() {
    Vector3i lightPos = new Vector3i(5, 0, 0);
    StubPropagatorWorldView worldView = new StubPropagatorWorldView(testingRegion, air);
    worldView.setBlockAt(Vector3i.zero(), fullLight);
    worldView.setBlockAt(lightPos, fullLight);
    BatchPropagator propagator = new StandardBatchPropagator(lightRules, worldView);
    propagator.process(new BlockChange(Vector3i.zero(), air, fullLight), new BlockChange(lightPos, air, fullLight));
    worldView.setBlockAt(lightPos, air);
    propagator.process(new BlockChange(lightPos, fullLight, air));
    for (int i = 0; i < 16; ++i) {
        byte expectedLuminance = (byte) Math.max(0, fullLight.getLuminance() - i);
        for (Vector3i pos : Diamond3iIterator.iterateAtDistance(Vector3i.zero(), i)) {
            assertEquals(expectedLuminance, worldView.getValueAt(pos));
        }
    }
}
Also used : Vector3i(org.terasology.math.geom.Vector3i) Test(org.junit.Test)

Example 99 with Vector3i

use of org.terasology.math.geom.Vector3i in project Terasology by MovingBlocks.

the class BulkLightPropagationTest method testRemoveSolidAllowsLight.

@Test
public void testRemoveSolidAllowsLight() {
    StubPropagatorWorldView worldView = new StubPropagatorWorldView(testingRegion, air);
    for (Vector3i pos : Region3i.createFromCenterExtents(new Vector3i(1, 0, 0), new Vector3i(0, 30, 30))) {
        worldView.setBlockAt(pos, solid);
    }
    worldView.setBlockAt(new Vector3i(0, 0, 0), fullLight);
    BatchPropagator propagator = new StandardBatchPropagator(lightRules, worldView);
    propagator.process(new BlockChange(new Vector3i(0, 0, 0), air, fullLight));
    assertEquals(0, worldView.getValueAt(new Vector3i(1, 0, 0)));
    worldView.setBlockAt(new Vector3i(1, 0, 0), air);
    propagator.process(new BlockChange(new Vector3i(1, 0, 0), solid, air));
    assertEquals(14, worldView.getValueAt(new Vector3i(1, 0, 0)));
    assertEquals(13, worldView.getValueAt(new Vector3i(2, 0, 0)));
}
Also used : Vector3i(org.terasology.math.geom.Vector3i) Test(org.junit.Test)

Example 100 with Vector3i

use of org.terasology.math.geom.Vector3i in project Terasology by MovingBlocks.

the class BulkLightPropagationTest method testAddWeakLightNextToStrongLight.

@Test
public void testAddWeakLightNextToStrongLight() {
    StubPropagatorWorldView worldView = new StubPropagatorWorldView(testingRegion, air);
    worldView.setBlockAt(new Vector3i(0, 0, 0), fullLight);
    BatchPropagator propagator = new StandardBatchPropagator(lightRules, worldView);
    propagator.process(new BlockChange(new Vector3i(0, 0, 0), air, fullLight));
    worldView.setBlockAt(new Vector3i(1, 0, 0), weakLight);
    propagator.process(new BlockChange(new Vector3i(1, 0, 0), air, weakLight));
    assertEquals(14, worldView.getValueAt(new Vector3i(1, 0, 0)));
}
Also used : Vector3i(org.terasology.math.geom.Vector3i) Test(org.junit.Test)

Aggregations

Vector3i (org.terasology.math.geom.Vector3i)246 Test (org.junit.Test)91 EntityRef (org.terasology.entitySystem.entity.EntityRef)34 Block (org.terasology.world.block.Block)32 Chunk (org.terasology.world.chunks.Chunk)30 Vector3f (org.terasology.math.geom.Vector3f)21 ReceiveEvent (org.terasology.entitySystem.event.ReceiveEvent)17 ChunkImpl (org.terasology.world.chunks.internal.ChunkImpl)17 Region3i (org.terasology.math.Region3i)15 BaseVector3i (org.terasology.math.geom.BaseVector3i)15 LocationComponent (org.terasology.logic.location.LocationComponent)14 BlockComponent (org.terasology.world.block.BlockComponent)10 Side (org.terasology.math.Side)9 ChunkViewCoreImpl (org.terasology.world.internal.ChunkViewCoreImpl)8 Before (org.junit.Before)7 Biome (org.terasology.world.biomes.Biome)7 HashMap (java.util.HashMap)6 Map (java.util.Map)6 CoreChunk (org.terasology.world.chunks.CoreChunk)6 RenderableChunk (org.terasology.world.chunks.RenderableChunk)6