public void TryLoadHeightMap(WorldEdit worldEdit, string filename) { string folderPath = worldEdit.sapi.GetOrCreateDataPath("Heightmaps"); string filePath = Path.Combine(folderPath, filename); if (!File.Exists(filePath)) { worldEdit.Bad("No such file found."); return; } Bitmap bmp = null; try { bmp = new Bitmap(filePath); } catch (Exception e) { worldEdit.Bad("Unable to load {0}: {1}", filePath, e); return; } heights = new int[bmp.Width, bmp.Height]; for (int x = 0; x < bmp.Width; x++) { for (int y = 0; y < bmp.Height; y++) { heights[x, y] = bmp.GetPixel(x, y).R; } } worldEdit.Good("Ok, loaded {0}x{1} image", bmp.Width, bmp.Height); bmp.Dispose(); }
public override bool OnWorldEditCommand(WorldEdit worldEdit, CmdArgs args) { switch (args[0]) { case "ims": if (args.Length <= 1) { worldEdit.Bad("Please specify a filename"); return(true); } TryLoadHeightMap(worldEdit, args[1]); return(true); } return(false); }