Search in sources :

Example 1 with ChunkViewCoreImpl

use of org.terasology.world.internal.ChunkViewCoreImpl in project Terasology by MovingBlocks.

the class LocalChunkProvider method createWorldView.

private ChunkViewCore createWorldView(Region3i region, Vector3i offset) {
    Chunk[] chunks = new Chunk[region.sizeX() * region.sizeY() * region.sizeZ()];
    for (Vector3i chunkPos : region) {
        Chunk chunk = chunkCache.get(chunkPos);
        if (chunk == null) {
            return null;
        }
        chunkPos.sub(region.minX(), region.minY(), region.minZ());
        int index = TeraMath.calculate3DArrayIndex(chunkPos, region.size());
        chunks[index] = chunk;
    }
    return new ChunkViewCoreImpl(chunks, region, offset, blockManager.getBlock(BlockManager.AIR_ID));
}
Also used : ChunkViewCoreImpl(org.terasology.world.internal.ChunkViewCoreImpl) Vector3i(org.terasology.math.geom.Vector3i) Chunk(org.terasology.world.chunks.Chunk) ManagedChunk(org.terasology.world.chunks.ManagedChunk)

Example 2 with ChunkViewCoreImpl

use of org.terasology.world.internal.ChunkViewCoreImpl in project Terasology by MovingBlocks.

the class RemoteChunkProvider method createWorldView.

private ChunkViewCore createWorldView(Region3i region, Vector3i offset) {
    Chunk[] chunks = new Chunk[region.size().x * region.size().y * region.size().z];
    for (Vector3i chunkPos : region) {
        Chunk chunk = chunkCache.get(chunkPos);
        if (chunk == null || !chunk.isReady()) {
            return null;
        }
        chunkPos.sub(region.min());
        int index = TeraMath.calculate3DArrayIndex(chunkPos, region.size());
        chunks[index] = chunk;
    }
    return new ChunkViewCoreImpl(chunks, region, offset, blockManager.getBlock(BlockManager.AIR_ID));
}
Also used : ChunkViewCoreImpl(org.terasology.world.internal.ChunkViewCoreImpl) Vector3i(org.terasology.math.geom.Vector3i) Chunk(org.terasology.world.chunks.Chunk)

Example 3 with ChunkViewCoreImpl

use of org.terasology.world.internal.ChunkViewCoreImpl in project Terasology by MovingBlocks.

the class ChunkViewTest method testOffsetWorldViewAfterMainChunk.

@Test
public void testOffsetWorldViewAfterMainChunk() {
    Chunk chunk = createChunk(0, 0, 0);
    chunk.setBlock(new Vector3i(0, 0, 0), solidBlock);
    Chunk[] chunks = new Chunk[] { createChunk(-1, 0, -1), createChunk(0, 0, -1), createChunk(1, 0, -1), createChunk(-1, 0, 0), createChunk(0, 0, 0), createChunk(1, 0, 0), createChunk(-1, 0, 1), createChunk(0, 0, 1), chunk };
    ChunkViewCore chunkView = new ChunkViewCoreImpl(chunks, Region3i.createFromCenterExtents(new Vector3i(0, 0, 0), new Vector3i(1, 0, 1)), new Vector3i(1, 0, 1), airBlock);
    assertEquals(solidBlock, chunkView.getBlock(ChunkConstants.SIZE_X, 0, ChunkConstants.SIZE_Z));
}
Also used : ChunkViewCoreImpl(org.terasology.world.internal.ChunkViewCoreImpl) Vector3i(org.terasology.math.geom.Vector3i) Chunk(org.terasology.world.chunks.Chunk) ChunkViewCore(org.terasology.world.internal.ChunkViewCore) Test(org.junit.Test)

Example 4 with ChunkViewCoreImpl

use of org.terasology.world.internal.ChunkViewCoreImpl in project Terasology by MovingBlocks.

the class ChunkViewTest method testOffsetWorldView.

@Test
public void testOffsetWorldView() {
    Chunk chunk = createChunk(0, 0, 0);
    chunk.setBlock(new Vector3i(0, 0, 0), solidBlock);
    Chunk[] chunks = new Chunk[] { createChunk(-1, 0, -1), createChunk(0, 0, -1), createChunk(1, 0, -1), createChunk(-1, 0, 0), chunk, createChunk(1, 0, 0), createChunk(-1, 0, 1), createChunk(0, 0, 1), createChunk(1, 0, 1) };
    ChunkViewCore chunkView = new ChunkViewCoreImpl(chunks, Region3i.createFromCenterExtents(new Vector3i(0, 0, 0), new Vector3i(1, 0, 1)), new Vector3i(1, 0, 1), airBlock);
    assertEquals(solidBlock, chunkView.getBlock(0, 0, 0));
}
Also used : ChunkViewCoreImpl(org.terasology.world.internal.ChunkViewCoreImpl) Vector3i(org.terasology.math.geom.Vector3i) Chunk(org.terasology.world.chunks.Chunk) ChunkViewCore(org.terasology.world.internal.ChunkViewCore) Test(org.junit.Test)

Example 5 with ChunkViewCoreImpl

use of org.terasology.world.internal.ChunkViewCoreImpl in project Terasology by MovingBlocks.

the class ChunkViewTest method testSimpleWorldView.

@Test
public void testSimpleWorldView() {
    Chunk chunk = createChunk(0, 0, 0);
    chunk.setBlock(new Vector3i(0, 0, 0), solidBlock);
    ChunkViewCore chunkView = new ChunkViewCoreImpl(new Chunk[] { chunk }, Region3i.createFromCenterExtents(Vector3i.zero(), Vector3i.zero()), new Vector3i(), airBlock);
    assertEquals(solidBlock, chunkView.getBlock(0, 0, 0));
}
Also used : ChunkViewCoreImpl(org.terasology.world.internal.ChunkViewCoreImpl) Vector3i(org.terasology.math.geom.Vector3i) Chunk(org.terasology.world.chunks.Chunk) ChunkViewCore(org.terasology.world.internal.ChunkViewCore) Test(org.junit.Test)

Aggregations

Vector3i (org.terasology.math.geom.Vector3i)8 Chunk (org.terasology.world.chunks.Chunk)8 ChunkViewCoreImpl (org.terasology.world.internal.ChunkViewCoreImpl)8 Test (org.junit.Test)6 ChunkViewCore (org.terasology.world.internal.ChunkViewCore)5 ManagedChunk (org.terasology.world.chunks.ManagedChunk)1