private static int GetHigestSurrounding(int x, int z, ChunkColumn chunk, Level level) { int h = chunk.GetHeight(x, z); if (h == 255) { return(h); } if (x == 0 || x == 15 || z == 0 || z == 15) { var coords = new BlockCoordinates(x + (chunk.x * 16), h, z + (chunk.z * 16)); h = Math.Max(h, level.GetHeight(coords + BlockCoordinates.Up)); h = Math.Max(h, level.GetHeight(coords + BlockCoordinates.West)); h = Math.Max(h, level.GetHeight(coords + BlockCoordinates.East)); h = Math.Max(h, level.GetHeight(coords + BlockCoordinates.North)); h = Math.Max(h, level.GetHeight(coords + BlockCoordinates.South)); if (h > 255) { h = 255; } if (h < 0) { h = 0; } return(h); } //if (z < 15) h = Math.Max(h, chunk.GetHeight(x, z + 1)); //if (z > 0) h = Math.Max(h, chunk.GetHeight(x, z - 1)); //if (x < 15) h = Math.Max(h, chunk.GetHeight(x + 1, z)); //if (x < 15 && z > 0) h = Math.Max(h, chunk.GetHeight(x + 1, z - 1)); //if (x < 15 && z < 15) h = Math.Max(h, chunk.GetHeight(x + 1, z + 1)); //if (x > 0) h = Math.Max(h, chunk.GetHeight(x - 1, z)); //if (x > 0 && z > 0) h = Math.Max(h, chunk.GetHeight(x - 1, z - 1)); //if (x > 0 && z < 15) h = Math.Max(h, chunk.GetHeight(x - 1, z + 1)); h = Math.Max(h, chunk.GetHeight(x, z + 1)); h = Math.Max(h, chunk.GetHeight(x, z - 1)); h = Math.Max(h, chunk.GetHeight(x + 1, z)); h = Math.Max(h, chunk.GetHeight(x + 1, z - 1)); h = Math.Max(h, chunk.GetHeight(x + 1, z + 1)); h = Math.Max(h, chunk.GetHeight(x - 1, z)); h = Math.Max(h, chunk.GetHeight(x - 1, z - 1)); h = Math.Max(h, chunk.GetHeight(x - 1, z + 1)); return(h); }
private byte SetLightLevel(Level level, Queue <BlockCoordinates> lightBfsQueue, BlockCoordinates coordinates, byte lightLevel, bool down = false, bool up = false) { if (_trackResults) { MakeVisit(coordinates); } if (!down && !up && coordinates.Y >= level.GetHeight(coordinates)) { level.SetSkyLight(coordinates, 15); return(15); } bool isTransparent = level.IsTransparent(coordinates); byte skyLight = level.GetSkyLight(coordinates); if (down && isTransparent && lightLevel == 15) { if (skyLight != 15) { level.SetSkyLight(coordinates, 15); } /*if (!lightBfsQueue.Contains(coordinates)) */ lightBfsQueue.Enqueue(coordinates); return(15); } if (isTransparent && skyLight + 2 <= lightLevel) { byte newLevel = (byte)(lightLevel - 1); level.SetSkyLight(coordinates, newLevel); /*if (!lightBfsQueue.Contains(coordinates)) */ lightBfsQueue.Enqueue(coordinates); return(newLevel); } return(skyLight); }