Exemple #1
0
        /// <summary>
        /// Validates an NBT tree against the chunk's NBT schema definition.
        /// </summary>
        /// <param name="tree">The root node of the NBT tree to verify.</param>
        /// <returns>Status indicating if the tree represents a valid chunk.</returns>
        public bool ValidateTree(TagNode tree)
        {
            NbtVerifier v = new NbtVerifier(tree, LevelSchema);

            return(v.Verify());
        }
Exemple #2
0
        /// <summary>
        /// Imports a schematic file at the given path and returns in as a <see cref="Schematic"/> object.
        /// </summary>
        /// <param name="path">The path to the schematic file.</param>
        /// <returns>A <see cref="Schematic"/> object containing the decoded schematic file data.</returns>
        public static Schematic Import(string path)
        {
            NBTFile schematicFile = new NBTFile(path);

            if (!schematicFile.Exists())
            {
                return(null);
            }
            NbtTree tree;

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

                tree = new NbtTree(nbtStream);
            }

            NbtVerifier v = new NbtVerifier(tree.Root, _schema);

            if (!v.Verify())
            {
                return(null);
            }

            //TagNodeCompound schematic = tree.Root["Schematic"] as TagNodeCompound;
            TagNodeCompound schematic = tree.Root;
            int             xdim      = schematic["Width"].ToTagShort();
            int             zdim      = schematic["Length"].ToTagShort();
            int             ydim      = schematic["Height"].ToTagShort();

            Schematic self = new Schematic(xdim, ydim, zdim);

            // Damnit, schematic is YZX ordering.
            YZXByteArray schemaBlocks = new YZXByteArray(xdim, ydim, zdim, schematic["Blocks"].ToTagByteArray());
            YZXByteArray schemaData   = new YZXByteArray(xdim, ydim, zdim, schematic["Data"].ToTagByteArray());

            for (int x = 0; x < xdim; x++)
            {
                for (int y = 0; y < ydim; y++)
                {
                    for (int z = 0; z < zdim; z++)
                    {
                        self._blocks[x, y, z] = schemaBlocks[x, y, z];
                        self._data[x, y, z]   = schemaData[x, y, z];
                    }
                }
            }

            TagNodeList entities = schematic["Entities"] as TagNodeList;

            foreach (TagNode e in entities)
            {
                self._entities.Add(e);
            }

            TagNodeList tileEntities = schematic["TileEntities"] as TagNodeList;

            foreach (TagNode te in tileEntities)
            {
                self._tileEntities.Add(te);
            }

            self._blockset.Refresh();

            return(self);
        }