Search in sources :

Example 6 with ChunkImpl

use of org.terasology.engine.world.chunks.internal.ChunkImpl 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 7 with ChunkImpl

use of org.terasology.engine.world.chunks.internal.ChunkImpl 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 8 with ChunkImpl

use of org.terasology.engine.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 manager
    Vector3i chunkPos = Chunks.toChunkPos(pos, new Vector3i());
    Chunk chunk = chunks.get(chunkPos);
    if (chunk == null && worldGenerator != null) {
        chunk = new ChunkImpl(chunkPos, blockManager, extraDataManager);
        worldGenerator.createChunk(chunk, entityBuffer);
        chunks.put(chunkPos, chunk);
    }
    if (chunk != null) {
        return chunk.getBlock(Chunks.toRelative(pos, pos));
    }
    return null;
}
Also used : ChunkImpl(org.terasology.engine.world.chunks.internal.ChunkImpl) Vector3i(org.joml.Vector3i) Block(org.terasology.engine.world.block.Block) Chunk(org.terasology.engine.world.chunks.Chunk)

Example 9 with ChunkImpl

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

the class LocalChunkProvider method createOrLoadChunk.

protected ListenableFuture<Chunk> createOrLoadChunk(Vector3ic chunkPos) {
    Vector3i pos = new Vector3i(chunkPos);
    return loadingPipeline.invokeGeneratorTask(pos, () -> {
        ChunkStore chunkStore = storageManager.loadChunkStore(pos);
        Chunk chunk;
        EntityBufferImpl buffer = new EntityBufferImpl();
        if (chunkStore == null) {
            chunk = new ChunkImpl(pos, blockManager, extraDataManager);
            generator.createChunk(chunk, buffer);
            generateQueuedEntities.put(chunk.getPosition(new Vector3i()), buffer.getAll());
        } else {
            chunk = chunkStore.getChunk();
        }
        return chunk;
    });
}
Also used : ChunkImpl(org.terasology.engine.world.chunks.internal.ChunkImpl) Vector3i(org.joml.Vector3i) EntityBufferImpl(org.terasology.engine.world.generation.impl.EntityBufferImpl) Chunk(org.terasology.engine.world.chunks.Chunk) ChunkStore(org.terasology.engine.persistence.ChunkStore)

Example 10 with ChunkImpl

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

the class StorageManagerTest method testChunkSurvivesStorageSaveAndRestore.

@Test
public void testChunkSurvivesStorageSaveAndRestore() throws Exception {
    Chunk chunk = new ChunkImpl(CHUNK_POS, blockManager, extraDataManager);
    chunk.setBlock(0, 0, 0, testBlock);
    chunk.setBlock(0, 4, 2, testBlock2);
    chunk.markReady();
    ChunkProvider chunkProvider = mock(ChunkProvider.class);
    when(chunkProvider.getAllChunks()).thenReturn(Arrays.asList(chunk));
    when(chunkProvider.getChunk(ArgumentMatchers.any(Vector3ic.class))).thenReturn(chunk);
    CoreRegistry.put(ChunkProvider.class, chunkProvider);
    boolean storeChunkInZips = true;
    esm.setStoreChunksInZips(storeChunkInZips);
    esm.waitForCompletionOfPreviousSaveAndStartSaving();
    esm.finishSavingAndShutdown();
    EntitySystemSetupUtil.addReflectionBasedLibraries(context);
    EntitySystemSetupUtil.addEntityManagementRelatedClasses(context);
    EngineEntityManager newEntityManager = context.get(EngineEntityManager.class);
    StorageManager newSM = new ReadWriteStorageManager(savePath, moduleEnvironment, newEntityManager, blockManager, extraDataManager, storeChunkInZips, recordAndReplaySerializer, recordAndReplayUtils, recordAndReplayCurrentStatus);
    newSM.loadGlobalStore();
    ChunkStore restored = newSM.loadChunkStore(CHUNK_POS);
    assertNotNull(restored);
    assertEquals(CHUNK_POS, restored.getChunkPosition());
    assertNotNull(restored.getChunk());
    assertEquals(testBlock, restored.getChunk().getBlock(0, 0, 0));
    assertEquals(testBlock2, restored.getChunk().getBlock(0, 4, 2));
}
Also used : EngineEntityManager(org.terasology.engine.entitySystem.entity.internal.EngineEntityManager) ChunkImpl(org.terasology.engine.world.chunks.internal.ChunkImpl) Vector3ic(org.joml.Vector3ic) StorageManager(org.terasology.engine.persistence.StorageManager) Chunk(org.terasology.engine.world.chunks.Chunk) ChunkProvider(org.terasology.engine.world.chunks.ChunkProvider) ChunkStore(org.terasology.engine.persistence.ChunkStore) Test(org.junit.jupiter.api.Test)

Aggregations

ChunkImpl (org.terasology.engine.world.chunks.internal.ChunkImpl)23 Chunk (org.terasology.engine.world.chunks.Chunk)19 Test (org.junit.jupiter.api.Test)17 Vector3i (org.joml.Vector3i)14 Vector3ic (org.joml.Vector3ic)14 BlockRegion (org.terasology.engine.world.block.BlockRegion)11 EntityRef (org.terasology.engine.entitySystem.entity.EntityRef)4 ChunkStore (org.terasology.engine.persistence.ChunkStore)4 ChunkProvider (org.terasology.engine.world.chunks.ChunkProvider)3 Map (java.util.Map)2 EngineEntityManager (org.terasology.engine.entitySystem.entity.internal.EngineEntityManager)2 Event (org.terasology.engine.entitySystem.event.Event)2 StorageManager (org.terasology.engine.persistence.StorageManager)2 OnChunkLoaded (org.terasology.engine.world.chunks.event.OnChunkLoaded)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 Collection (java.util.Collection)1 ConcurrentMap (java.util.concurrent.ConcurrentMap)1 Vector3f (org.joml.Vector3f)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1 LocationComponent (org.terasology.engine.logic.location.LocationComponent)1