Esempio n. 1
0
        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);
        }
Esempio n. 2
0
        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);
        }
Esempio n. 3
0
        public void ToStructure(string file)
        {
            var loadtag   = NBTFile.LoadFromFile(file);
            var schematic = SilverNBTLibrary.Structure.Schematic.LoadFromNBT(loadtag);
            var structure = new SilverNBTLibrary.Structure.StructureTemplate(schematic.Width, schematic.Height, schematic.Length);

            structure.Author = "Haru";

            form.Invoke((MethodInvoker) delegate()
            {
                pgb.Maximum = schematic.Width * schematic.Height * schematic.Length;
                pgb.Value   = 0;
            });
            for (int x = 0; x < schematic.Width; x++)
            {
                for (int y = 0; y < schematic.Height; y++)
                {
                    for (int z = 0; z < schematic.Length; z++)
                    {
                        var id   = schematic.GetBlockId(x, y, z);
                        var meta = schematic.GetBlockMetadata(x, y, z);
                        structure.SetBlock(x, y, z, id, meta);
                        bw.ReportProgress(0);
                    }
                }
            }

            foreach (NBTTagCompound te in schematic.TileEntities)
            {
                structure.AddTileEntityTag(te.GetTagInt("x").Value, te.GetTagInt("y").Value, te.GetTagInt("z").Value, te);
            }
            foreach (NBTTagCompound entity in schematic.Entities)
            {
                structure.Entities.Add(entity);
            }
            var nbt = structure.SaveToNBT();

            NBTFile.SaveToFile(Path.GetDirectoryName(file) + @"\" + Path.GetFileNameWithoutExtension(file) + ".nbt", nbt);
        }