Search in sources :

Example 6 with ChunkImpl

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

the class InternalLightGeneratorTest method testUnblockedSunlightPropagation.

@Test
public void testUnblockedSunlightPropagation() {
    Chunk chunk = new ChunkImpl(0, 0, 0, blockManager, biomeManager);
    InternalLightProcessor.generateInternalLighting(chunk);
    for (Vector3i pos : Region3i.createFromMinAndSize(new Vector3i(0, 0, 0), new Vector3i(ChunkConstants.SIZE_X, 15, ChunkConstants.SIZE_Z))) {
        assertEquals("Incorrect lighting at " + pos, 15 - pos.y, chunk.getSunlight(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)

Example 7 with ChunkImpl

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

the class InternalLightGeneratorTest method testBlockedSunlightRegenPropagationResets.

@Test
public void testBlockedSunlightRegenPropagationResets() {
    Chunk chunk = new ChunkImpl(0, 0, 0, blockManager, biomeManager);
    for (Vector3i pos : Region3i.createFromMinAndSize(new Vector3i(0, 60, 0), new Vector3i(ChunkConstants.SIZE_X, 1, ChunkConstants.SIZE_Z))) {
        chunk.setBlock(pos, solidBlock);
    }
    InternalLightProcessor.generateInternalLighting(chunk);
    for (Vector3i pos : Region3i.createFromMinAndSize(new Vector3i(0, 61, 0), new Vector3i(ChunkConstants.SIZE_X, 3, ChunkConstants.SIZE_Z))) {
        byte expectedRegen = (byte) Math.min(ChunkConstants.SIZE_Y - pos.y - 1, ChunkConstants.MAX_SUNLIGHT_REGEN);
        assertEquals(expectedRegen, chunk.getSunlightRegen(pos));
    }
    for (Vector3i pos : Region3i.createFromMinAndSize(new Vector3i(0, 60, 0), new Vector3i(ChunkConstants.SIZE_X, 1, ChunkConstants.SIZE_Z))) {
        assertEquals(0, chunk.getSunlightRegen(pos));
    }
    for (Vector3i pos : Region3i.createFromMinAndSize(new Vector3i(0, 0, 0), new Vector3i(ChunkConstants.SIZE_X, 59, ChunkConstants.SIZE_Z))) {
        byte expectedRegen = (byte) Math.min(60 - pos.y - 1, ChunkConstants.MAX_SUNLIGHT_REGEN);
        assertEquals(expectedRegen, chunk.getSunlightRegen(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)

Example 8 with ChunkImpl

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

the class BetweenChunkPropagationTest method testPropagateSunlightAppearingMidChunk.

@Test
public void testPropagateSunlightAppearingMidChunk() {
    Chunk topChunk = new ChunkImpl(new Vector3i(0, 1, 0), blockManager, biomeManager);
    Chunk bottomChunk = new ChunkImpl(new Vector3i(0, 0, 0), blockManager, biomeManager);
    provider.addChunk(topChunk);
    provider.addChunk(bottomChunk);
    for (Vector3i pos : Region3i.createFromMinAndSize(new Vector3i(0, 0, 0), new Vector3i(ChunkConstants.SIZE_X, 1, ChunkConstants.SIZE_Z))) {
        topChunk.setSunlight(pos, (byte) 0);
        topChunk.setSunlightRegen(pos, (byte) 0);
    }
    for (Vector3i pos : Region3i.createFromMinAndSize(new Vector3i(8, 0, 8), new Vector3i(ChunkConstants.SIZE_X - 16, 1, ChunkConstants.SIZE_Z - 16))) {
        topChunk.setSunlight(pos, (byte) 0);
        topChunk.setSunlightRegen(pos, (byte) 32);
    }
    InternalLightProcessor.generateInternalLighting(bottomChunk);
    propagator.propagateBetween(topChunk, bottomChunk, Side.BOTTOM, false);
    propagator.process();
    sunlightPropagator.process();
    for (int i = 0; i < 15; ++i) {
        assertEquals("Incorrect value at " + (33 + i), 14 - i, bottomChunk.getSunlight(7, 33 + i, 16));
    }
    for (int i = 2; i < 33; ++i) {
        assertEquals("Incorrect value at " + i, 14, bottomChunk.getSunlight(7, i, 16));
    }
}
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 9 with ChunkImpl

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

the class BetweenChunkPropagationTest method testBetweenChunksWithOverhang.

@Test
public void testBetweenChunksWithOverhang() {
    Chunk topChunk = new ChunkImpl(new Vector3i(0, 1, 0), blockManager, biomeManager);
    Chunk bottomChunk = new ChunkImpl(new Vector3i(0, 0, 0), blockManager, biomeManager);
    provider.addChunk(topChunk);
    provider.addChunk(bottomChunk);
    for (Vector3i pos : Region3i.createFromMinAndSize(new Vector3i(0, 0, 0), new Vector3i(ChunkConstants.SIZE_X, 1, ChunkConstants.SIZE_Z))) {
        topChunk.setSunlight(pos, ChunkConstants.MAX_SUNLIGHT);
        topChunk.setSunlightRegen(pos, ChunkConstants.MAX_SUNLIGHT_REGEN);
    }
    for (Vector3i pos : Region3i.createFromMinMax(new Vector3i(16, 48, 0), new Vector3i(31, 48, 31))) {
        bottomChunk.setBlock(pos, solid);
    }
    InternalLightProcessor.generateInternalLighting(bottomChunk);
    propagator.propagateBetween(topChunk, bottomChunk, Side.BOTTOM, false);
    propagator.process();
    sunlightPropagator.process();
    for (int z = 0; z < ChunkConstants.SIZE_Z; ++z) {
        assertEquals(14, bottomChunk.getSunlight(16, 47, z));
    }
    for (int z = 0; z < ChunkConstants.SIZE_Z; ++z) {
        assertEquals(13, bottomChunk.getSunlight(17, 47, z));
    }
}
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 10 with ChunkImpl

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

the class StorageManagerTest method testEntitySurvivesStorageInChunkStore.

@Test
public void testEntitySurvivesStorageInChunkStore() throws Exception {
    Chunk chunk = new ChunkImpl(CHUNK_POS, blockManager, biomeManager);
    chunk.setBlock(0, 0, 0, testBlock);
    chunk.markReady();
    ChunkProvider chunkProvider = mock(ChunkProvider.class);
    when(chunkProvider.getAllChunks()).thenReturn(Arrays.asList(chunk));
    CoreRegistry.put(ChunkProvider.class, chunkProvider);
    EntityRef entity = entityManager.create();
    long id = entity.getId();
    LocationComponent locationComponent = new LocationComponent();
    Vector3f positionInChunk = new Vector3f(chunk.getAABB().getMin());
    positionInChunk.x += 1;
    positionInChunk.y += 1;
    positionInChunk.z += 1;
    locationComponent.setWorldPosition(positionInChunk);
    entity.addComponent(locationComponent);
    esm.waitForCompletionOfPreviousSaveAndStartSaving();
    esm.finishSavingAndShutdown();
    EntitySystemSetupUtil.addReflectionBasedLibraries(context);
    EntitySystemSetupUtil.addEntityManagementRelatedClasses(context);
    EngineEntityManager newEntityManager = context.get(EngineEntityManager.class);
    StorageManager newSM = new ReadWriteStorageManager(savePath, moduleEnvironment, newEntityManager, blockManager, biomeManager, false);
    newSM.loadGlobalStore();
    ChunkStore restored = newSM.loadChunkStore(CHUNK_POS);
    restored.restoreEntities();
    EntityRef ref = newEntityManager.getEntity(id);
    assertTrue(ref.exists());
    assertTrue(ref.isActive());
}
Also used : EngineEntityManager(org.terasology.entitySystem.entity.internal.EngineEntityManager) ChunkImpl(org.terasology.world.chunks.internal.ChunkImpl) Vector3f(org.terasology.math.geom.Vector3f) StorageManager(org.terasology.persistence.StorageManager) Chunk(org.terasology.world.chunks.Chunk) ChunkProvider(org.terasology.world.chunks.ChunkProvider) EntityRef(org.terasology.entitySystem.entity.EntityRef) LocationComponent(org.terasology.logic.location.LocationComponent) ChunkStore(org.terasology.persistence.ChunkStore) 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