public void GetChunk(int x, int y, int z, ushort[] chunk) { if (!started) { Init(); started = true; } bool addCaves = (bool)m.GetOption("DefaultGenCaves"); bool addCaveLava = (bool)m.GetOption("DefaultGenLavaCaves"); int ChunkSize = m.GetChunkSize(); x *= ChunkSize; y *= ChunkSize; z *= ChunkSize; int chunksize = ChunkSize; var noise = new LibNoise.FastNoise(); noise.Frequency = 0.01; for (int xx = 0; xx < chunksize; xx++) { for (int yy = 0; yy < chunksize; yy++) { int currentHeight = (byte)((finalTerrain.GetValue((xx + x) / 100.0, 0, (yy + y) / 100.0) * 60) + 64); int ymax = currentHeight; int biome = (int)(BiomeSelect.GetValue((x + xx) / 100.0, 0, (y + yy) / 100.0) * 2); //MD * 2 int toplayer = BLOCK_DIRT; if (biome == 0) { toplayer = BLOCK_DIRT; } if (biome == 1) { toplayer = BLOCK_SAND; } if (biome == 2) { toplayer = BLOCK_DIRT; } if (biome == 3) { toplayer = BLOCK_DIRT; } if (biome == 4) { toplayer = BLOCK_DIRT; } if (biome == 5) { toplayer = BLOCK_CLAY; } int stoneHeight = (int)currentHeight - ((64 - (currentHeight % 64)) / 8) + 1; if (ymax < seaLevel) { ymax = seaLevel; } ymax++; if (ymax > z + chunksize - 1) { ymax = z + chunksize - 1; } for (int bY = z; bY <= ymax; bY++) { int curBlock = 0; // Place bedrock if (bY == 0) { curBlock = BLOCK_BEDROCK; } else if (bY < currentHeight) { if (bY < stoneHeight) { curBlock = BLOCK_STONE; // Add caves if (addCaves) { if (caveNoise.GetValue((x + xx) / 4.0, (bY) / 1.5, (y + yy) / 4.0) > cavestreshold) { if (bY < 10 && addCaveLava) { curBlock = BLOCK_LAVA; } else { curBlock = BLOCK_AIR; } } } } else { curBlock = toplayer; } } else if ((currentHeight + 1) == bY && bY > seaLevel && biome == 3) { curBlock = BLOCK_SNOW; continue; } else if ((currentHeight + 1) == bY && bY > seaLevel + 1) { if (biome == 1 || biome == 0) { continue; } double f = flowers.GetValue(x + xx / 10.0, 0, y + yy / 10.0); if (f < -0.999) { curBlock = BLOCK_RED_ROSE; } else if (f > 0.999) { curBlock = BLOCK_YELLOW_FLOWER; } else if (f < 0.001 && f > -0.001) { curBlock = BLOCK_PUMPKIN; } } else if (currentHeight == bY) { if (bY == seaLevel || bY == seaLevel - 1 || bY == seaLevel - 2) { curBlock = BLOCK_SAND; // FF } else if (bY < seaLevel - 1) { curBlock = BLOCK_GRAVEL; // FF } else if (toplayer == BLOCK_DIRT) { curBlock = BLOCK_GRASS; } else { curBlock = toplayer; // FF } } else { if (bY <= seaLevel) { curBlock = BLOCK_WATER; // FF } else { curBlock = BLOCK_AIR; // FF } if (bY == seaLevel && biome == 3) { curBlock = BLOCK_ICE; } } chunk[m.Index3d(xx, yy, bY - z, chunksize, chunksize)] = (ushort)curBlock; } } } }
public byte[, ,] GetChunk(int x, int y, int z) { byte[, ,] chunk = new byte[ChunkSize, ChunkSize, ChunkSize]; x *= ChunkSize; y *= ChunkSize; z *= ChunkSize; int chunksize = ChunkSize; var noise = new LibNoise.FastNoise(); noise.Frequency = 0.01; for (int xx = 0; xx < chunksize; xx++) { for (int yy = 0; yy < chunksize; yy++) { /* * var v = noise.GetValue(x + xx, y + yy, 0); * //if (v < min) { min = v; } * int height = (int)(((v + 1) * 0.5) * 64) + 5; * //if (height < 0) * { * // Console.Beep(); * } */ int currentHeight = (byte)((finalTerrain.GetValue((xx + x) / 100.0, 0, (yy + y) / 100.0) * 60) + 64); int ymax = currentHeight; /*for (int zz = 0; zz < chunksize; zz++) * { * if (z + zz <= currentHeight) { chunk[xx, yy, zz] = 1; } * }*/ int biome = (int)(BiomeSelect.GetValue((x + xx) / 100.0, 0, (y + yy) / 100.0) * 2); //MD * 2 byte toplayer = BLOCK_DIRT; if (biome == 0) { toplayer = BLOCK_DIRT; } if (biome == 1) { toplayer = BLOCK_SAND; } if (biome == 2) { toplayer = BLOCK_DIRT; } if (biome == 3) { toplayer = BLOCK_DIRT; } if (biome == 4) { toplayer = BLOCK_DIRT; } if (biome == 5) { toplayer = BLOCK_CLAY; } //biomecoun[biome]++; int stoneHeight = (int)currentHeight - ((64 - (currentHeight % 64)) / 8) + 1; int bYbX = ((y << 7) + (x << 11)); if (ymax < seaLevel) { ymax = seaLevel; } ymax++; if (ymax > z + chunksize - 1) //md { ymax = z + chunksize - 1; } //for (int bY = 0; bY <= ymax; bY++) for (int bY = z; bY <= ymax; bY++) { //curBlock = &(chunk->blocks[bYbX++]); int curBlock = 0; // Place bedrock if (bY == 0) { curBlock = BLOCK_BEDROCK; continue; } if (bY < currentHeight) { if (bY < stoneHeight) { curBlock = BLOCK_STONE; // Add caves if (addCaves) { //cave.AddCaves(curBlock, x + xx, bY, y + yy); if (caveNoise.GetValue((x + xx) / 4.0, (bY) / 1.5, (y + yy) / 4.0) > cavestreshold) { if (bY < 10 && addCaveLava) { curBlock = BLOCK_LAVA; } else { curBlock = BLOCK_AIR; } } } } else { curBlock = toplayer; } } else if ((currentHeight + 1) == bY && bY > seaLevel && biome == 3) { curBlock = BLOCK_SNOW; continue; } else if ((currentHeight + 1) == bY && bY > seaLevel + 1) { if (biome == 1 || biome == 0) { continue; } double f = flowers.GetValue(x + xx / 10.0, 0, y + yy / 10.0); if (f < -0.999) { curBlock = BLOCK_RED_ROSE; } else if (f > 0.999) { curBlock = BLOCK_YELLOW_FLOWER; } else if (f < 0.001 && f > -0.001) { curBlock = BLOCK_PUMPKIN; } } else if (currentHeight == bY) { if (bY == seaLevel || bY == seaLevel - 1 || bY == seaLevel - 2) { curBlock = BLOCK_SAND; // FF } else if (bY < seaLevel - 1) { curBlock = BLOCK_GRAVEL; // FF } else if (toplayer == BLOCK_DIRT) { curBlock = BLOCK_GRASS; } else { curBlock = toplayer; // FF } } else { if (bY <= seaLevel) { curBlock = BLOCK_WATER; // FF } else { curBlock = BLOCK_AIR; // FF } if (bY == seaLevel && biome == 3) { curBlock = BLOCK_ICE; } } chunk[xx, yy, bY - z] = (byte)curBlock; } } } return(chunk); }