Search in sources :

Example 1 with SeaLevelFacet

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

the class AbstractSpawner method findSpawnPosition.

/**
 * Tries to find a suitable spawning point based on {@link SurfaceHeightFacet} and {@link SeaLevelFacet}.
 * @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 SurfaceHeightFacet can be created.
 */
protected Vector3f findSpawnPosition(World world, Vector2i pos, int searchRadius) {
    Vector3i ext = new Vector3i(searchRadius, 1, searchRadius);
    Vector3i desiredPos = new Vector3i(pos.getX(), 1, pos.getY());
    // try and find somewhere in this region a spot to land
    Region3i spawnArea = Region3i.createFromCenterExtents(desiredPos, ext);
    Region worldRegion = world.getWorldData(spawnArea);
    // check if generation uses sea level and surface height facets
    SurfaceHeightFacet surfaceHeightFacet = worldRegion.getFacet(SurfaceHeightFacet.class);
    if (surfaceHeightFacet == null) {
        throw new IllegalStateException("surface height facet not found");
    }
    SeaLevelFacet seaLevelFacet = worldRegion.getFacet(SeaLevelFacet.class);
    int seaLevel = (seaLevelFacet != null) ? seaLevelFacet.getSeaLevel() : 0;
    int spiralRad = searchRadius / 2 - 1;
    SpiralIterable spiral = SpiralIterable.clockwise(pos).maxRadius(spiralRad).scale(2).build();
    for (BaseVector2i test : spiral) {
        float val = surfaceHeightFacet.getWorld(test.getX(), test.getY());
        int height = TeraMath.floorToInt(val);
        if (height >= seaLevel) {
            return new Vector3f(test.getX(), height, test.getY());
        }
    }
    // nothing above sea level found
    float y = surfaceHeightFacet.getWorld(pos.getX(), pos.getY());
    return new Vector3f(pos.getX(), y, pos.getY());
}
Also used : SurfaceHeightFacet(org.terasology.world.generation.facets.SurfaceHeightFacet) Vector3f(org.terasology.math.geom.Vector3f) Vector3i(org.terasology.math.geom.Vector3i) BaseVector2i(org.terasology.math.geom.BaseVector2i) Region(org.terasology.world.generation.Region) SeaLevelFacet(org.terasology.world.generation.facets.SeaLevelFacet) SpiralIterable(org.terasology.math.geom.SpiralIterable) Region3i(org.terasology.math.Region3i)

Example 2 with SeaLevelFacet

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

the class DefaultTreeProvider method getFilters.

protected List<Predicate<Vector3i>> getFilters(GeneratingRegion region) {
    List<Predicate<Vector3i>> filters = Lists.newArrayList();
    SeaLevelFacet seaLevel = region.getRegionFacet(SeaLevelFacet.class);
    filters.add(PositionFilters.minHeight(seaLevel.getSeaLevel()));
    filters.add(PositionFilters.probability(densityNoiseGen, configuration.density * 0.05f));
    SurfaceHeightFacet surface = region.getRegionFacet(SurfaceHeightFacet.class);
    filters.add(PositionFilters.flatness(surface, 1, 0));
    return filters;
}
Also used : SurfaceHeightFacet(org.terasology.world.generation.facets.SurfaceHeightFacet) SeaLevelFacet(org.terasology.world.generation.facets.SeaLevelFacet) Predicate(com.google.common.base.Predicate)

Example 3 with SeaLevelFacet

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

the class PerlinBaseSurfaceProvider method process.

@Override
public void process(GeneratingRegion region) {
    Border3D border = region.getBorderForFacet(SurfaceHeightFacet.class);
    SurfaceHeightFacet facet = new SurfaceHeightFacet(region.getRegion(), border);
    SeaLevelFacet seaLevelFacet = region.getRegionFacet(SeaLevelFacet.class);
    float seaLevel = seaLevelFacet.getSeaLevel();
    Rect2i processRegion = facet.getWorldRegion();
    float[] noise = surfaceNoise.noise(processRegion);
    for (int i = 0; i < noise.length; ++i) {
        noise[i] = seaLevel + seaLevel * ((noise[i] * 2.11f + 1f) / 2f);
    }
    facet.set(noise);
    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) SeaLevelFacet(org.terasology.world.generation.facets.SeaLevelFacet)

Example 4 with SeaLevelFacet

use of org.terasology.world.generation.facets.SeaLevelFacet 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 5 with SeaLevelFacet

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

Aggregations

SeaLevelFacet (org.terasology.world.generation.facets.SeaLevelFacet)7 SurfaceHeightFacet (org.terasology.world.generation.facets.SurfaceHeightFacet)5 Border3D (org.terasology.world.generation.Border3D)3 Predicate (com.google.common.base.Predicate)2 BiomeFacet (org.terasology.core.world.generator.facets.BiomeFacet)2 BaseVector2i (org.terasology.math.geom.BaseVector2i)2 Vector3i (org.terasology.math.geom.Vector3i)2 CoreBiome (org.terasology.core.world.CoreBiome)1 Region3i (org.terasology.math.Region3i)1 Rect2i (org.terasology.math.geom.Rect2i)1 SpiralIterable (org.terasology.math.geom.SpiralIterable)1 Vector2i (org.terasology.math.geom.Vector2i)1 Vector3f (org.terasology.math.geom.Vector3f)1 Biome (org.terasology.world.biomes.Biome)1 Block (org.terasology.world.block.Block)1 Region (org.terasology.world.generation.Region)1 DensityFacet (org.terasology.world.generation.facets.DensityFacet)1 SurfaceDepthFacet (org.terasology.world.generation.facets.SurfaceDepthFacet)1 SurfaceHumidityFacet (org.terasology.world.generation.facets.SurfaceHumidityFacet)1 SurfaceTemperatureFacet (org.terasology.world.generation.facets.SurfaceTemperatureFacet)1