private static void Test(Level level, BlockCoordinates coord, BlockCoordinates newCoord, Queue <BlockCoordinates> lightBfsQueue, ChunkColumn chunk, int lightLevel) { //Interlocked.Add(ref touches, 1); var newChunkCoord = (ChunkCoordinates)newCoord; if (chunk.X != newChunkCoord.X || chunk.Z != newChunkCoord.Z) { chunk = GetChunk(level, newCoord); } if (chunk == null) { return; } if (chunk.GetBlockId(newCoord.X & 0x0f, newCoord.Y & 0xff, newCoord.Z & 0x0f) == 0) { SetLightLevel(chunk, lightBfsQueue, newCoord, lightLevel); } else { //if (BlockFactory.LuminousBlocks.ContainsKey(chunk.GetBlocklight(newCoord.X & 0x0f, newCoord.Y & 0xff, newCoord.Z & 0x0f))) //{ //} //else { SetLightLevel(chunk, lightBfsQueue, level.GetBlock(newCoord, chunk), lightLevel); } } }
public static bool IsNotBlockingSkylight(BlockCoordinates blockCoordinates, ChunkColumn chunk) { if (chunk == null) { return(true); } int bid = chunk.GetBlockId(blockCoordinates.X & 0x0f, blockCoordinates.Y & 0xff, blockCoordinates.Z & 0x0f); return(bid == 0 || (BlockFactory.TransparentBlocks[bid] == 1 && bid != 18 && bid != 161 && bid != 30 && bid != 8 && bid != 9)); }
private void PopulateChunk(ChunkColumn chunk) { int trees = new Random().Next(0, 10); int[,] treeBasePositions = new int[trees, 2]; for (int t = 0; t < trees; t++) { int x = new Random().Next(1, 16); int z = new Random().Next(1, 16); treeBasePositions[t, 0] = x; treeBasePositions[t, 1] = z; } var bottom = new SimplexOctaveGenerator(_seed.GetHashCode(), 8); var overhang = new SimplexOctaveGenerator(_seed.GetHashCode(), 8); overhang.SetScale(1 / 64.0); bottom.SetScale(1 / 128.0); double overhangsMagnitude = 16; double bottomsMagnitude = 32; for (int x = 0; x < 16; x++) { for (int z = 0; z < 16; z++) { float ox = x + chunk.X * 16; float oz = z + chunk.Z * 16; int bottomHeight = (int)((bottom.Noise(ox, oz, 0.5, 0.5) * bottomsMagnitude) + 64.0); int maxHeight = (int)((overhang.Noise(ox, oz, 0.5, 0.5) * overhangsMagnitude) + bottomHeight + 32.0); double threshold = 0.0; maxHeight = Math.Max(1, maxHeight); for (int y = 0; y < maxHeight && y < 255; y++) { if (y <= 1) { chunk.SetBlock(x, y, z, new Bedrock()); continue; } if (y > bottomHeight) { //part where we do the overhangs double density = overhang.Noise(ox, y, oz, 0.5, 0.5); if (density > threshold) { chunk.SetBlock(x, y, z, new Stone()); } } else { chunk.SetBlock(x, y, z, new Stone()); } } //turn the tops into grass chunk.SetBlock(x, bottomHeight, z, new Grass()); //the top of the base hills chunk.SetBlock(x, bottomHeight - 1, z, new Dirt()); chunk.SetBlock(x, bottomHeight - 2, z, new Dirt()); for (int y = bottomHeight + 1; y > bottomHeight && y < maxHeight && y < 255; y++) { //the overhang int thisblock = chunk.GetBlockId(x, y, z); int blockabove = chunk.GetBlockId(x, y + 1, z); if (thisblock != (decimal)Material.Air && blockabove == (decimal)Material.Air) { if (chunk.GetBlockId(x, y, z) == (byte)Material.Dirt || chunk.GetBlockId(x, y, z) == (byte)Material.Air || chunk.GetBlockId(x, y, z) == (byte)Material.Stone) { chunk.SetBlock(x, y, z, new Grass()); } if (chunk.GetBlockId(x, y - 1, z) != (decimal)Material.Air) { chunk.SetBlock(x, y - 1, z, new Dirt()); } if (chunk.GetBlockId(x, y - 2, z) != (decimal)Material.Air) { chunk.SetBlock(x, y - 2, z, new Dirt()); } } } for (int y = 0; y < WaterLevel; y++) { //Lake generation if (y < WaterLevel) { if (chunk.GetBlockId(x, y, z) == (decimal)Material.Grass || chunk.GetBlockId(x, y, z) == (decimal)Material.Dirt) //Grass or Dirt? { if (GetRandomNumber(1, 40) == 1 && y < WaterLevel - 4) { chunk.SetBlock(x, y, z, new Clay()); //Clay } else { chunk.SetBlock(x, y, z, new Sand()); //Sand } } if (chunk.GetBlockId(x, y + 1, z) == (decimal)Material.Air) { if (y < WaterLevel - 3) { chunk.SetBlock(x, y + 1, z, new FlowingWater()); //FlowingWater } } } } for (int y = 0; y < 255; y++) { int thisblock = chunk.GetBlockId(x, y, z); int blockabove = chunk.GetBlockId(x, y + 1, z); if (thisblock == (decimal)Material.Grass && blockabove == (decimal)Material.Air && y > WaterLevel) { //Grass if (GetRandomNumber(0, 5) == 1) { chunk.SetBlock(x, y + 1, z, new Tallgrass { TallGrassType = "tall" }); } //Flowers if (GetRandomNumber(0, 65) == 1) { int meta = GetRandomNumber(0, 8); //chunk.SetBlock(x, y + 1, z, 38, (byte) meta); chunk.SetBlock(x, y + 1, z, new RedFlower()); } //Trees for (int pos = 0; pos < trees; pos++) { if (treeBasePositions[pos, 0] < 14 && treeBasePositions[pos, 0] > 4 && treeBasePositions[pos, 1] < 14 && treeBasePositions[pos, 1] > 4) { if (chunk.GetBlockId(treeBasePositions[pos, 0], y + 1, treeBasePositions[pos, 1]) == 2) { if (y >= bottomHeight) { GenerateTree(chunk, treeBasePositions[pos, 0], y + 1, treeBasePositions[pos, 1], WoodType.Oak); } } } } } } } } }
private void PopulateChunk(ChunkColumn chunk) { int trees = new Random().Next(0, 10); int[,] treeBasePositions = new int[trees, 2]; for (int t = 0; t < trees; t++) { int x = new Random().Next(1, 16); int z = new Random().Next(1, 16); treeBasePositions[t, 0] = x; treeBasePositions[t, 1] = z; } for (int x = 0; x < 16; x++) { for (int z = 0; z < 16; z++) { int stoneHeight = (int)Math.Floor(stoneBaseHeight); stoneHeight += GetNoise(chunk.X * 16 + x, chunk.Z * 16 + z, stoneMountainFrequency, (int)Math.Floor(stoneMountainHeight)); if (stoneHeight < stoneMinHeight) { stoneHeight = (int)Math.Floor(stoneMinHeight); } stoneHeight += GetNoise(chunk.X * 16 + x, chunk.Z * 16 + z, stoneBaseNoise, (int)Math.Floor(stoneBaseNoiseHeight)); int dirtHeight = stoneHeight + (int)Math.Floor(dirtBaseHeight); dirtHeight += GetNoise(chunk.X * 16 + x, chunk.Z * 16 + z, dirtNoise, (int)Math.Floor(dirtNoiseHeight)); for (int y = 0; y < 256; y++) { //float y2 = Get3DNoise(chunk.X*16, y, chunk.Z*16, stoneBaseNoise, (int) Math.Floor(stoneBaseNoiseHeight)); if (y <= stoneHeight) { chunk.SetBlock(x, y, z, new Stone()); //Diamond ore if (GetRandomNumber(0, 2500) < 5) { chunk.SetBlock(x, y, z, new DiamondOre()); } //Coal Ore if (GetRandomNumber(0, 1500) < 50) { chunk.SetBlock(x, y, z, new CoalOre()); } //Iron Ore if (GetRandomNumber(0, 2500) < 30) { chunk.SetBlock(x, y, z, new IronOre()); } //Gold Ore if (GetRandomNumber(0, 2500) < 20) { chunk.SetBlock(x, y, z, new GoldOre()); } } if (y < waterLevel) //FlowingWater :) { if (chunk.GetBlockId(x, y, z) == 2 || chunk.GetBlockId(x, y, z) == 3) //Grass or Dirt? { if (GetRandomNumber(1, 40) == 5 && y < waterLevel - 4) { chunk.SetBlock(x, y, z, new Clay()); //Clay } else { chunk.SetBlock(x, y, z, new Sand()); //Sand } } if (y < waterLevel - 3) { chunk.SetBlock(x, y + 1, z, new FlowingWater()); //FlowingWater } } if (y <= dirtHeight && y >= stoneHeight) { chunk.SetBlock(x, y, z, new Dirt()); //Dirt chunk.SetBlock(x, y + 1, z, new Grass()); //Grass Block if (y > waterLevel) { //Grass if (GetRandomNumber(0, 5) == 2) { chunk.SetBlock(x, y + 2, z, new Tallgrass() { TallGrassType = "tall" }); } //flower if (GetRandomNumber(0, 65) == 8) { int meta = GetRandomNumber(0, 8); //chunk.SetBlock(x, y + 2, z, 38, (byte) meta); chunk.SetBlock(x, y + 2, z, new RedFlower()); } for (int pos = 0; pos < trees; pos++) { if (treeBasePositions[pos, 0] < 14 && treeBasePositions[pos, 0] > 4 && treeBasePositions[pos, 1] < 14 && treeBasePositions[pos, 1] > 4) { if (y < waterLevel + 2) { break; } if (chunk.GetBlockId(treeBasePositions[pos, 0], y + 1, treeBasePositions[pos, 1]) == 2) { if (y == dirtHeight) { GenerateTree(chunk, treeBasePositions[pos, 0], y + 1, treeBasePositions[pos, 1]); } } } } } } if (y == 0) { chunk.SetBlock(x, y, z, new Bedrock()); } } } } }