public NBTTagCompound ImageConvert(Bitmap bmp, bool IsSchematic, ref BackgroundWorker bw) { var schema = new SilverNBTLibrary.Structure.Schematic(bmp.Width, 1, bmp.Height); var mapbyte = new byte[16384]; var compound = new NBTTagCompound(); int i = 0; using (BitmapAccessor accessor = new BitmapAccessor(bmp)) { for (int y = 0; y < bmp.Height; y++) { for (int x = 0; x < bmp.Width; x++) { Color bitmapRGB = accessor.GetPixel(x, y); var block = IsSchematic ? RGBToBlockColor(bitmapRGB) : RGBToMapColor(bitmapRGB); if (IsSchematic) { schema.SetBlock(x, 0, y, block.ID, block.Meta); } else { mapbyte[i] = (byte)block.ID; i++; } } bw.ReportProgress(y); } } if (IsSchematic) { compound = schema.SaveToNBT(); } else { var map = new NBTTagByteArray("colors", mapbyte); compound = NBTFile.LoadFromFile(System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + @"\data\MapTemplate.dat"); var data = (NBTTagCompound)compound.GetTag("data"); data.Add(map); } bmp.Dispose(); return(compound); }
public void ToSchematic(string file) { var loadtag = NBTFile.LoadFromFile(file); var structure = SilverNBTLibrary.Structure.StructureTemplate.LoadFromNBT(loadtag); var schema = new SilverNBTLibrary.Structure.Schematic(structure.Width, structure.Height, structure.Length); form.Invoke((MethodInvoker) delegate() { pgb.Maximum = structure.Width * structure.Height * structure.Length; pgb.Value = 0; }); for (int x = 0; x < structure.Width; x++) { for (int y = 0; y < structure.Height; y++) { for (int z = 0; z < structure.Length; z++) { var id = structure.GetBlockId(x, y, z); var meta = structure.GetBlockMetadata(x, y, z); schema.SetBlock(x, y, z, id, meta); var te = structure.GetTileEntityTag(x, y, z); if (te != null) { schema.AddTileEntityTag(x, y, z, te); } form.Invoke((MethodInvoker) delegate() { pgb.Value++; }); } } } foreach (NBTTagCompound entity in structure.Entities) { schema.Entities.Add(entity); } var nbt = schema.SaveToNBT(); NBTFile.SaveToFile(Path.GetDirectoryName(file) + @"\" + Path.GetFileNameWithoutExtension(file) + ".schematic", nbt); }