Search in sources :

Example 1 with LiquidData

use of org.terasology.world.liquid.LiquidData 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 2 with LiquidData

use of org.terasology.world.liquid.LiquidData in project Terasology by MovingBlocks.

the class WorldProviderCoreImpl method getLiquid.

@Override
public LiquidData getLiquid(int x, int y, int z) {
    Vector3i chunkPos = ChunkMath.calcChunkPos(x, y, z);
    CoreChunk chunk = chunkProvider.getChunk(chunkPos);
    if (chunk != null) {
        Vector3i blockPos = ChunkMath.calcBlockPos(x, y, z);
        return chunk.getLiquid(blockPos);
    }
    return new LiquidData();
}
Also used : CoreChunk(org.terasology.world.chunks.CoreChunk) Vector3i(org.terasology.math.geom.Vector3i) LiquidData(org.terasology.world.liquid.LiquidData)

Example 3 with LiquidData

use of org.terasology.world.liquid.LiquidData in project Terasology by MovingBlocks.

the class WorldProviderCoreImpl method setLiquid.

@Override
public boolean setLiquid(int x, int y, int z, LiquidData newState, LiquidData oldState) {
    Vector3i chunkPos = ChunkMath.calcChunkPos(x, y, z);
    CoreChunk chunk = chunkProvider.getChunk(chunkPos);
    if (chunk != null) {
        Vector3i blockPos = ChunkMath.calcBlockPos(x, y, z);
        LiquidData liquidState = chunk.getLiquid(blockPos);
        if (liquidState.equals(oldState)) {
            chunk.setLiquid(blockPos, newState);
            return true;
        }
    }
    return false;
}
Also used : CoreChunk(org.terasology.world.chunks.CoreChunk) Vector3i(org.terasology.math.geom.Vector3i) LiquidData(org.terasology.world.liquid.LiquidData)

Example 4 with LiquidData

use of org.terasology.world.liquid.LiquidData in project Terasology by MovingBlocks.

the class GroundRasterizer method generateChunk.

@Override
public void generateChunk(CoreChunk chunk, Region chunkRegion) {
    LiquidData waterLiquid = new LiquidData(LiquidType.WATER, LiquidData.MAX_LIQUID_DEPTH);
    SurfaceHeightFacet surfaceHeightData = chunkRegion.getFacet(SurfaceHeightFacet.class);
    Vector3i chunkOffset = chunk.getChunkWorldOffset();
    for (int x = 0; x < chunk.getChunkSizeX(); ++x) {
        for (int z = 0; z < chunk.getChunkSizeZ(); ++z) {
            float surfaceHeight = surfaceHeightData.get(x, z);
            int y;
            for (y = 0; y < chunk.getChunkSizeY() && y + chunkOffset.y < surfaceHeight; ++y) {
                chunk.setBlock(x, y, z, stone);
            }
            for (; y < chunk.getChunkSizeY() && y + chunkOffset.y <= 32; ++y) {
                chunk.setBlock(x, y, z, water);
                chunk.setLiquid(x, y, z, waterLiquid);
            }
        }
    }
}
Also used : SurfaceHeightFacet(org.terasology.world.generation.facets.SurfaceHeightFacet) Vector3i(org.terasology.math.geom.Vector3i) LiquidData(org.terasology.world.liquid.LiquidData)

Aggregations

Vector3i (org.terasology.math.geom.Vector3i)4 LiquidData (org.terasology.world.liquid.LiquidData)4 CoreChunk (org.terasology.world.chunks.CoreChunk)2 SurfaceHeightFacet (org.terasology.world.generation.facets.SurfaceHeightFacet)2 CoreBiome (org.terasology.core.world.CoreBiome)1 BiomeFacet (org.terasology.core.world.generator.facets.BiomeFacet)1 Vector2i (org.terasology.math.geom.Vector2i)1 Biome (org.terasology.world.biomes.Biome)1 Block (org.terasology.world.block.Block)1 DensityFacet (org.terasology.world.generation.facets.DensityFacet)1 SeaLevelFacet (org.terasology.world.generation.facets.SeaLevelFacet)1 SurfaceDepthFacet (org.terasology.world.generation.facets.SurfaceDepthFacet)1