コード例 #1
0
    //Fills the column with air spaces to make caves
    IEnumerator generateCaves(ChunkColumn column)
    {
        //Get the biome of the column
        Biome biome = column.getBiome();

        //Get the coordinates af the column
        int x = column.getLocation().getBlockX();
        int z = column.getLocation().getBlockZ();

        //Get the highest block's z coordinate
        int blockHeight = column.getHighestRenderableBlock().getBlockY();

        //Get the cave size and frequency from the biome
        int   caveSize      = biome.getCaveSize();
        float caveFrequency = biome.getCaveFrequency();

        //Create a noise generator that represents the probability of getting a cave as the caveFrequency as a percent
        NoiseGenerator noiseGenerator = new NoiseGenerator(caveFrequency, 100);

        //Iterate over all solid blocks in the column
        for (int y = 0; y < blockHeight + 1; y++)
        {
            //Get the probability of having a cave at this coordinate
            int caveChance = noiseGenerator.generateNoise(x, y, z);

            //If the cave chance is within the likely hood of generating a cave
            if (caveChance < caveSize)
            {
                Location airLocation = new Location(getWorld(), x, y, z);
                column.setBlock(y, new Air(airLocation));
            }
            yield return(null);
        }
        column.recalculateRendering();
    }