Search in sources :

Example 21 with Chunk

use of org.terasology.world.chunks.Chunk 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 22 with Chunk

use of org.terasology.world.chunks.Chunk 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 23 with Chunk

use of org.terasology.world.chunks.Chunk 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 24 with Chunk

use of org.terasology.world.chunks.Chunk 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)

Example 25 with Chunk

use of org.terasology.world.chunks.Chunk 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)

Aggregations

Chunk (org.terasology.world.chunks.Chunk)50 Vector3i (org.terasology.math.geom.Vector3i)31 Test (org.junit.Test)28 ChunkImpl (org.terasology.world.chunks.internal.ChunkImpl)18 ReadyChunkInfo (org.terasology.world.chunks.internal.ReadyChunkInfo)9 ManagedChunk (org.terasology.world.chunks.ManagedChunk)8 ChunkViewCoreImpl (org.terasology.world.internal.ChunkViewCoreImpl)8 ChunkStore (org.terasology.persistence.ChunkStore)7 EntityRef (org.terasology.entitySystem.entity.EntityRef)5 ChunkViewCore (org.terasology.world.internal.ChunkViewCore)5 ChunkProvider (org.terasology.world.chunks.ChunkProvider)3 TIntList (gnu.trove.list.TIntList)2 TShortObjectHashMap (gnu.trove.map.hash.TShortObjectHashMap)2 EntityStore (org.terasology.entitySystem.entity.EntityStore)2 EngineEntityManager (org.terasology.entitySystem.entity.internal.EngineEntityManager)2 Event (org.terasology.entitySystem.event.Event)2 LocationComponent (org.terasology.logic.location.LocationComponent)2 Side (org.terasology.math.Side)2 StorageManager (org.terasology.persistence.StorageManager)2 Block (org.terasology.world.block.Block)2