protected void GenerateRiver(IChunk c, int x, int y, int z, double heightPercentage, BIOME_TYPE type) { // Rivers under water? Nope. if (y <= 63) { return; } double lakeIntens = CalcLakeIntensity(x + c.Coords.ChunkX * 16, z + c.Coords.ChunkZ * 16); short currentIndex = (short)(x << 11 | z << 7 | y); if (lakeIntens < 0.2) { if (heightPercentage < 0.001) { c.SetType(x, y, z, BlockData.Blocks.Air, false); } else if (heightPercentage < 0.02) { if (type == BIOME_TYPE.SNOW) { // To be sure that there's no snow above us c.SetType(x, y + 1, z, BlockData.Blocks.Air, false); c.SetType(x, y, z, BlockData.Blocks.Ice, false); } else { c.SetType(x, y, z, BlockData.Blocks.Still_Water, false); } } } }
private void GenerateTree(IChunk c, int x, int y, int z) { // Trees should only be placed in direct sunlight if (!CanSeeTheSky(x, y + 1, z, c)) { return; } double r2 = _FastRandom.standNormalDistrDouble(); /*if (r2 > -2 && r2 < -1) * {*/ // Standard tree for (int by = y + 4; by < y + 6; by++) { for (int bx = x - 2; bx <= x + 2; bx++) { for (int bz = z - 2; bz <= z + 2; bz++) { c.SetType(bx, by, bz, BlockData.Blocks.Leaves, false); c.SetData(bx, by, bz, 0, false); } } } for (int bx = x - 1; bx <= x + 1; bx++) { for (int bz = z - 1; bz <= z + 1; bz++) { c.SetType(bx, y + 6, bz, BlockData.Blocks.Leaves, false); c.SetData(bx, y + 6, bz, 0, false); } } for (int by = y + 1; by < y + 6; by++) { c.SetType(x, by, z, BlockData.Blocks.Wood, false); c.SetData(x, by, z, 0, false); } //} // TODO: other tree types /*else if (r2 > 1 && r2 < 2) * { * c.setBlock(x, y + 1, z, (byte)0x0); * c.getParent().getObjectGenerator("firTree").generate(c.getBlockWorldPosX(x), y + 1, c.getBlockWorldPosZ(z), false); * } * else * { * c.setBlock(x, y + 1, z, (byte)0x0); * c.getParent().getObjectGenerator("tree").generate(c.getBlockWorldPosX(x), y + 1, c.getBlockWorldPosZ(z), false); * }*/ }
private void GenerateResource(int x, int y, int z, IChunk c) { if (r.Next(100 * y) == 0) { c.SetType(x, y, z, BlockData.Blocks.Diamond_Ore, false); } else if (r.Next(100 * y) == 0) { c.SetType(x, y, z, BlockData.Blocks.Lapis_Lazuli_Ore, false); } else if (r.Next(40 * y) == 0) { c.SetType(x, y, z, BlockData.Blocks.Gold_Ore, false); } else if (r.Next(10 * y) == 0) { c.SetType(x, y, z, BlockData.Blocks.Redstone_Ore_Glowing, false); } else if (r.Next(4 * y) == 0) { c.SetType(x, y, z, BlockData.Blocks.Iron_Ore, false); } else if (r.Next(2 * y) == 0) { c.SetType(x, y, z, BlockData.Blocks.Coal_Ore, false); } }
private void GenerateCactus(IChunk c, int x, int y, int z) { int height = (_FastRandom.randomInt() + 1) % 3; if (!CanSeeTheSky(x, y + 1, z, c)) { return; } for (int by = height; by < y + height; ++y) { c.SetType(x, y, z, BlockData.Blocks.Cactus, false); } }
private void GenerateInnerLayer(int x, int y, int z, BIOME_TYPE type, IChunk c) { c.SetType(x, y, z, BlockData.Blocks.Stone, false); }
protected void GenerateRiver(IChunk c, int x, int y, int z, double heightPercentage, BIOME_TYPE type) { // Rivers under water? Nope. if (y <= 63) return; double lakeIntens = CalcLakeIntensity(x + c.Coords.ChunkX * 16, z + c.Coords.ChunkZ * 16); short currentIndex = (short)(x << 11 | z << 7 | y); if (lakeIntens < 0.2) { if (heightPercentage < 0.001) c.SetType(x, y, z, BlockData.Blocks.Air, false); else if (heightPercentage < 0.02) { if (type == BIOME_TYPE.SNOW) { // To be sure that there's no snow above us c.SetType(x, y + 1, z, BlockData.Blocks.Air, false); c.SetType(x, y, z, BlockData.Blocks.Ice, false); } else c.SetType(x, y, z, BlockData.Blocks.Still_Water, false); } } }
private void GenerateOuterLayer(int x, int y, int z, int firstBlockHeight, BIOME_TYPE type, IChunk c) { double heightPercentage = (firstBlockHeight - y) / 128.0; switch (type) { case BIOME_TYPE.PLAINS: case BIOME_TYPE.MOUNTAINS: // Beach if (y >= 60 && y <= 66) { c.SetBiomeColumn(x, z, (byte)BIOME_TYPE.MOUNTAINS); c.SetType(x, y, z, BlockData.Blocks.Sand, false); break; } c.SetBiomeColumn(x, z, (byte)BIOME_TYPE.MOUNTAINS); if (heightPercentage == 0.0 && y > 66) { // Grass on top c.SetType(x, y, z, BlockData.Blocks.Grass, false); } else if (heightPercentage > 0.2) { // Stone c.SetType(x, y, z, BlockData.Blocks.Stone, false); } else { // Dirt c.SetType(x, y, z, BlockData.Blocks.Dirt, false); } GenerateRiver(c, x, y, z, heightPercentage, type); break; case BIOME_TYPE.SNOW: c.SetBiomeColumn(x, z, (byte)BIOME_TYPE.SNOW); if (heightPercentage == 0.0 && y > 65) { // Snow on top c.SetType(x, y, z, BlockData.Blocks.Snow, false); // Grass under the snow c.SetType(x, y - 1, z, BlockData.Blocks.Grass, false); } else if (heightPercentage > 0.2) // Stone c.SetType(x, y, z, BlockData.Blocks.Stone, false); else // Dirt c.SetType(x, y, z, BlockData.Blocks.Dirt, false); GenerateRiver(c, x, y, z, heightPercentage, type); break; case BIOME_TYPE.DESERT: c.SetBiomeColumn(x, z, (byte)BIOME_TYPE.DESERT); /*if (heightPercentage > 0.6 && y < 75) { // Stone data[x << 11 | z << 7 | y] = (byte)BlockData.Blocks.Stone; } else*/ if (y < 80) c.SetType(x, y, z, BlockData.Blocks.Sand, false); break; } }
private void GenerateTree(IChunk c, int x, int y, int z) { // Trees should only be placed in direct sunlight if (!CanSeeTheSky(x, y + 1, z, c)) return; double r2 = _FastRandom.standNormalDistrDouble(); /*if (r2 > -2 && r2 < -1) {*/ // Standard tree for (int by = y + 4; by < y + 6; by++) for (int bx = x - 2; bx <= x + 2; bx++) for (int bz = z - 2; bz <= z + 2; bz++) { c.SetType(bx, by, bz, BlockData.Blocks.Leaves, false); c.SetData(bx, by, bz, 0, false); } for (int bx = x - 1; bx <= x + 1; bx++) for (int bz = z - 1; bz <= z + 1; bz++) { c.SetType(bx, y + 6, bz, BlockData.Blocks.Leaves, false); c.SetData(bx, y + 6, bz, 0, false); } for (int by = y + 1; by < y + 6; by++) { c.SetType(x, by, z, BlockData.Blocks.Wood, false); c.SetData(x, by, z, 0, false); } //} // TODO: other tree types /*else if (r2 > 1 && r2 < 2) { c.setBlock(x, y + 1, z, (byte)0x0); c.getParent().getObjectGenerator("firTree").generate(c.getBlockWorldPosX(x), y + 1, c.getBlockWorldPosZ(z), false); } else { c.setBlock(x, y + 1, z, (byte)0x0); c.getParent().getObjectGenerator("tree").generate(c.getBlockWorldPosX(x), y + 1, c.getBlockWorldPosZ(z), false); }*/ }
private void GenerateCactus(IChunk c, int x, int y, int z) { int height = (_FastRandom.randomInt() + 1) % 3; if (!CanSeeTheSky(x, y + 1, z, c)) return; for (int by = height; by < y + height; ++y) c.SetType(x, y, z, BlockData.Blocks.Cactus, false); }
private void GenerateFlora(IChunk c, int x, int z) { BIOME_TYPE biome = CalcBiomeType(x, z); for (int bx = 0; bx < 16; ++bx) { int worldX = bx + x * 16; for (int bz = 0; bz < 16; ++bz) { int worldZ = bz + z * 16; for (int by = 64; by < 128; ++by) { int worldY = by; //int index = bx << 11 | bz << 7 | by + 1; if (c.GetType(bx, by, bz) == BlockData.Blocks.Grass && c.GetType(bx, by + 1, bz) == (byte)BlockData.Blocks.Air) { double grassDens = CalcGrassDensity(worldX, worldZ); if (grassDens > 0.0) { // Generate high grass. double rand = _FastRandom.standNormalDistrDouble(); if (rand > -0.2 && rand < 0.2) { c.SetType(bx, by + 1, bz, BlockData.Blocks.TallGrass, false); c.SetData(bx, by + 1, bz, 1, false); } //Generate flowers. if (_FastRandom.standNormalDistrDouble() < -2) { if (_FastRandom.randomBoolean()) c.SetType(bx, by + 1, bz, BlockData.Blocks.Rose, false); else c.SetType(bx, by + 1, bz, BlockData.Blocks.Yellow_Flower, false); } } if (by < 110 && bx % 4 == 0 && bz % 4 == 0) { double forestDens = CalcForestDensity(worldX, worldZ); if (forestDens > 0.005) { int randX = bx + _FastRandom.randomInt() % 12 + 4; int randZ = bz + _FastRandom.randomInt() % 12 + 4; if (randX < 3) randX = 3; else if (randX > 12) randX = 12; if (randZ < 3) randZ = 3; else if (randZ > 15) randZ = 12; if (c.GetType(randX, by, randZ) == BlockData.Blocks.Grass) GenerateTree(c, randX, by, randZ); else if (biome == BIOME_TYPE.DESERT && c.GetType(randX, by, randZ) == BlockData.Blocks.Sand) GenerateCactus(c, randX, by, randZ); } } } } } } }
private void GenerateResource(int x, int y, int z, IChunk c) { if (r.Next(100 * y) == 0) c.SetType(x, y, z, BlockData.Blocks.Diamond_Ore, false); else if (r.Next(100 * y) == 0) c.SetType(x, y, z, BlockData.Blocks.Lapis_Lazuli_Ore, false); else if (r.Next(40 * y) == 0) c.SetType(x, y, z, BlockData.Blocks.Gold_Ore, false); else if (r.Next(10 * y) == 0) c.SetType(x, y, z, BlockData.Blocks.Redstone_Ore_Glowing, false); else if (r.Next(4 * y) == 0) c.SetType(x, y, z, BlockData.Blocks.Iron_Ore, false); else if (r.Next(2 * y) == 0) c.SetType(x, y, z, BlockData.Blocks.Coal_Ore, false); }
private void GenerateTerrain(IChunk c, int x, int z) { double[, ,] density = new double[17, 129, 17]; // Build the density map with lower resolution, 4*4*16 instead of 16*16*128 for (int bx = 0; bx <= 16; bx += 4) { int worldX = bx + (x * 16); for (int bz = 0; bz <= 16; bz += 4) { BIOME_TYPE type = CalcBiomeType(x, z); int worldZ = bz + (z * 16); for (int by = 0; by <= 128; by += 8) { density[bx, by, bz] = CalcDensity(worldX, by, worldZ, type); } } } triLerpDensityMap(density); for (int bx = 0; bx < 16; bx++) { int worldX = bx + (x * 16); for (int bz = 0; bz < 16; bz++) { int worldZ = bz + (z * 16); int firstBlockHeight = -1; BIOME_TYPE type = CalcBiomeType(worldX, worldZ); for (int by = 127; by >= 0; --by) { //int index = bx << 11 | bz << 7 | by; if (by == 0) // First bedrock Layer c.SetType(bx, by, bz, BlockData.Blocks.Bedrock, false); else if (by > 0 && by < 5 && _FastRandom.randomDouble() > 0.3) // Randomly put blocks of the remaining 4 layers of bedrock c.SetType(bx, by, bz, BlockData.Blocks.Bedrock, false); else if (by <= 55) c.SetType(bx, by, bz, BlockData.Blocks.Stone, false); else { if (by > 55 && by < 64) { c.SetType(bx, by, bz, BlockData.Blocks.Still_Water, false); if (by == 63 && type == BIOME_TYPE.SNOW) { c.SetBiomeColumn(bx, bz, (byte)BIOME_TYPE.SNOW); c.SetType(bx, by, bz, BlockData.Blocks.Ice, false); } } double dens = density[bx, by, bz]; if (dens >= 0.009 && dens <= 0.02) { // Some block was set... if (firstBlockHeight == -1) firstBlockHeight = by; GenerateOuterLayer(bx, by, bz, firstBlockHeight, type, c); } else if (dens > 0.02) { // Some block was set... if (firstBlockHeight == -1) firstBlockHeight = by; if (CalcCaveDensity(worldX, by, worldZ) > -0.6) GenerateInnerLayer(bx, by, bz, type, c); } else firstBlockHeight = -1; } if (c.GetType(bx, by, bz) == BlockData.Blocks.Stone) GenerateResource(bx, by, bz, c); } } } }
private void GenerateOuterLayer(int x, int y, int z, int firstBlockHeight, BIOME_TYPE type, IChunk c) { double heightPercentage = (firstBlockHeight - y) / 128.0; switch (type) { case BIOME_TYPE.PLAINS: case BIOME_TYPE.MOUNTAINS: // Beach if (y >= 60 && y <= 66) { c.SetBiomeColumn(x, z, (byte)BIOME_TYPE.MOUNTAINS); c.SetType(x, y, z, BlockData.Blocks.Sand, false); break; } c.SetBiomeColumn(x, z, (byte)BIOME_TYPE.MOUNTAINS); if (heightPercentage == 0.0 && y > 66) { // Grass on top c.SetType(x, y, z, BlockData.Blocks.Grass, false); } else if (heightPercentage > 0.2) { // Stone c.SetType(x, y, z, BlockData.Blocks.Stone, false); } else { // Dirt c.SetType(x, y, z, BlockData.Blocks.Dirt, false); } GenerateRiver(c, x, y, z, heightPercentage, type); break; case BIOME_TYPE.SNOW: c.SetBiomeColumn(x, z, (byte)BIOME_TYPE.SNOW); if (heightPercentage == 0.0 && y > 65) { // Snow on top c.SetType(x, y, z, BlockData.Blocks.Snow, false); // Grass under the snow c.SetType(x, y - 1, z, BlockData.Blocks.Grass, false); } else if (heightPercentage > 0.2) { // Stone c.SetType(x, y, z, BlockData.Blocks.Stone, false); } else { // Dirt c.SetType(x, y, z, BlockData.Blocks.Dirt, false); } GenerateRiver(c, x, y, z, heightPercentage, type); break; case BIOME_TYPE.DESERT: c.SetBiomeColumn(x, z, (byte)BIOME_TYPE.DESERT); /*if (heightPercentage > 0.6 && y < 75) * { * // Stone * data[x << 11 | z << 7 | y] = (byte)BlockData.Blocks.Stone; * } * else*/ if (y < 80) { c.SetType(x, y, z, BlockData.Blocks.Sand, false); } break; } }
private void GenerateFlora(IChunk c, int x, int z) { BIOME_TYPE biome = CalcBiomeType(x, z); for (int bx = 0; bx < 16; ++bx) { int worldX = bx + x * 16; for (int bz = 0; bz < 16; ++bz) { int worldZ = bz + z * 16; for (int by = 64; by < 128; ++by) { int worldY = by; //int index = bx << 11 | bz << 7 | by + 1; if (c.GetType(bx, by, bz) == BlockData.Blocks.Grass && c.GetType(bx, by + 1, bz) == (byte)BlockData.Blocks.Air) { double grassDens = CalcGrassDensity(worldX, worldZ); if (grassDens > 0.0) { // Generate high grass. double rand = _FastRandom.standNormalDistrDouble(); if (rand > -0.2 && rand < 0.2) { c.SetType(bx, by + 1, bz, BlockData.Blocks.TallGrass, false); c.SetData(bx, by + 1, bz, 1, false); } //Generate flowers. if (_FastRandom.standNormalDistrDouble() < -2) { if (_FastRandom.randomBoolean()) { c.SetType(bx, by + 1, bz, BlockData.Blocks.Rose, false); } else { c.SetType(bx, by + 1, bz, BlockData.Blocks.Yellow_Flower, false); } } } if (by < 110 && bx % 4 == 0 && bz % 4 == 0) { double forestDens = CalcForestDensity(worldX, worldZ); if (forestDens > 0.005) { int randX = bx + _FastRandom.randomInt() % 12 + 4; int randZ = bz + _FastRandom.randomInt() % 12 + 4; if (randX < 3) { randX = 3; } else if (randX > 12) { randX = 12; } if (randZ < 3) { randZ = 3; } else if (randZ > 15) { randZ = 12; } if (c.GetType(randX, by, randZ) == BlockData.Blocks.Grass) { GenerateTree(c, randX, by, randZ); } else if (biome == BIOME_TYPE.DESERT && c.GetType(randX, by, randZ) == BlockData.Blocks.Sand) { GenerateCactus(c, randX, by, randZ); } } } } } } } }
private void GenerateTerrain(IChunk c, int x, int z) { double[, ,] density = new double[17, 129, 17]; // Build the density map with lower resolution, 4*4*16 instead of 16*16*128 for (int bx = 0; bx <= 16; bx += 4) { int worldX = bx + (x * 16); for (int bz = 0; bz <= 16; bz += 4) { BIOME_TYPE type = CalcBiomeType(x, z); int worldZ = bz + (z * 16); for (int by = 0; by <= 128; by += 8) { density[bx, by, bz] = CalcDensity(worldX, by, worldZ, type); } } } triLerpDensityMap(density); for (int bx = 0; bx < 16; bx++) { int worldX = bx + (x * 16); for (int bz = 0; bz < 16; bz++) { int worldZ = bz + (z * 16); int firstBlockHeight = -1; BIOME_TYPE type = CalcBiomeType(worldX, worldZ); for (int by = 127; by >= 0; --by) { //int index = bx << 11 | bz << 7 | by; if (by == 0) // First bedrock Layer { c.SetType(bx, by, bz, BlockData.Blocks.Bedrock, false); } else if (by > 0 && by < 5 && _FastRandom.randomDouble() > 0.3) // Randomly put blocks of the remaining 4 layers of bedrock { c.SetType(bx, by, bz, BlockData.Blocks.Bedrock, false); } else if (by <= 55) { c.SetType(bx, by, bz, BlockData.Blocks.Stone, false); } else { if (by > 55 && by < 64) { c.SetType(bx, by, bz, BlockData.Blocks.Still_Water, false); if (by == 63 && type == BIOME_TYPE.SNOW) { c.SetBiomeColumn(bx, bz, (byte)BIOME_TYPE.SNOW); c.SetType(bx, by, bz, BlockData.Blocks.Ice, false); } } double dens = density[bx, by, bz]; if (dens >= 0.009 && dens <= 0.02) { // Some block was set... if (firstBlockHeight == -1) { firstBlockHeight = by; } GenerateOuterLayer(bx, by, bz, firstBlockHeight, type, c); } else if (dens > 0.02) { // Some block was set... if (firstBlockHeight == -1) { firstBlockHeight = by; } if (CalcCaveDensity(worldX, by, worldZ) > -0.6) { GenerateInnerLayer(bx, by, bz, type, c); } } else { firstBlockHeight = -1; } } if (c.GetType(bx, by, bz) == BlockData.Blocks.Stone) { GenerateResource(bx, by, bz, c); } } } } }