use of org.terasology.engine.world.chunks.Chunk in project Terasology by MovingBlocks.
the class WorldProviderCoreImpl method getTotalLight.
@Override
public byte getTotalLight(int x, int y, int z) {
Vector3i chunkPos = Chunks.toChunkPos(x, y, z, new Vector3i());
Chunk chunk = chunkProvider.getChunk(chunkPos);
if (chunk != null) {
Vector3i blockPos = Chunks.toRelative(x, y, z, new Vector3i());
return (byte) Math.max(chunk.getSunlight(blockPos), chunk.getLight(blockPos));
}
return 0;
}
use of org.terasology.engine.world.chunks.Chunk in project Terasology by MovingBlocks.
the class LocalChunkProviderTest method requestCreatingOrLoadingArea.
private Future<Chunk> requestCreatingOrLoadingArea(Vector3ic chunkPosition, int radius) {
Future<Chunk> chunkFuture = chunkProvider.createOrLoadChunk(chunkPosition);
BlockRegion extentsRegion = new BlockRegion(chunkPosition.x() - radius, chunkPosition.y() - radius, chunkPosition.z() - radius, chunkPosition.x() + radius, chunkPosition.y() + radius, chunkPosition.z() + radius);
extentsRegion.iterator().forEachRemaining(pos -> {
if (!pos.equals(chunkPosition)) {
// remove center. we takes future for it already.
chunkProvider.createOrLoadChunk(pos);
}
});
return chunkFuture;
}
use of org.terasology.engine.world.chunks.Chunk in project Terasology by MovingBlocks.
the class ChunkProcessingPipelineTest method multiRequirementsChunksExistsSuccess.
/**
* Imagine that we have task, which requires neighbors with same Z level. neighbors chunk already in chunk cache.
*/
@Test
void multiRequirementsChunksExistsSuccess() throws ExecutionException, InterruptedException, TimeoutException {
Vector3i positionToGenerate = new Vector3i(0, 0, 0);
Map<Vector3ic, Chunk> chunkCache = getNearChunkPositions(positionToGenerate).stream().filter(// remove central chunk.
(p) -> !p.equals(positionToGenerate)).map(this::createChunkAt).collect(Collectors.toMap((chunk) -> chunk.getPosition(new Vector3i()), Function.identity()));
pipeline = new ChunkProcessingPipeline(chunkCache::get, (o1, o2) -> 0);
pipeline.addStage(ChunkTaskProvider.createMulti("flat merging task", (chunks) -> chunks.stream().filter((c) -> c.getPosition().equals(positionToGenerate)).findFirst().get(), this::getNearChunkPositions));
Chunk chunk = createChunkAt(positionToGenerate);
Future<Chunk> chunkFuture = pipeline.invokeGeneratorTask(new Vector3i(0, 0, 0), () -> chunk);
Chunk chunkAfterProcessing = chunkFuture.get(1, TimeUnit.SECONDS);
Assertions.assertEquals(chunkAfterProcessing.getPosition(new Vector3i()), chunk.getPosition(new Vector3i()), "Chunk after processing must have equals position, probably pipeline lost you chunk");
}
use of org.terasology.engine.world.chunks.Chunk in project Terasology by MovingBlocks.
the class ChunkProcessingPipelineTest method simpleStopProcessingSuccess.
@Test
void simpleStopProcessingSuccess() {
pipeline = new ChunkProcessingPipeline((p) -> null, (o1, o2) -> 0);
Vector3i position = new Vector3i(0, 0, 0);
Chunk chunk = createChunkAt(position);
pipeline.addStage(ChunkTaskProvider.create("dummy long executing task", (c) -> {
try {
Thread.sleep(1_000);
} catch (InterruptedException e) {
}
return c;
}));
Future<Chunk> chunkFuture = pipeline.invokeGeneratorTask(position, () -> chunk);
pipeline.stopProcessingAt(position);
Assertions.assertThrows(CancellationException.class, () -> chunkFuture.get(1, TimeUnit.SECONDS), "chunkFuture must be cancelled, when processing stopped");
}
use of org.terasology.engine.world.chunks.Chunk in project Terasology by MovingBlocks.
the class ChunkViewTest method testSimpleWorldView.
@Test
public void testSimpleWorldView() {
Chunk chunk = createChunk(0, 0, 0);
chunk.setBlock(new Vector3i(0, 0, 0), solidBlock);
ChunkViewCore chunkView = new ChunkViewCoreImpl(new Chunk[] { chunk }, new BlockRegion(0, 0, 0), new Vector3i(), airBlock);
assertEquals(solidBlock, chunkView.getBlock(0, 0, 0));
}
Aggregations