Esempio n. 1
0
        public void Test1()
        {
            var nbtFile = new NbtFile();

            nbtFile.RootTag.Add(new NbtInt(1, "23333"));
            nbtFile.RootTag.Add(new NbtCompound("test"));
            var testCompound = nbtFile.RootTag["test"] as NbtCompound;

            Assert.NotNull(testCompound);
            var testList = new NbtList(NbtTagType.Int, "testList");

            testCompound.Add(testList);
            testList.Add(new NbtInt(2));
            testList.Add(new NbtInt(4));
            testCompound.Add(new NbtLong(0x000000FFFFFFFFFF, "testLong"));

            using (var sw = new StringWriter())
            {
                nbtFile.RootTag.Accept(new OutputVisitor(sw));
                var str = sw.ToString();
                Console.WriteLine(str);
            }

            var stream = new FileStream("test.bin", FileMode.OpenOrCreate, FileAccess.ReadWrite);

            stream.SetLength(0);
            nbtFile.WriteTo(stream);

            stream.Seek(0, SeekOrigin.Begin);
            var nbtFile2 = new NbtFile(stream);

            using (var sw = new StringWriter())
            {
                nbtFile2.RootTag.Accept(new OutputVisitor(sw));
                Console.WriteLine(sw.ToString());
            }
        }