public Bitmap GetSurfaceMap(int xMin, int zMin, short[,] heightmap, bool shading) { int xMax = xMin + heightmap.GetLength(0); int zMax = zMin + heightmap.GetLength(1); Bitmap bmp = new Bitmap(heightmap.GetLength(0), heightmap.GetLength(1), System.Drawing.Imaging.PixelFormat.Format32bppArgb); for (int z = zMin; z < zMax; z++) { for (int x = xMin; x < xMax; x++) { int y = heightmap[x - xMin, z - zMin]; if (y < 0) { continue; } var block = GetBlock(x, y, z); int shade = 0; if (shading && z - 1 >= zMin) { if (block.IsWater) { //Water dithering var depth = GetWaterDepth(x, y, z); if (depth < 8) { shade = 1; } else if (depth < 16) { shade = 0; } else { shade = -1; } if (depth % 8 >= 4 && shade > -1) { if (x % 2 == z % 2) { shade--; } } } else { var above = heightmap[x - xMin, z - 1 - zMin]; if (above > y) { shade = -1; } else if (above < y) { shade = 1; } } } var aboveBlock = GetBlock(x, y + 1, z); if (aboveBlock != null && aboveBlock.ID == "minecraft:snow") { block = aboveBlock; } bmp.SetPixel(x - xMin, z - zMin, Blocks.GetMapColor(block, shade)); } } return(bmp); }
public static Bitmap GetSurfaceMap(string filepath, HeightmapType surfaceType, bool mcMapShading) { Region r = LoadRegion(filepath); var hm = r.GetHeightmapFromNBT(surfaceType); for (int z = 0; z < 512; z++) { for (int x = 0; x < 512; x++) { short y = hm[x, z]; while (!Blocks.IsBlockForMap(r.GetBlock(x, y, z), surfaceType) && y > 0) { y--; } hm[x, z] = y; } } Bitmap bmp = new Bitmap(512, 512, System.Drawing.Imaging.PixelFormat.Format24bppRgb); for (int z = 0; z < 512; z++) { for (int x = 0; x < 512; x++) { int y = hm[x, z]; var block = r.GetBlock(x, y, z); if (block.IsAir && y > 0) { throw new ArgumentException("the mapped block was air."); } int shade = 0; if (mcMapShading && z > 0) { if (block.IsWater) { //Water dithering var depth = r.GetWaterDepth(x, y, z); if (depth < 8) { shade = 1; } else if (depth < 16) { shade = 0; } else { shade = -1; } if (depth % 8 >= 4 && shade > -1) { if (x % 2 == z % 2) { shade--; } } } else { int above = hm[x, z - 1]; if (above > y) { shade = -1; } else if (above < y) { shade = 1; } } } bmp.SetPixel(x, z, Blocks.GetMapColor(block, shade)); } } return(bmp); }