/// <summary> /// From the VoxelSim project /// http://github.com/N3X15/VoxelSim /// </summary> /// <param name="X"></param> /// <param name="Z"></param> /// <param name="chunksize"></param> /// <returns></returns> public override double[,] Generate(IMapHandler mh, long X, long Z, out double minHeight, out double maxHeight) { Vector3i chunksize = mh.ChunkScale; int x_o = (int)(X * chunksize.X); int z_o = (int)(Z * chunksize.Z); int YH = (int)chunksize.Y - 2; double[,] hm = new double[chunksize.X, chunksize.Z]; minHeight = (double)chunksize.Y; maxHeight = 0; for (int x = 0; x < chunksize.X; x++) { for (int z = 0; z < chunksize.Z; z++) { double height = 1 - Utils.FixLibnoiseOutput(ContinentNoise.GetValue((double)(x + x_o) / 10d, (double)(z + z_o) / 10d, 0)); height *= 0.5; height += 0.25; height = Utils.Clamp(height, 0.1, 1); if (height < minHeight) { minHeight = height; } if (height > maxHeight) { maxHeight = height; } hm[x, z] = height; } } return(hm); }
public virtual void AddSoil(long X, long Z, RidgedMultifractal CavernNoise, Perlin CaveNoise, double[,] hm, ref byte[,,] b, BiomeType[,] biomes, int WaterHeight, int depth, MapGenMaterials mats) { int YH = b.GetLength(1) - 2; double xo = (double)(X * b.GetLength(0)); double zo = (double)(Z * b.GetLength(2)); for (int x = 0; x < b.GetLength(0); x++) { //Console.WriteLine(); for (int z = 0; z < b.GetLength(2); z++) { double hmY = (double)(System.Math.Min(hm[x, z], 1d) * (b.GetLength(1) - 3)); bool HavePloppedGrass = false; bool HaveTouchedSoil = false; // Caves first if (GenerateCaves) { for (int y = 0; y < b.GetLength(1); y++) { // If we're in rock, and CavernNoise value is under a threshold value calculated by height // or CaveNoise value is over threshold value, and the block we're removing won't fall on us... if ( b[x, y, z] == 1 && ( ((CavernNoise.GetValue(x + xo, y, z + zo) / 2) + 1) < Utils.Lerp(CavernThresholdMax, CavernThresholdMin, (((double)y / (hmY + 1)))) || (Utils.FixLibnoiseOutput(CaveNoise.GetValue(x + xo, y, z + zo)) > CaveThreshold) ) && !(b[x, y, z] == 9 || b[x, y, z] == 8 || b[x, y, z] == 12 || b[x, y, z] == 13)) { // Remove it b[x, y, z] = 0; } } } for (int y = (int)b.GetLength(1) - 1; y > 0; y--) { byte supportBlock = b[x, y - 1, z]; // Ensure there's going to be stuff holding us up. if (b[x, y, z] == mats.Rock && supportBlock == mats.Rock) { HaveTouchedSoil = true; if (y + depth >= YH) { continue; } byte ddt = b[x, y + depth, z]; switch (ddt) { case 0: // Air case 8: // Water case 9: // Water BiomeType bt = biomes[x, z]; if (bt == BiomeType.Tundra) { b[x, y, z] = mats.Sand; } else { if (y - depth <= WaterHeight && GenerateWater) { if ((bt == BiomeType.Taiga || bt == BiomeType.TemperateForest || bt == BiomeType.Tundra) && y > WaterHeight) { b[x, y, z] = (HavePloppedGrass) ? mats.Soil : mats.Grass; } else { b[x, y, z] = mats.Sand; } } else { b[x, y, z] = (HavePloppedGrass) ? mats.Soil : mats.Grass; } } if (!HavePloppedGrass) { HavePloppedGrass = true; } break; default: y = 0; break; } } else if (b[x, y, z] == 0 && y <= WaterHeight && !HaveTouchedSoil && GenerateWater) { b[x, y, z] = mats.Water; } } } } }