Search in sources :

Example 1 with SurfaceHeightFacet

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

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

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

the class DefaultTreeProvider method process.

@Override
public void process(GeneratingRegion region) {
    SurfaceHeightFacet surface = region.getRegionFacet(SurfaceHeightFacet.class);
    BiomeFacet biome = region.getRegionFacet(BiomeFacet.class);
    List<Predicate<Vector3i>> filters = getFilters(region);
    // these value are derived from the maximum tree extents as
    // computed by the TreeTests class. Birch is the highest with 32
    // and Pine has 13 radius.
    // These values must be identical in the class annotations.
    int maxRad = 13;
    int maxHeight = 32;
    Border3D borderForTreeFacet = region.getBorderForFacet(TreeFacet.class);
    TreeFacet facet = new TreeFacet(region.getRegion(), borderForTreeFacet.extendBy(0, maxHeight, maxRad));
    populateFacet(facet, surface, biome, filters);
    region.setRegionFacet(TreeFacet.class, facet);
}
Also used : SurfaceHeightFacet(org.terasology.world.generation.facets.SurfaceHeightFacet) Border3D(org.terasology.world.generation.Border3D) TreeFacet(org.terasology.core.world.generator.facets.TreeFacet) BiomeFacet(org.terasology.core.world.generator.facets.BiomeFacet) Predicate(com.google.common.base.Predicate)

Example 4 with SurfaceHeightFacet

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

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

the class PerlinOceanProvider method process.

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

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