use of org.terasology.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 & biome manager
Vector3i chunkPos = ChunkMath.calcChunkPos(pos);
Chunk chunk = chunks.get(chunkPos);
if (chunk == null && worldGenerator != null) {
chunk = new ChunkImpl(chunkPos, blockManager, biomeManager);
worldGenerator.createChunk(chunk, entityBuffer);
chunks.put(chunkPos, chunk);
}
if (chunk != null) {
return chunk.getBlock(ChunkMath.calcBlockPos(pos.x, pos.y, pos.z));
}
return null;
}
use of org.terasology.world.chunks.internal.ChunkImpl in project Terasology by MovingBlocks.
the class ReadWriteStorageManager method deactivateChunk.
@Override
public void deactivateChunk(Chunk chunk) {
Collection<EntityRef> entitiesOfChunk = getEntitiesOfChunk(chunk);
// storage manager only works with ChunkImpl
ChunkImpl chunkImpl = (ChunkImpl) chunk;
unloadedAndUnsavedChunkMap.put(chunk.getPosition(), new CompressedChunkBuilder(getEntityManager(), chunkImpl, entitiesOfChunk, true));
entitiesOfChunk.forEach(this::deactivateOrDestroyEntityRecursive);
}
use of org.terasology.world.chunks.internal.ChunkImpl in project Terasology by MovingBlocks.
the class SaveTransaction method prepareCompressedChunkBuilders.
/**
* @param unsavedEntities currently loaded persistent entities without owner that have not been saved yet.
* This method removes entities it saves.
*/
private void prepareCompressedChunkBuilders(Set<EntityRef> unsavedEntities) {
Map<Vector3i, Collection<EntityRef>> chunkPosToEntitiesMap = createChunkPosToUnsavedOwnerLessEntitiesMap();
allChunks = Maps.newHashMap();
allChunks.putAll(unloadedChunks);
for (Map.Entry<Vector3i, ChunkImpl> chunkEntry : loadedChunks.entrySet()) {
Collection<EntityRef> entitiesToStore = chunkPosToEntitiesMap.get(chunkEntry.getKey());
if (entitiesToStore == null) {
entitiesToStore = Collections.emptySet();
}
ChunkImpl chunk = chunkEntry.getValue();
unsavedEntities.removeAll(entitiesToStore);
CompressedChunkBuilder compressedChunkBuilder = new CompressedChunkBuilder(privateEntityManager, chunk, entitiesToStore, false);
unsavedEntities.removeAll(compressedChunkBuilder.getStoredEntities());
allChunks.put(chunkEntry.getKey(), compressedChunkBuilder);
}
}
use of org.terasology.world.chunks.internal.ChunkImpl in project Terasology by MovingBlocks.
the class InternalLightGeneratorTest method testHorizontalSunlightPropagation.
@Test
public void testHorizontalSunlightPropagation() {
Chunk chunk = new ChunkImpl(0, 0, 0, blockManager, biomeManager);
for (Vector3i pos : Region3i.createFromMinAndSize(new Vector3i(0, 4, 0), new Vector3i(ChunkConstants.SIZE_X, 1, ChunkConstants.SIZE_Z))) {
chunk.setBlock(pos, solidBlock);
}
chunk.setBlock(new Vector3i(16, 4, 16), airBlock);
InternalLightProcessor.generateInternalLighting(chunk);
assertEquals(12, chunk.getSunlight(16, 3, 16));
assertEquals(11, chunk.getSunlight(15, 3, 16));
assertEquals(11, chunk.getSunlight(17, 3, 16));
assertEquals(11, chunk.getSunlight(16, 3, 15));
assertEquals(11, chunk.getSunlight(16, 3, 17));
assertEquals(12, chunk.getSunlight(15, 2, 16));
assertEquals(12, chunk.getSunlight(17, 2, 16));
assertEquals(12, chunk.getSunlight(16, 2, 15));
assertEquals(12, chunk.getSunlight(16, 2, 17));
}
use of org.terasology.world.chunks.internal.ChunkImpl in project Terasology by MovingBlocks.
the class InternalLightGeneratorTest method testLightPropagation.
@Test
public void testLightPropagation() {
Chunk chunk = new ChunkImpl(0, 0, 0, blockManager, biomeManager);
chunk.setBlock(16, 32, 16, fullLight);
InternalLightProcessor.generateInternalLighting(chunk);
assertEquals(fullLight.getLuminance(), chunk.getLight(16, 32, 16));
assertEquals(fullLight.getLuminance() - 1, chunk.getLight(new Vector3i(16, 33, 16)));
for (int i = 1; i < fullLight.getLuminance(); ++i) {
for (Vector3i pos : Diamond3iIterator.iterateAtDistance(new Vector3i(16, 32, 16), i)) {
assertEquals(fullLight.getLuminance() - i, chunk.getLight(pos));
}
}
}
Aggregations