Exemple #1
0
    /// <summary>
    /// Generates a block for a given position.
    /// </summary>
    /// <param name="pos">The block position.</param>
    /// <returns>ID of generated block at given position.</returns>
    public static Atlas.ID GenerateBlock(BlockPos pos)
    {
        int        x      = pos.GetWorldX();
        int        y      = pos.GetWorldY();
        int        z      = pos.GetWorldZ();
        DataColumn column = GetColumn(pos.chunkPos);

        // Topology
        float stone = column.GetSurface(x, z);
        float dirt  = 3;

        if (y <= stone)
        {
            // Caves
            float caves = SimplexNoise(x, y * 2, z, 40, 12, 1);
            caves += SimplexNoise(x, y, z, 30, 8, 0);
            caves += SimplexNoise(x, y, z, 10, 4, 0);

            if (caves > 16)
            {
                return(Atlas.ID.Air);                // Generating caves
            }

            // Underground ores
            float coal = SimplexNoise(x, y, z, 20, 20, 0);

            if (coal > 18)
            {
                return(Atlas.ID.Coal);
            }

            return(Atlas.ID.Stone);            // Stone layer
        }
        else if (y <= stone + dirt)
        {
            return(Atlas.ID.Dirt);            // Dirt cover
        }
        else if (y <= stone + dirt + 1)
        {
            return(Atlas.ID.Grass);            // Grass cover
        }
        else
        {
            return(Atlas.ID.Air);            // Open Air
        }
    }