Examples of DensityFacet


Examples of org.terasology.world.generation.facets.DensityFacet

    }

    @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 (Vector2i pos : rect) {
            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);
    }
View Full Code Here

Examples of org.terasology.world.generation.facets.DensityFacet

    @Override
    public void process(GeneratingRegion region) {
        Border3D borderForTreeFacet = region.getBorderForFacet(TreeFacet.class);
        TreeFacet facet = new TreeFacet(region.getRegion(), borderForTreeFacet.extendBy(0, 15, 10));
        SurfaceHeightFacet surface = region.getRegionFacet(SurfaceHeightFacet.class);
        DensityFacet density = region.getRegionFacet(DensityFacet.class);
        SeaLevelFacet seaLevel = region.getRegionFacet(SeaLevelFacet.class);

        Rect2i worldRegion2D = Rect2i.createFromMinAndMax(facet.getWorldRegion().minX(),
                facet.getWorldRegion().minZ(),
                facet.getWorldRegion().maxX(),
                facet.getWorldRegion().maxZ());

        for (Vector2i pos : worldRegion2D) {
            int x = pos.getX();
            int z = pos.getY();
            int height = TeraMath.floorToInt(surface.getWorld(x, z));
            // if the surface is in range, and if we are above sea level
            if (facet.getWorldRegion().encompasses(x, height, z) && facet.getWorldRegion().encompasses(x, height + 1, z) && height >= seaLevel.getSeaLevel()) {

                // if the block on the surface is dense enough
                if (density.getWorld(x, height, z) >= 0
                        && density.getWorld(x, height + 1, z) < 0
                        // and if there is a level surface in adjacent directions
                        && (x > facet.getWorldRegion().minX() && TeraMath.floorToInt(surface.getWorld(x - 1, z)) == height)
                        && (x < facet.getWorldRegion().maxX() && TeraMath.floorToInt(surface.getWorld(x + 1, z)) == height)
                        && (z > facet.getWorldRegion().minZ() && TeraMath.floorToInt(surface.getWorld(x, z - 1)) == height)
                        && (z < facet.getWorldRegion().maxZ() && TeraMath.floorToInt(surface.getWorld(x, z + 1)) == height)
View Full Code Here

Examples of org.terasology.world.generation.facets.DensityFacet

        dirt = blockManager.getBlock("core:Dirt");
    }

    @Override
    public void generateChunk(CoreChunk chunk, Region chunkRegion) {
        DensityFacet solidityFacet = chunkRegion.getFacet(DensityFacet.class);
        SurfaceHeightFacet surfaceFacet = chunkRegion.getFacet(SurfaceHeightFacet.class);
        BiomeFacet biomeFacet = chunkRegion.getFacet(BiomeFacet.class);
        Vector2i pos2d = new Vector2i();
        for (Vector3i pos : ChunkConstants.CHUNK_REGION) {
            pos2d.set(pos.x, pos.z);
            CoreBiome 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)) - pos.y - chunk.getChunkWorldOffsetY();
                Block block = getSurfaceBlock(depth, pos.y + chunk.getChunkWorldOffsetY(), biome);
View Full Code Here

Examples of org.terasology.world.generation.facets.DensityFacet

    @Override
    public void process(GeneratingRegion region) {
        PlantFacet facet = new PlantFacet(region.getRegion(), region.getBorderForFacet(PlantFacet.class));
        SurfaceHeightFacet surface = region.getRegionFacet(SurfaceHeightFacet.class);
        DensityFacet density = region.getRegionFacet(DensityFacet.class);
        BiomeFacet biomeFacet = region.getRegionFacet(BiomeFacet.class);

        int minY = facet.getWorldRegion().minY();
        int maxY = facet.getWorldRegion().maxY();
        for (int z = facet.getRelativeRegion().minZ(); z <= facet.getRelativeRegion().maxZ(); ++z) {
            for (int x = facet.getRelativeRegion().minX(); x <= facet.getRelativeRegion().maxX(); ++x) {
                int height = TeraMath.floorToInt(surface.get(x, z));
                if (height >= minY && height < maxY) {
                    CoreBiome biome = biomeFacet.get(x, z);
                    height = height - minY + facet.getRelativeRegion().minY();

                    if ((biome == CoreBiome.FOREST || biome == CoreBiome.PLAINS) && density.get(x, height, z) > 0
                            && density.get(x, height + 1, z) <= 0 && noiseTable.noise(x, z) < configuration.density) {
                        facet.set(x, height + 1, z, true);
                    }
                }
            }
        }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.