Search in sources :

Example 16 with Vector3ic

use of org.joml.Vector3ic in project Terasology by MovingBlocks.

the class BulkLightPropagationTest method testReduceLight.

@Test
public void testReduceLight() {
    StubPropagatorWorldView worldView = new StubPropagatorWorldView(testingRegion, air);
    worldView.setBlockAt(new Vector3i(0, 0, 0), fullLight);
    BatchPropagator propagator = new StandardBatchPropagator(lightRules, worldView);
    propagator.process(new BlockChange(ZERO_VECTOR, air, fullLight));
    worldView.setBlockAt(new Vector3i(0, 0, 0), weakLight);
    propagator.process(new BlockChange(ZERO_VECTOR, fullLight, weakLight));
    assertEquals(weakLight.getLuminance(), worldView.getValueAt(new Vector3i(0, 0, 0)));
    for (int i = 1; i < 15; ++i) {
        byte expectedLuminance = (byte) Math.max(0, weakLight.getLuminance() - i);
        for (Vector3ic pos : Diamond3iIterable.shell(new Vector3i(0, 0, 0), i).build()) {
            assertEquals(expectedLuminance, worldView.getValueAt(pos));
        }
    }
}
Also used : Vector3ic(org.joml.Vector3ic) Vector3i(org.joml.Vector3i) Test(org.junit.jupiter.api.Test)

Example 17 with Vector3ic

use of org.joml.Vector3ic in project Terasology by MovingBlocks.

the class BulkLightPropagationTest method testAddLightInLight.

@Test
public void testAddLightInLight() {
    StubPropagatorWorldView worldView = new StubPropagatorWorldView(testingRegion, air);
    worldView.setBlockAt(new Vector3i(2, 0, 0), mediumLight);
    BatchPropagator propagator = new StandardBatchPropagator(lightRules, worldView);
    propagator.process(new BlockChange(new Vector3i(2, 0, 0), air, mediumLight));
    worldView.setBlockAt(new Vector3i(0, 0, 0), fullLight);
    propagator.process(new BlockChange(ZERO_VECTOR, air, fullLight));
    for (int i = 0; i < fullLight.getLuminance() + 1; ++i) {
        byte expectedLuminance = (byte) Math.max(0, fullLight.getLuminance() - i);
        for (Vector3ic pos : Diamond3iIterable.shell(new Vector3i(0, 0, 0), i).build()) {
            assertEquals(expectedLuminance, worldView.getValueAt(pos));
        }
    }
}
Also used : Vector3ic(org.joml.Vector3ic) Vector3i(org.joml.Vector3i) Test(org.junit.jupiter.api.Test)

Example 18 with Vector3ic

use of org.joml.Vector3ic in project Terasology by MovingBlocks.

the class BulkLightPropagationTest method testRemoveLightInVacuum.

@Test
public void testRemoveLightInVacuum() {
    StubPropagatorWorldView worldView = new StubPropagatorWorldView(testingRegion, air);
    worldView.setBlockAt(new Vector3i(0, 0, 0), fullLight);
    BatchPropagator propagator = new StandardBatchPropagator(lightRules, worldView);
    propagator.process(new BlockChange(ZERO_VECTOR, air, fullLight));
    worldView.setBlockAt(new Vector3i(0, 0, 0), air);
    propagator.process(new BlockChange(ZERO_VECTOR, fullLight, air));
    assertEquals(0, worldView.getValueAt(new Vector3i(0, 0, 0)));
    for (int i = 1; i < fullLight.getLuminance(); ++i) {
        for (Vector3ic pos : Diamond3iIterable.shell(new Vector3i(0, 0, 0), i).build()) {
            assertEquals(0, worldView.getValueAt(pos));
        }
    }
}
Also used : Vector3ic(org.joml.Vector3ic) Vector3i(org.joml.Vector3i) Test(org.junit.jupiter.api.Test)

Example 19 with Vector3ic

use of org.joml.Vector3ic in project Terasology by MovingBlocks.

the class BulkLightPropagationTest method testRemoveSolidAllowsLight.

@Test
public void testRemoveSolidAllowsLight() {
    StubPropagatorWorldView worldView = new StubPropagatorWorldView(testingRegion, air);
    for (Vector3ic pos : new BlockRegion(1, 0, 0).expand(0, 30, 30)) {
        worldView.setBlockAt(new Vector3i(pos), solid);
    }
    worldView.setBlockAt(new Vector3i(0, 0, 0), fullLight);
    BatchPropagator propagator = new StandardBatchPropagator(lightRules, worldView);
    propagator.process(new BlockChange(ZERO_VECTOR, 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 : Vector3ic(org.joml.Vector3ic) Vector3i(org.joml.Vector3i) BlockRegion(org.terasology.engine.world.block.BlockRegion) Test(org.junit.jupiter.api.Test)

Example 20 with Vector3ic

use of org.joml.Vector3ic in project Terasology by MovingBlocks.

the class BlockRegionTest method testBoxOfBlocksRegion.

@Test
public void testBoxOfBlocksRegion() {
    BlockRegion region = new BlockRegion(new Vector3i(0, 0, 0), new Vector3i(1, 1, 1));
    List<Vector3ic> actual = new ArrayList<>();
    for (Vector3ic vector3ic : region) {
        actual.add(new Vector3i(vector3ic));
    }
    Assertions.assertEquals(8, actual.size());
    Assertions.assertEquals(new HashSet<>(expectedPositions(region)), new HashSet<>(actual));
}
Also used : Vector3ic(org.joml.Vector3ic) Vector3i(org.joml.Vector3i) ArrayList(java.util.ArrayList) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

Vector3ic (org.joml.Vector3ic)87 Vector3i (org.joml.Vector3i)52 Test (org.junit.jupiter.api.Test)35 BlockRegion (org.terasology.engine.world.block.BlockRegion)28 Chunk (org.terasology.engine.world.chunks.Chunk)28 ChunkImpl (org.terasology.engine.world.chunks.internal.ChunkImpl)16 Block (org.terasology.engine.world.block.Block)12 ReceiveEvent (org.terasology.engine.entitySystem.event.ReceiveEvent)11 Map (java.util.Map)8 Lists (com.google.common.collect.Lists)5 List (java.util.List)5 EntityRef (org.terasology.engine.entitySystem.entity.EntityRef)5 LocationComponent (org.terasology.engine.logic.location.LocationComponent)5 BlockRegionComponent (org.terasology.engine.world.block.regions.BlockRegionComponent)5 Maps (com.google.common.collect.Maps)4 Sets (com.google.common.collect.Sets)4 ArrayList (java.util.ArrayList)4 Collections (java.util.Collections)4 Set (java.util.Set)4 Vector3f (org.joml.Vector3f)4