Search in sources :

Example 6 with ChunkProvider

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

the class StorageManagerTest method testChunkSurvivesStorageSaveAndRestore.

@Test
public void testChunkSurvivesStorageSaveAndRestore() throws Exception {
    Chunk chunk = new ChunkImpl(CHUNK_POS, blockManager, biomeManager);
    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(Matchers.any(Vector3i.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, biomeManager, storeChunkInZips);
    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.entitySystem.entity.internal.EngineEntityManager) ChunkImpl(org.terasology.world.chunks.internal.ChunkImpl) Vector3i(org.terasology.math.geom.Vector3i) StorageManager(org.terasology.persistence.StorageManager) Chunk(org.terasology.world.chunks.Chunk) ChunkProvider(org.terasology.world.chunks.ChunkProvider) ChunkStore(org.terasology.persistence.ChunkStore) Test(org.junit.Test)

Example 7 with ChunkProvider

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

the class StorageManagerTest method testStoreAndRestoreChunkStore.

@Test
public void testStoreAndRestoreChunkStore() {
    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);
    esm.waitForCompletionOfPreviousSaveAndStartSaving();
    esm.finishSavingAndShutdown();
    ChunkStore restored = esm.loadChunkStore(CHUNK_POS);
    assertNotNull(restored);
    assertEquals(CHUNK_POS, restored.getChunkPosition());
    assertNotNull(restored.getChunk());
    assertEquals(testBlock, restored.getChunk().getBlock(0, 0, 0));
}
Also used : ChunkImpl(org.terasology.world.chunks.internal.ChunkImpl) Chunk(org.terasology.world.chunks.Chunk) ChunkProvider(org.terasology.world.chunks.ChunkProvider) ChunkStore(org.terasology.persistence.ChunkStore) Test(org.junit.Test)

Aggregations

ChunkProvider (org.terasology.world.chunks.ChunkProvider)7 Test (org.junit.Test)3 ChunkStore (org.terasology.persistence.ChunkStore)3 Chunk (org.terasology.world.chunks.Chunk)3 ChunkImpl (org.terasology.world.chunks.internal.ChunkImpl)3 EntityRef (org.terasology.entitySystem.entity.EntityRef)2 EngineEntityManager (org.terasology.entitySystem.entity.internal.EngineEntityManager)2 StorageManager (org.terasology.persistence.StorageManager)2 Map (java.util.Map)1 AudioManager (org.terasology.audio.AudioManager)1 Config (org.terasology.config.Config)1 SimpleUri (org.terasology.engine.SimpleUri)1 EnvironmentSwitchHandler (org.terasology.engine.bootstrap.EnvironmentSwitchHandler)1 ModuleManager (org.terasology.engine.module.ModuleManager)1 Component (org.terasology.entitySystem.Component)1 EntityManager (org.terasology.entitySystem.entity.EntityManager)1 LocationComponent (org.terasology.logic.location.LocationComponent)1 Vector3f (org.terasology.math.geom.Vector3f)1 Vector3i (org.terasology.math.geom.Vector3i)1 ModuleEnvironment (org.terasology.module.ModuleEnvironment)1