Search in sources :

Example 21 with BlockRegion

use of org.terasology.engine.world.block.BlockRegion in project Terasology by MovingBlocks.

the class InternalLightGeneratorTest method testHorizontalSunlightPropagation.

@Test
public void testHorizontalSunlightPropagation() {
    Chunk chunk = new ChunkImpl(0, 0, 0, blockManager, extraDataManager);
    for (Vector3ic pos : new BlockRegion(0, 4, 0).setSize(Chunks.SIZE_X, 1, Chunks.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.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)

Example 22 with BlockRegion

use of org.terasology.engine.world.block.BlockRegion in project Terasology by MovingBlocks.

the class InternalLightGeneratorTest method testUnblockedSunlightRegenPropagation.

@Test
public void testUnblockedSunlightRegenPropagation() {
    Chunk chunk = new ChunkImpl(0, 0, 0, blockManager, extraDataManager);
    InternalLightProcessor.generateInternalLighting(chunk);
    for (Vector3ic pos : new BlockRegion(0, 0, 0).setSize(Chunks.SIZE_X, Chunks.SIZE_Y, Chunks.SIZE_Z)) {
        byte expectedRegen = (byte) Math.min(Chunks.SIZE_Y - pos.y() - 1, Chunks.MAX_SUNLIGHT_REGEN);
        assertEquals(expectedRegen, chunk.getSunlightRegen(pos));
    }
}
Also used : ChunkImpl(org.terasology.engine.world.chunks.internal.ChunkImpl) Vector3ic(org.joml.Vector3ic) BlockRegion(org.terasology.engine.world.block.BlockRegion) Chunk(org.terasology.engine.world.chunks.Chunk) Test(org.junit.jupiter.api.Test)

Example 23 with BlockRegion

use of org.terasology.engine.world.block.BlockRegion 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)

Example 24 with BlockRegion

use of org.terasology.engine.world.block.BlockRegion in project Terasology by MovingBlocks.

the class BulkSunlightPropagationTest method testStopSunlightVertical.

@Test
public void testStopSunlightVertical() {
    for (Vector3ic pos : new BlockRegion(0, 16, 0).union(Chunks.SIZE_X - 1, Chunks.SIZE_Y - 1, Chunks.SIZE_Z - 1)) {
        regenWorldView.setValueAt(pos, Chunks.MAX_SUNLIGHT_REGEN);
        lightWorldView.setValueAt(pos, Chunks.MAX_SUNLIGHT);
    }
    for (Vector3ic pos : new BlockRegion(0, 15, 0).union(Chunks.SIZE_X - 1, 15, Chunks.SIZE_Z - 1)) {
        regenWorldView.setBlockAt(new Vector3i(pos), solid);
    }
    for (Vector3ic pos : new BlockRegion(0, 0, 0).union(Chunks.SIZE_X - 1, 14, Chunks.SIZE_Z - 1)) {
        regenWorldView.setValueAt(pos, (byte) (14 - pos.y()));
    }
    regenWorldView.setBlockAt(new Vector3i(16, 15, 16), air);
    propagator.process(new BlockChange(new Vector3i(16, 15, 16), solid, air));
    sunlightPropagator.process(new BlockChange(new Vector3i(16, 15, 16), solid, air));
    regenWorldView.setBlockAt(new Vector3i(16, 15, 16), solid);
    propagator.process(new BlockChange(new Vector3i(16, 15, 16), air, solid));
    sunlightPropagator.process(new BlockChange(new Vector3i(16, 15, 16), air, solid));
    for (Vector3ic pos : new BlockRegion(0, 0, 0).union(Chunks.SIZE_X - 1, 15, Chunks.SIZE_Z - 1)) {
        assertEquals(Math.max(0, 14 - pos.y()), regenWorldView.getValueAt(pos), "Incorrect value at " + pos);
        assertEquals(0, lightWorldView.getValueAt(pos), "Incorrect value at " + pos);
    }
}
Also used : Vector3ic(org.joml.Vector3ic) Vector3i(org.joml.Vector3i) BlockRegion(org.terasology.engine.world.block.BlockRegion) Test(org.junit.jupiter.api.Test)

Example 25 with BlockRegion

use of org.terasology.engine.world.block.BlockRegion in project Terasology by MovingBlocks.

the class RenderableWorldImpl method onChunkLoaded.

@Override
public void onChunkLoaded(Vector3ic chunkCoordinates) {
    if (renderableRegion.contains(chunkCoordinates)) {
        Chunk chunk = chunkProvider.getChunk(chunkCoordinates);
        if (chunk != null) {
            chunksInProximityOfCamera.add(chunk);
            chunksInProximityOfCamera.sort(new ChunkFrontToBackComparator());
            if (lodChunkProvider != null) {
                lodChunkProvider.onRealChunkLoaded(chunkCoordinates);
            }
        } else {
            logger.warn("Warning: onChunkLoaded called for a null chunk!");
        }
    }
    for (Vector3ic pos : new BlockRegion(chunkCoordinates).expand(1, 1, 1)) {
        Chunk chunk = chunkProvider.getChunk(pos);
        if (chunk != null) {
            chunk.setDirty(true);
        }
    }
}
Also used : Vector3ic(org.joml.Vector3ic) BlockRegion(org.terasology.engine.world.block.BlockRegion) RenderableChunk(org.terasology.engine.world.chunks.RenderableChunk) Chunk(org.terasology.engine.world.chunks.Chunk)

Aggregations

BlockRegion (org.terasology.engine.world.block.BlockRegion)52 Vector3i (org.joml.Vector3i)29 Vector3ic (org.joml.Vector3ic)26 Test (org.junit.jupiter.api.Test)26 Chunk (org.terasology.engine.world.chunks.Chunk)23 ChunkImpl (org.terasology.engine.world.chunks.internal.ChunkImpl)11 ChunkViewCoreImpl (org.terasology.engine.world.internal.ChunkViewCoreImpl)7 ChunkViewCore (org.terasology.engine.world.internal.ChunkViewCore)5 Vector3f (org.joml.Vector3f)4 BeforeEach (org.junit.jupiter.api.BeforeEach)4 ReceiveEvent (org.terasology.engine.entitySystem.event.ReceiveEvent)4 Border3D (org.terasology.engine.world.generation.Border3D)4 WorldGeneratorPluginLibrary (org.terasology.engine.world.generator.plugin.WorldGeneratorPluginLibrary)4 ElevationFacet (org.terasology.engine.world.generation.facets.ElevationFacet)3 Vector2ic (org.joml.Vector2ic)2 RenderableChunk (org.terasology.engine.world.chunks.RenderableChunk)2 PreLodChunk (org.terasology.engine.world.chunks.internal.PreLodChunk)2 Region (org.terasology.engine.world.generation.Region)2 World (org.terasology.engine.world.generation.World)2 JsonElement (com.google.gson.JsonElement)1