Search in sources :

Example 11 with ChunkImpl

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

the class MapWorldProvider method getBlock.

@Override
public Block getBlock(int x, int y, int z) {
    Vector3i pos = new Vector3i(x, y, z);
    Block block = blocks.get(pos);
    if (block != null) {
        return block;
    }
    // TODO block & biome manager
    Vector3i chunkPos = ChunkMath.calcChunkPos(pos);
    Chunk chunk = chunks.get(chunkPos);
    if (chunk == null && worldGenerator != null) {
        chunk = new ChunkImpl(chunkPos, blockManager, biomeManager);
        worldGenerator.createChunk(chunk, entityBuffer);
        chunks.put(chunkPos, chunk);
    }
    if (chunk != null) {
        return chunk.getBlock(ChunkMath.calcBlockPos(pos.x, pos.y, pos.z));
    }
    return null;
}
Also used : ChunkImpl(org.terasology.world.chunks.internal.ChunkImpl) Vector3i(org.terasology.math.geom.Vector3i) Block(org.terasology.world.block.Block) Chunk(org.terasology.world.chunks.Chunk)

Example 12 with ChunkImpl

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

the class ReadWriteStorageManager method deactivateChunk.

@Override
public void deactivateChunk(Chunk chunk) {
    Collection<EntityRef> entitiesOfChunk = getEntitiesOfChunk(chunk);
    // storage manager only works with ChunkImpl
    ChunkImpl chunkImpl = (ChunkImpl) chunk;
    unloadedAndUnsavedChunkMap.put(chunk.getPosition(), new CompressedChunkBuilder(getEntityManager(), chunkImpl, entitiesOfChunk, true));
    entitiesOfChunk.forEach(this::deactivateOrDestroyEntityRecursive);
}
Also used : ChunkImpl(org.terasology.world.chunks.internal.ChunkImpl) EntityRef(org.terasology.entitySystem.entity.EntityRef)

Example 13 with ChunkImpl

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

the class SaveTransaction method prepareCompressedChunkBuilders.

/**
 * @param unsavedEntities currently loaded persistent entities without owner that have not been saved yet.
 *                        This method removes entities it saves.
 */
private void prepareCompressedChunkBuilders(Set<EntityRef> unsavedEntities) {
    Map<Vector3i, Collection<EntityRef>> chunkPosToEntitiesMap = createChunkPosToUnsavedOwnerLessEntitiesMap();
    allChunks = Maps.newHashMap();
    allChunks.putAll(unloadedChunks);
    for (Map.Entry<Vector3i, ChunkImpl> chunkEntry : loadedChunks.entrySet()) {
        Collection<EntityRef> entitiesToStore = chunkPosToEntitiesMap.get(chunkEntry.getKey());
        if (entitiesToStore == null) {
            entitiesToStore = Collections.emptySet();
        }
        ChunkImpl chunk = chunkEntry.getValue();
        unsavedEntities.removeAll(entitiesToStore);
        CompressedChunkBuilder compressedChunkBuilder = new CompressedChunkBuilder(privateEntityManager, chunk, entitiesToStore, false);
        unsavedEntities.removeAll(compressedChunkBuilder.getStoredEntities());
        allChunks.put(chunkEntry.getKey(), compressedChunkBuilder);
    }
}
Also used : ChunkImpl(org.terasology.world.chunks.internal.ChunkImpl) Vector3i(org.terasology.math.geom.Vector3i) Collection(java.util.Collection) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) EntityRef(org.terasology.entitySystem.entity.EntityRef)

Example 14 with ChunkImpl

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

the class InternalLightGeneratorTest method testHorizontalSunlightPropagation.

@Test
public void testHorizontalSunlightPropagation() {
    Chunk chunk = new ChunkImpl(0, 0, 0, blockManager, biomeManager);
    for (Vector3i pos : Region3i.createFromMinAndSize(new Vector3i(0, 4, 0), new Vector3i(ChunkConstants.SIZE_X, 1, ChunkConstants.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.world.chunks.internal.ChunkImpl) Vector3i(org.terasology.math.geom.Vector3i) Chunk(org.terasology.world.chunks.Chunk) Test(org.junit.Test)

Example 15 with ChunkImpl

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

the class InternalLightGeneratorTest method testLightPropagation.

@Test
public void testLightPropagation() {
    Chunk chunk = new ChunkImpl(0, 0, 0, blockManager, biomeManager);
    chunk.setBlock(16, 32, 16, fullLight);
    InternalLightProcessor.generateInternalLighting(chunk);
    assertEquals(fullLight.getLuminance(), chunk.getLight(16, 32, 16));
    assertEquals(fullLight.getLuminance() - 1, chunk.getLight(new Vector3i(16, 33, 16)));
    for (int i = 1; i < fullLight.getLuminance(); ++i) {
        for (Vector3i pos : Diamond3iIterator.iterateAtDistance(new Vector3i(16, 32, 16), i)) {
            assertEquals(fullLight.getLuminance() - i, chunk.getLight(pos));
        }
    }
}
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)

Aggregations

ChunkImpl (org.terasology.world.chunks.internal.ChunkImpl)22 Vector3i (org.terasology.math.geom.Vector3i)18 Chunk (org.terasology.world.chunks.Chunk)18 Test (org.junit.Test)15 ChunkStore (org.terasology.persistence.ChunkStore)4 EntityRef (org.terasology.entitySystem.entity.EntityRef)3 ChunkProvider (org.terasology.world.chunks.ChunkProvider)3 Map (java.util.Map)2 EngineEntityManager (org.terasology.entitySystem.entity.internal.EngineEntityManager)2 StorageManager (org.terasology.persistence.StorageManager)2 Block (org.terasology.world.block.Block)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 TShortObjectMap (gnu.trove.map.TShortObjectMap)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 ConcurrentMap (java.util.concurrent.ConcurrentMap)1 Before (org.junit.Before)1 ResourceUrn (org.terasology.assets.ResourceUrn)1 AssetManager (org.terasology.assets.management.AssetManager)1 LocationComponent (org.terasology.logic.location.LocationComponent)1