예제 #1
0
        static void Main(string[] args)
        {
            if (!File.Exists("level.dat")) {
                Console.WriteLine("Could not find level.dat");
                return;
            }

            NBTFile nf = new NBTFile("level.dat");
            NbtTree tree;

            using (Stream nbtstr = nf.GetDataInputStream()) {
                if (nbtstr == null) {
                    Console.WriteLine("Could not open level.dat");
                    return;
                }

                tree = new NbtTree(nbtstr);
            }

            TagNodeList list = tree.Root["FML"].ToTagCompound()["ItemData"].ToTagList();
            foreach (TagNodeCompound tag in list) {
                TagNodeString modid = tag["K"].ToTagString();
                if (modid.Data.Contains("modularpots:modularpots:")) {
                    modid.Data = modid.Data.Replace("modularpots:modularpots:", "modularpots:");
                    Console.WriteLine("Updating entry " + tag["V"].ToTagInt().Data + ": " + modid.Data);
                }
            }

            using (Stream zipstr = nf.GetDataOutputStream()) {
                if (zipstr == null) {
                    Console.WriteLine("Could not write back to level.dat");
                    return;
                }

                tree.WriteTo(zipstr);
            }

            Console.WriteLine("Update complete");
        }
예제 #2
0
 protected override void SaveCore()
 {
     NBTFile file = new NBTFile(_path);
     using (Stream str = file.GetDataOutputStream(_compressionType)) {
         _tree.WriteTo(str);
     }
 }
예제 #3
0
        /// <summary>
        /// Exports the <see cref="Schematic"/> object to a schematic file.
        /// </summary>
        /// <param name="path">The path to write out the schematic file to.</param>
        public void Export(string path)
        {
            int xdim = _blockset.XDim;
            int ydim = _blockset.YDim;
            int zdim = _blockset.ZDim;

            byte[] blockData = new byte[xdim * ydim * zdim];
            byte[] dataData = new byte[xdim * ydim * zdim];

            YZXByteArray schemaBlocks = new YZXByteArray(_blockset.XDim, _blockset.YDim, _blockset.ZDim, blockData);
            YZXByteArray schemaData = new YZXByteArray(_blockset.XDim, _blockset.YDim, _blockset.ZDim, dataData);

            TagNodeList entities = new TagNodeList(TagType.TAG_COMPOUND);
            TagNodeList tileEntities = new TagNodeList(TagType.TAG_COMPOUND);

            for (int x = 0; x < xdim; x++) {
                for (int z = 0; z < zdim; z++) {
                    for (int y = 0; y < ydim; y++) {
                        AlphaBlock block = _blockset.GetBlock(x, y, z);
                        schemaBlocks[x, y, z] = (byte)block.ID;
                        schemaData[x, y, z] = (byte)block.Data;

                        TileEntity te = block.GetTileEntity();
                        if (te != null) {
                            te.X = x;
                            te.Y = y;
                            te.Z = z;

                            tileEntities.Add(te.BuildTree());
                        }
                    }
                }
            }

            foreach (TypedEntity e in _entityset) {
                entities.Add(e.BuildTree());
            }

            TagNodeCompound schematic = new TagNodeCompound();
            schematic["Width"] = new TagNodeShort((short)xdim);
            schematic["Length"] = new TagNodeShort((short)zdim);
            schematic["Height"] = new TagNodeShort((short)ydim);

            schematic["Entities"] = entities;
            schematic["TileEntities"] = tileEntities;

            schematic["Materials"] = new TagNodeString("Alpha");

            schematic["Blocks"] = new TagNodeByteArray(blockData);
            schematic["Data"] = new TagNodeByteArray(dataData);

            NBTFile schematicFile = new NBTFile(path);

            Stream nbtStream = schematicFile.GetDataOutputStream();
            if (nbtStream == null) {
                return;
            }

            NbtTree tree = new NbtTree(schematic, "Schematic");
            tree.WriteTo(nbtStream);

            nbtStream.Close();
        }
예제 #4
0
        static void SaveNbtFileNode(TreeNode node)
        {
            NbtFileData data = node.Tag as NbtFileData;
            if (data == null || !data.Modified)
                return;

            NBTFile file = new NBTFile(data.Path);
            using (Stream str = file.GetDataOutputStream(data.CompressionType))
            {
                data.Tree.WriteTo(str);
            }
            data.Modified = false;
        }