use of org.terasology.world.generation.Border3D in project Terasology by MovingBlocks.
the class BooleanFacetTest method setup.
@Before
public void setup() {
Border3D border = new Border3D(0, 0, 0).extendBy(0, 15, 10);
Vector3i min = new Vector3i(10, 20, 30);
Vector3i size = new Vector3i(40, 50, 60);
Region3i region = Region3i.createFromMinAndSize(min, size);
facet = createFacet(region, border);
// facet = [worldMin=(0, 5, 20), relativeMin=(-10, -15, -10), size=(60, 65, 80)]
}
use of org.terasology.world.generation.Border3D in project Terasology by MovingBlocks.
the class LayeredZoneRegionFunctionTest method setup.
@Before
public void setup() {
parent.addZone(new Zone("Medium sky", new LayeredZoneRegionFunction(new MinMaxLayerThickness(100, 100), MEDIUM_SKY))).addZone(new Zone("Low sky", new LayeredZoneRegionFunction(new MinMaxLayerThickness(100, 100), LOW_SKY))).addZone(new Zone("Above ground", new LayeredZoneRegionFunction(new MinMaxLayerThickness(100, 100), ABOVE_GROUND))).addZone(new Zone("Ground", new LayeredZoneRegionFunction(new MinMaxLayerThickness(100, 100), GROUND))).addZone(new Zone("Shallow underground", new LayeredZoneRegionFunction(new MinMaxLayerThickness(100, 100), SHALLOW_UNDERGROUND))).addZone(new Zone("Medium underground", new LayeredZoneRegionFunction(new MinMaxLayerThickness(100, 100), MEDIUM_UNDERGROUND)));
parent.setSeed(12345);
parent.initialize();
ListMultimap<Class<? extends WorldFacet>, FacetProvider> facetProviderChains = ArrayListMultimap.create();
facetProviderChains.put(SurfaceHeightFacet.class, (generatingRegion) -> {
SurfaceHeightFacet facet = new SurfaceHeightFacet(generatingRegion.getRegion(), generatingRegion.getBorderForFacet(SurfaceHeightFacet.class));
for (BaseVector2i pos : facet.getRelativeRegion().contents()) {
facet.set(pos, 100);
}
generatingRegion.setRegionFacet(SurfaceHeightFacet.class, facet);
});
Map<Class<? extends WorldFacet>, Border3D> borders = new HashMap<>();
borders.put(SurfaceHeightFacet.class, new Border3D(0, 0, 0));
region = new RegionImpl(Region3i.createFromCenterExtents(new Vector3i(0, 0, 0), 4), facetProviderChains, borders);
}
use of org.terasology.world.generation.Border3D in project Terasology by MovingBlocks.
the class SurfaceProvider method process.
@Override
public void process(GeneratingRegion region) {
// Create our surface height facet (we will get into borders later)
Border3D border = region.getBorderForFacet(SurfaceHeightFacet.class);
SurfaceHeightFacet facet = new SurfaceHeightFacet(region.getRegion(), border);
// loop through every position on our 2d array
Rect2i processRegion = facet.getWorldRegion();
for (BaseVector2i position : processRegion.contents()) {
facet.setWorld(position, surfaceNoise.noise(position.x(), position.y()) * 20);
}
// give our newly created and populated facet to the region
region.setRegionFacet(SurfaceHeightFacet.class, facet);
}
use of org.terasology.world.generation.Border3D in project Terasology by MovingBlocks.
the class BiomeProvider method process.
@Override
public void process(GeneratingRegion region) {
SeaLevelFacet seaLevelFacet = region.getRegionFacet(SeaLevelFacet.class);
SurfaceHeightFacet heightFacet = region.getRegionFacet(SurfaceHeightFacet.class);
SurfaceTemperatureFacet temperatureFacet = region.getRegionFacet(SurfaceTemperatureFacet.class);
SurfaceHumidityFacet humidityFacet = region.getRegionFacet(SurfaceHumidityFacet.class);
Border3D border = region.getBorderForFacet(BiomeFacet.class);
BiomeFacet biomeFacet = new BiomeFacet(region.getRegion(), border);
int seaLevel = seaLevelFacet.getSeaLevel();
for (BaseVector2i pos : biomeFacet.getRelativeRegion().contents()) {
float temp = temperatureFacet.get(pos);
float hum = temp * humidityFacet.get(pos);
float height = heightFacet.get(pos);
if (height <= seaLevel) {
biomeFacet.set(pos, CoreBiome.OCEAN);
} else if (height <= seaLevel + 2) {
biomeFacet.set(pos, CoreBiome.BEACH);
} else if (temp >= 0.5f && hum < 0.3f) {
biomeFacet.set(pos, CoreBiome.DESERT);
} else if (hum >= 0.3f && hum <= 0.6f && temp >= 0.5f) {
biomeFacet.set(pos, CoreBiome.PLAINS);
} else if (temp <= 0.3f && hum > 0.5f) {
biomeFacet.set(pos, CoreBiome.SNOW);
} else if (hum >= 0.2f && hum <= 0.6f && temp < 0.5f) {
biomeFacet.set(pos, CoreBiome.MOUNTAINS);
} else {
biomeFacet.set(pos, CoreBiome.FOREST);
}
}
region.setRegionFacet(BiomeFacet.class, biomeFacet);
}
use of org.terasology.world.generation.Border3D in project Terasology by MovingBlocks.
the class HeightMapSurfaceHeightProvider method process.
@Override
public void process(GeneratingRegion region) {
Border3D border = region.getBorderForFacet(SurfaceHeightFacet.class);
SurfaceHeightFacet facet = new SurfaceHeightFacet(region.getRegion(), border);
for (BaseVector2i pos : facet.getWorldRegion().contents()) {
int xzScale = configuration.terrainScale;
int mapX0;
int mapZ0;
int mapX1;
int mapZ1;
switch(configuration.wrapMode) {
case CLAMP:
mapX0 = TeraMath.clamp(pos.getX(), 0, mapWidth * xzScale - 1) / xzScale;
mapZ0 = TeraMath.clamp(pos.getY(), 0, mapHeight * xzScale - 1) / xzScale;
mapX1 = TeraMath.clamp(mapX0 + 1, 0, mapWidth - 1);
mapZ1 = TeraMath.clamp(mapZ0 + 1, 0, mapHeight - 1);
break;
case REPEAT:
mapX0 = IntMath.mod(pos.getX(), mapWidth * xzScale) / xzScale;
mapZ0 = IntMath.mod(pos.getY(), mapHeight * xzScale) / xzScale;
mapX1 = IntMath.mod(mapX0 + 1, mapWidth);
mapZ1 = IntMath.mod(mapZ0 + 1, mapHeight);
break;
default:
throw new UnsupportedOperationException("Not supported: " + configuration.wrapMode);
}
double p00 = heightmap[mapX0][mapZ0];
double p10 = heightmap[mapX1][mapZ0];
double p11 = heightmap[mapX1][mapZ1];
double p01 = heightmap[mapX0][mapZ1];
float relX = IntMath.mod(pos.getX(), xzScale) / (float) xzScale;
float relZ = IntMath.mod(pos.getY(), xzScale) / (float) xzScale;
float interpolatedHeight = (float) lerp(relX, lerp(relZ, p00, p01), lerp(relZ, p10, p11));
float height = configuration.heightOffset + configuration.heightScale * interpolatedHeight;
facet.setWorld(pos, height);
}
region.setRegionFacet(SurfaceHeightFacet.class, facet);
}
Aggregations