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));
}
}
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));
}
}
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));
}
}
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));
}
}
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());
}
Aggregations