Search in sources :

Example 6 with SurfaceHeightFacet

use of org.terasology.world.generation.facets.SurfaceHeightFacet in project Terasology by MovingBlocks.

the class PerlinRiverProvider method process.

@Override
public void process(GeneratingRegion region) {
    SurfaceHeightFacet facet = region.getRegionFacet(SurfaceHeightFacet.class);
    float[] noise = riverNoise.noise(facet.getWorldRegion());
    float[] surfaceHeights = facet.getInternal();
    for (int i = 0; i < noise.length; ++i) {
        surfaceHeights[i] += configuration.maxDepth * TeraMath.clamp(7f * (TeraMath.sqrt(Math.abs(noise[i] * 2.11f)) - 0.1f) + 0.25f);
    }
}
Also used : SurfaceHeightFacet(org.terasology.world.generation.facets.SurfaceHeightFacet)

Example 7 with SurfaceHeightFacet

use of org.terasology.world.generation.facets.SurfaceHeightFacet in project Terasology by MovingBlocks.

the class SurfaceToDensityProvider method process.

@Override
public void process(GeneratingRegion region) {
    SurfaceHeightFacet surfaceHeight = region.getRegionFacet(SurfaceHeightFacet.class);
    DensityFacet facet = new DensityFacet(region.getRegion(), region.getBorderForFacet(DensityFacet.class));
    Region3i area = region.getRegion();
    Rect2i rect = Rect2i.createFromMinAndMax(facet.getRelativeRegion().minX(), facet.getRelativeRegion().minZ(), facet.getRelativeRegion().maxX(), facet.getRelativeRegion().maxZ());
    for (BaseVector2i pos : rect.contents()) {
        float height = surfaceHeight.get(pos);
        for (int y = facet.getRelativeRegion().minY(); y <= facet.getRelativeRegion().maxY(); ++y) {
            facet.set(pos.x(), y, pos.y(), height - area.minY() - y);
        }
    }
    region.setRegionFacet(DensityFacet.class, facet);
}
Also used : SurfaceHeightFacet(org.terasology.world.generation.facets.SurfaceHeightFacet) Rect2i(org.terasology.math.geom.Rect2i) DensityFacet(org.terasology.world.generation.facets.DensityFacet) BaseVector2i(org.terasology.math.geom.BaseVector2i) Region3i(org.terasology.math.Region3i)

Example 8 with SurfaceHeightFacet

use of org.terasology.world.generation.facets.SurfaceHeightFacet in project Terasology by MovingBlocks.

the class SolidRasterizer method generateChunk.

@Override
public void generateChunk(CoreChunk chunk, Region chunkRegion) {
    LiquidData waterLiquid = new LiquidData(LiquidType.WATER, LiquidData.MAX_LIQUID_DEPTH);
    DensityFacet solidityFacet = chunkRegion.getFacet(DensityFacet.class);
    SurfaceHeightFacet surfaceFacet = chunkRegion.getFacet(SurfaceHeightFacet.class);
    SurfaceDepthFacet surfaceDepthFacet = chunkRegion.getFacet(SurfaceDepthFacet.class);
    BiomeFacet biomeFacet = chunkRegion.getFacet(BiomeFacet.class);
    SeaLevelFacet seaLevelFacet = chunkRegion.getFacet(SeaLevelFacet.class);
    int seaLevel = seaLevelFacet.getSeaLevel();
    Vector2i pos2d = new Vector2i();
    for (Vector3i pos : ChunkConstants.CHUNK_REGION) {
        pos2d.set(pos.x, pos.z);
        int posY = pos.y + chunk.getChunkWorldOffsetY();
        // Check for an optional depth for this layer - if defined stop generating below that level
        if (surfaceDepthFacet != null && posY < surfaceDepthFacet.get(pos2d)) {
            continue;
        }
        Biome biome = biomeFacet.get(pos2d);
        chunk.setBiome(pos.x, pos.y, pos.z, biome);
        float density = solidityFacet.get(pos);
        if (density >= 32) {
            chunk.setBlock(pos, stone);
        } else if (density >= 0) {
            int depth = TeraMath.floorToInt(surfaceFacet.get(pos2d)) - posY;
            Block block = getSurfaceBlock(depth, posY, biome, seaLevel);
            chunk.setBlock(pos, block);
        } else {
            // fill up terrain up to sealevel height with water or ice
            if (posY == seaLevel && CoreBiome.SNOW == biome) {
                chunk.setBlock(pos, ice);
            } else if (posY <= seaLevel) {
                // either OCEAN or SNOW
                chunk.setBlock(pos, water);
                chunk.setLiquid(pos, waterLiquid);
            }
        }
    }
}
Also used : SurfaceHeightFacet(org.terasology.world.generation.facets.SurfaceHeightFacet) Biome(org.terasology.world.biomes.Biome) CoreBiome(org.terasology.core.world.CoreBiome) DensityFacet(org.terasology.world.generation.facets.DensityFacet) Vector3i(org.terasology.math.geom.Vector3i) Block(org.terasology.world.block.Block) SeaLevelFacet(org.terasology.world.generation.facets.SeaLevelFacet) Vector2i(org.terasology.math.geom.Vector2i) BiomeFacet(org.terasology.core.world.generator.facets.BiomeFacet) LiquidData(org.terasology.world.liquid.LiquidData) SurfaceDepthFacet(org.terasology.world.generation.facets.SurfaceDepthFacet)

Example 9 with SurfaceHeightFacet

use of org.terasology.world.generation.facets.SurfaceHeightFacet 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);
}
Also used : HashMap(java.util.HashMap) Zone(org.terasology.world.zones.Zone) FacetProvider(org.terasology.world.generation.FacetProvider) Border3D(org.terasology.world.generation.Border3D) MinMaxLayerThickness(org.terasology.world.zones.MinMaxLayerThickness) LayeredZoneRegionFunction(org.terasology.world.zones.LayeredZoneRegionFunction) WorldFacet(org.terasology.world.generation.WorldFacet) SurfaceHeightFacet(org.terasology.world.generation.facets.SurfaceHeightFacet) BaseVector2i(org.terasology.math.geom.BaseVector2i) Vector3i(org.terasology.math.geom.Vector3i) RegionImpl(org.terasology.world.generation.RegionImpl) Before(org.junit.Before)

Example 10 with SurfaceHeightFacet

use of org.terasology.world.generation.facets.SurfaceHeightFacet 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);
}
Also used : SurfaceHeightFacet(org.terasology.world.generation.facets.SurfaceHeightFacet) Rect2i(org.terasology.math.geom.Rect2i) Border3D(org.terasology.world.generation.Border3D) BaseVector2i(org.terasology.math.geom.BaseVector2i)

Aggregations

SurfaceHeightFacet (org.terasology.world.generation.facets.SurfaceHeightFacet)17 BaseVector2i (org.terasology.math.geom.BaseVector2i)9 Border3D (org.terasology.world.generation.Border3D)6 SeaLevelFacet (org.terasology.world.generation.facets.SeaLevelFacet)5 BiomeFacet (org.terasology.core.world.generator.facets.BiomeFacet)4 Rect2i (org.terasology.math.geom.Rect2i)4 Vector3i (org.terasology.math.geom.Vector3i)4 Predicate (com.google.common.base.Predicate)3 Region3i (org.terasology.math.Region3i)3 DensityFacet (org.terasology.world.generation.facets.DensityFacet)2 SurfaceHumidityFacet (org.terasology.world.generation.facets.SurfaceHumidityFacet)2 SurfaceTemperatureFacet (org.terasology.world.generation.facets.SurfaceTemperatureFacet)2 LiquidData (org.terasology.world.liquid.LiquidData)2 HashMap (java.util.HashMap)1 Before (org.junit.Before)1 CoreBiome (org.terasology.core.world.CoreBiome)1 FloraFacet (org.terasology.core.world.generator.facets.FloraFacet)1 TreeFacet (org.terasology.core.world.generator.facets.TreeFacet)1 SpiralIterable (org.terasology.math.geom.SpiralIterable)1 Vector2f (org.terasology.math.geom.Vector2f)1