use of org.terasology.engine.world.block.BlockRegion in project Terasology by MovingBlocks.
the class BulkLightPropagationTest method testRemoveSolidAndLight.
@Test
public void testRemoveSolidAndLight() {
StubPropagatorWorldView worldView = new StubPropagatorWorldView(testingRegion, air);
for (Vector3ic pos : new BlockRegion(1, 0, 0).expand(0, 30, 30)) {
worldView.setBlockAt(new Vector3i(pos), solid);
}
worldView.setBlockAt(new Vector3i(0, 0, 0), fullLight);
BatchPropagator propagator = new StandardBatchPropagator(lightRules, worldView);
propagator.process(new BlockChange(ZERO_VECTOR, air, fullLight));
assertEquals(0, worldView.getValueAt(new Vector3i(1, 0, 0)));
worldView.setBlockAt(new Vector3i(1, 0, 0), air);
worldView.setBlockAt(new Vector3i(0, 0, 0), air);
propagator.process(new BlockChange(new Vector3i(1, 0, 0), solid, air), new BlockChange(ZERO_VECTOR, fullLight, air));
for (int i = 0; i < fullLight.getLuminance() + 1; ++i) {
byte expectedLuminance = (byte) 0;
for (Vector3ic pos : Diamond3iIterable.shell(new Vector3i(0, 0, 0), i).build()) {
assertEquals(expectedLuminance, worldView.getValueAt(pos));
}
}
}
use of org.terasology.engine.world.block.BlockRegion in project Terasology by MovingBlocks.
the class BetweenChunkPropagationTest method testBetweenChunksSimpleSunlightRegenOnly.
@Test
public void testBetweenChunksSimpleSunlightRegenOnly() {
Chunk topChunk = new ChunkImpl(new Vector3i(0, 1, 0), blockManager, extraDataManager);
Chunk bottomChunk = new ChunkImpl(new Vector3i(0, 0, 0), blockManager, extraDataManager);
provider.addChunk(topChunk);
provider.addChunk(bottomChunk);
for (Vector3ic pos : new BlockRegion(0, 0, 0).setSize(Chunks.SIZE_X, 1, Chunks.SIZE_Z)) {
topChunk.setSunlight(pos, Chunks.MAX_SUNLIGHT);
topChunk.setSunlightRegen(pos, Chunks.MAX_SUNLIGHT_REGEN);
}
InternalLightProcessor.generateInternalLighting(bottomChunk);
propagator.propagateBetween(topChunk, bottomChunk, Side.BOTTOM, true);
propagator.process();
for (Vector3ic pos : Chunks.CHUNK_REGION) {
assertEquals(Chunks.MAX_SUNLIGHT_REGEN, bottomChunk.getSunlightRegen(pos), () -> "Incorrect at position " + pos);
}
}
use of org.terasology.engine.world.block.BlockRegion in project Terasology by MovingBlocks.
the class BulkSunlightPropagationTest method testAllowSunlightVertical.
@Test
public void testAllowSunlightVertical() {
for (Vector3ic pos : new BlockRegion(0, 16, 0).union(Chunks.SIZE_X - 1, Chunks.SIZE_Y - 1, Chunks.SIZE_Z - 1)) {
regenWorldView.setValueAt(pos, Chunks.MAX_SUNLIGHT_REGEN);
lightWorldView.setValueAt(pos, Chunks.MAX_SUNLIGHT);
}
for (Vector3ic pos : new BlockRegion(0, 15, 0).union(Chunks.SIZE_X - 1, 15, Chunks.SIZE_Z - 1)) {
regenWorldView.setBlockAt(new Vector3i(pos), solid);
}
for (Vector3ic pos : new BlockRegion(0, 0, 0).union(Chunks.SIZE_X - 1, 14, Chunks.SIZE_Z - 1)) {
regenWorldView.setValueAt(pos, (byte) (14 - pos.y()));
}
regenWorldView.setBlockAt(new Vector3i(16, 15, 16), air);
propagator.process(new BlockChange(new Vector3i(16, 15, 16), solid, air));
sunlightPropagator.process(new BlockChange(new Vector3i(16, 15, 16), solid, air));
for (int y = 0; y < 16; y++) {
assertEquals(Chunks.MAX_SUNLIGHT_REGEN, regenWorldView.getValueAt(new Vector3i(16, y, 16)), "Incorrect value at " + y);
assertEquals(Chunks.MAX_SUNLIGHT, lightWorldView.getValueAt(new Vector3i(16, y, 16)));
}
for (int y = 0; y < 15; y++) {
assertEquals(Chunks.MAX_SUNLIGHT - 1, lightWorldView.getValueAt(new Vector3i(15, y, 16)));
}
}
use of org.terasology.engine.world.block.BlockRegion in project Terasology by MovingBlocks.
the class AbstractSpawner method findSpawnPosition.
/**
* Tries to find a suitable spawning point based on {@link SurfacesFacet} and {@link ElevationFacet}.
* @param searchRadius the radius within a suitable spawning point will be searched
* @param world the facet-based world
* @param pos the desired 2D position in that world
* @return a 3D position above the surface and sea level or <code>null</code> if none was found
* @throws IllegalStateException if no required facets can be created.
*/
protected Vector3f findSpawnPosition(World world, Vector2i pos, int searchRadius) {
Vector3i ext = new Vector3i(searchRadius, searchRadius, searchRadius);
Vector3i desiredPos = new Vector3i(pos.x(), getStartHeight(world, pos), pos.y());
// try and find somewhere in this region a spot to land
BlockRegion spawnArea = new BlockRegion(desiredPos).expand(ext);
Region worldRegion = world.getWorldData(spawnArea);
Function<Vector2ic, Optional<Float>> getWorld;
// check if generation uses sea level and surface height facets
SurfacesFacet surfacesFacet = worldRegion.getFacet(SurfacesFacet.class);
ElevationFacet elevationFacet = worldRegion.getFacet(ElevationFacet.class);
SpawnHeightFacet spawnHeightFacet = worldRegion.getFacet(SpawnHeightFacet.class);
if (spawnHeightFacet != null) {
getWorld = v -> spawnHeightFacet.getWorld(v.x(), v.y());
} else if (elevationFacet != null) {
if (surfacesFacet != null) {
getWorld = v -> surfacesFacet.getPrimarySurface(elevationFacet, v.x(), v.y());
} else {
getWorld = v -> Optional.of(elevationFacet.getWorld(v.x(), v.y()));
}
} else {
throw new IllegalStateException("No spawn height facet or elevation facet facet found. Can't place spawn point.");
}
Function<Vector2ic, Optional<Integer>> getSeaLevel;
SeaLevelFacet seaLevelFacet = worldRegion.getFacet(SeaLevelFacet.class);
StrictlySparseSeaLevelFacet sparseSeaLevelFacet = worldRegion.getFacet(StrictlySparseSeaLevelFacet.class);
if (sparseSeaLevelFacet != null) {
getSeaLevel = v -> sparseSeaLevelFacet.getSeaLevel(v.x(), v.y());
} else if (seaLevelFacet != null) {
getSeaLevel = v -> Optional.of(seaLevelFacet.getSeaLevel());
} else {
getSeaLevel = v -> Optional.of(0);
}
int spiralRad = searchRadius / 2 - 1;
SpiralIterable spiral = SpiralIterable.clockwise(pos).maxRadius(spiralRad).scale(2).build();
for (Vector2ic test : spiral) {
Optional<Float> val = getWorld.apply(test);
if (!val.isPresent()) {
continue;
}
int height = TeraMath.floorToInt(val.get());
if (!getSeaLevel.apply(test).isPresent() || height >= getSeaLevel.apply(test).get()) {
return new Vector3f(test.x(), height, test.y());
}
}
// nothing above sea level found
for (Vector2ic test : spiral) {
Optional<Float> val = getWorld.apply(test);
if (!val.isPresent()) {
continue;
}
return new Vector3f(test.x(), TeraMath.floorToInt(val.get()), test.y());
}
throw new IllegalStateException("No spawn location found");
}
use of org.terasology.engine.world.block.BlockRegion 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, new BlockRegion(0, 0, 0).expand(1, 0, 1), new Vector3i(1, 0, 1), airBlock);
assertEquals(solidBlock, chunkView.getBlock(Chunks.SIZE_X, 0, Chunks.SIZE_Z));
}
Aggregations