Search in sources :

Example 1 with Vector3i

use of org.joml.Vector3i in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.

the class VSIterationUtilsTest method testIterator3d.

@Test
public void testIterator3d() {
    Iterator<Vector3i> iterator = new VSIterationUtils.Int3dIterator(-10, -10, -10, 10, 10, 10);
    List<Vector3i> iVals = new ArrayList<>();
    List<Vector3i> oVals = new ArrayList<>();
    while (iterator.hasNext()) {
        Vector3i vec = iterator.next();
        iVals.add(vec);
    }
    VSIterationUtils.iterate3d(-10, -10, -10, 10, 10, 10, (x, y, z) -> oVals.add(new Vector3i(x, y, z)));
    assertThat(iVals, containsInAnyOrder(oVals.toArray()));
}
Also used : Vector3i(org.joml.Vector3i) ArrayList(java.util.ArrayList) Test(org.junit.jupiter.api.Test)

Example 2 with Vector3i

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

the class LocalChunkProviderTest method testGenerateSingleChunkWithBlockLifeCycle.

@Test
void testGenerateSingleChunkWithBlockLifeCycle() throws InterruptedException, ExecutionException, TimeoutException {
    Vector3i chunkPosition = new Vector3i(0, 0, 0);
    blockAtBlockManager.setLifecycleEventsRequired(true);
    blockAtBlockManager.setEntity(mock(EntityRef.class));
    requestCreatingOrLoadingArea(chunkPosition).get(WAIT_CHUNK_IS_READY_IN_SECONDS, TimeUnit.SECONDS);
    chunkProvider.update();
    final ArgumentCaptor<Event> worldEventCaptor = ArgumentCaptor.forClass(Event.class);
    verify(worldEntity, atLeast(2)).send(worldEventCaptor.capture());
    Assertions.assertAll("World Events not valid", () -> {
        Event mustBeOnGeneratedEvent = worldEventCaptor.getAllValues().get(0);
        Assertions.assertTrue(mustBeOnGeneratedEvent instanceof OnChunkGenerated, "First world event must be OnChunkGenerated");
        Assertions.assertEquals(((OnChunkGenerated) mustBeOnGeneratedEvent).getChunkPos(), chunkPosition, "Chunk position at event not expected");
    }, () -> {
        Event mustBeOnLoadedEvent = worldEventCaptor.getAllValues().get(1);
        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(1)).send(blockEventCaptor.capture());
    Event mustBeOnActivatedBlocks = blockEventCaptor.getAllValues().get(0);
    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) OnChunkGenerated(org.terasology.engine.world.chunks.event.OnChunkGenerated) Vector3i(org.joml.Vector3i) Event(org.terasology.engine.entitySystem.event.Event) EntityRef(org.terasology.engine.entitySystem.entity.EntityRef) Test(org.junit.jupiter.api.Test)

Example 3 with Vector3i

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

the class BooleanFacetTest method setup.

@BeforeEach
public void setup() {
    Border3D border = new Border3D(0, 0, 0).extendBy(0, 15, 10);
    Vector3i min = new Vector3i(10, 20, 30);
    Vector3i size = new Vector3i(40, 50, 60);
    BlockRegion region = new BlockRegion(min).setSize(size);
    facet = createFacet(region, border);
// facet = [worldMin=(0, 5, 20), relativeMin=(-10, -15, -10), size=(60, 65, 80)]
}
Also used : Border3D(org.terasology.engine.world.generation.Border3D) Vector3i(org.joml.Vector3i) BlockRegion(org.terasology.engine.world.block.BlockRegion) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 4 with Vector3i

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

the class SparseBooleanFacetTest method testGetWorldMap.

@Test
public void testGetWorldMap() {
    facet.set(0, 1, 2, true);
    facet.set(0, 1, 3, true);
    facet.set(9, 3, 1, true);
    facet.setWorld(13, 28, 34, true);
    facet.setWorld(10, 21, 35, true);
    Map<Vector3i, Boolean> expected = ImmutableMap.of(new Vector3i(10, 21, 32), true, new Vector3i(10, 21, 33), true, new Vector3i(13, 28, 34), true, new Vector3i(10, 21, 35), true, new Vector3i(19, 23, 31), true);
    assertEquals(expected, facet.getWorldEntries());
}
Also used : Vector3i(org.joml.Vector3i) Test(org.junit.jupiter.api.Test)

Example 5 with Vector3i

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

the class BetweenChunkPropagationTest method testBetweenChunksSimple.

@Test
public void testBetweenChunksSimple() {
    Chunk topChunk = new ChunkImpl(new Vector3i(0, 1, 0), blockManager, extraDataManager);
    Chunk bottomChunk = new ChunkImpl(new Vector3i(0, 0, 0), blockManager, extraDataManager);
    provider.addChunk(topChunk);
    provider.addChunk(bottomChunk);
    for (Vector3ic pos : new BlockRegion(0, 0, 0).setSize(Chunks.SIZE_X, 1, Chunks.SIZE_Z)) {
        topChunk.setSunlight(pos, Chunks.MAX_SUNLIGHT);
        topChunk.setSunlightRegen(pos, Chunks.MAX_SUNLIGHT_REGEN);
    }
    InternalLightProcessor.generateInternalLighting(bottomChunk);
    propagator.propagateBetween(topChunk, bottomChunk, Side.BOTTOM, true);
    propagator.process();
    sunlightPropagator.process();
    for (Vector3ic pos : Chunks.CHUNK_REGION) {
        assertEquals(Chunks.MAX_SUNLIGHT, bottomChunk.getSunlight(pos), () -> "Incorrect at position " + pos);
        assertEquals(Chunks.MAX_SUNLIGHT_REGEN, bottomChunk.getSunlightRegen(pos), () -> "Incorrect at position " + pos);
    }
}
Also used : ChunkImpl(org.terasology.engine.world.chunks.internal.ChunkImpl) Vector3ic(org.joml.Vector3ic) Vector3i(org.joml.Vector3i) BlockRegion(org.terasology.engine.world.block.BlockRegion) Chunk(org.terasology.engine.world.chunks.Chunk) Test(org.junit.jupiter.api.Test)

Aggregations

Vector3i (org.joml.Vector3i)203 Test (org.junit.jupiter.api.Test)87 Vector3ic (org.joml.Vector3ic)54 EntityRef (org.terasology.engine.entitySystem.entity.EntityRef)38 Chunk (org.terasology.engine.world.chunks.Chunk)36 BlockRegion (org.terasology.engine.world.block.BlockRegion)30 Block (org.terasology.engine.world.block.Block)22 ChunkImpl (org.terasology.engine.world.chunks.internal.ChunkImpl)21 Vector3f (org.joml.Vector3f)19 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)15 Map (java.util.Map)11 BeforeEach (org.junit.jupiter.api.BeforeEach)10 ReceiveEvent (org.terasology.engine.entitySystem.event.ReceiveEvent)10 ChunkViewCoreImpl (org.terasology.engine.world.internal.ChunkViewCoreImpl)8 OnChunkLoaded (org.terasology.engine.world.chunks.event.OnChunkLoaded)7 Lists (com.google.common.collect.Lists)6 Maps (com.google.common.collect.Maps)6 List (java.util.List)6 ExecutionException (java.util.concurrent.ExecutionException)6 Future (java.util.concurrent.Future)6