Esempio n. 1
0
        public void TestNbtListType()
        {
            var file = new NbtFile();

            file.RootTag = new NbtCompound("ListTypeTest");

            NbtTagType mytype = NbtTagType.TAG_Compound;

            NbtList list = new NbtList("Entities", null, mytype);

            file.RootTag.Tags.Add(list);

            file.SaveFile("TestFiles/NbtListType.nbt");


            NbtFile read = new NbtFile();

            read.LoadFile("TestFiles/NbtListType.nbt");
            Assert.NotNull(read);
            Console.WriteLine(read.RootTag.ToString());

            NbtList readlist = (NbtList)read.RootTag.Tags.ToArray()[0];

            Assert.NotNull(readlist);

            Assert.AreEqual(mytype, readlist.ListType);
        }
Esempio n. 2
0
 public void SaveToFile(string file)
 {
     using (NbtFile rdr = new NbtFile())
     {
         rdr.RootTag = new NbtCompound("Region");
         NbtCompound cMats = new NbtCompound("VoxMaterials");
         rdr.RootTag.Tags.Add(mMaterials.ToNBT());
         rdr.RootTag.Tags.Add(new NbtByteArray("Voxels", ToBytes()));
         rdr.SaveFile(file);
     }
 }
Esempio n. 3
0
 private object NBT2Bytes(NbtCompound nbtCompound)
 {
     using (MemoryStream ms = new MemoryStream())
     {
         NbtFile f = new NbtFile();
         f.RootTag = nbtCompound;
         f.SaveFile(ms, false);
         //ms.Position = 0;
         //byte[] buffer = new byte[ms.Length];
         //ms.Read(buffer, 0, buffer.Length);
         return(ms.ToArray());
     }
 }
Esempio n. 4
0
        public static void Save()
        {
            File.WriteAllLines(".luf", LastUsedFiles.ToArray());


            NbtFile f = new NbtFile();

            f.RootTag.Add("GridLines", new NbtByte("GridLines", (byte)(ShowGridLines ? 0x01 : 0x00)));
            f.RootTag.Add("ShowChunks", new NbtByte("ShowChunks", (byte)(ShowChunks ? 0x01 : 0x00)));
            f.RootTag.Add("ShowMapIcons", new NbtByte("ShowMapIcons", (byte)(ShowMapIcons ? 0x01 : 0x00)));
            f.RootTag.Add("ShowWaterDepth", new NbtByte("ShowWaterDepth", (byte)(ShowWaterDepth ? 0x01 : 0x00)));
            f.SaveFile(".settings");
            f.Dispose();
        }
        public void TestNbtSmallFileSavingUncompressed()
        {
            var file = new NbtFile
            {
                RootTag = new NbtCompound("hello world", new NbtTag[]
                {
                    new NbtString("name", "Bananrama")
                })
            };

            file.SaveFile("TestTemp/test.nbt", false);

            FileAssert.AreEqual("TestFiles/test.nbt", "TestTemp/test.nbt");
        }
Esempio n. 6
0
        public void TestNbtSmallFileSavingUncompressed()
        {
            var file = new NbtFile
                           {
                               RootTag = new NbtCompound("hello world", new NbtTag[]
                                                                            {
                                                                                new NbtString("name", "Bananrama")
                                                                            })
                           };

            file.SaveFile("TestTemp/test.nbt", false);

            FileAssert.AreEqual("TestFiles/test.nbt", "TestTemp/test.nbt");
        }
        public void TestNbtSmallFileSavingUncompressedStream()
        {
            var file = new NbtFile
            {
                RootTag = new NbtCompound("hello world", new NbtTag[]
                {
                    new NbtString("name", "Bananrama")
                })
            };

            var nbtStream = new MemoryStream();

            file.SaveFile(nbtStream, false);

            FileStream testFileStream = File.OpenRead("TestFiles/test.nbt");

            FileAssert.AreEqual(testFileStream, nbtStream);
        }
Esempio n. 8
0
        public byte[] GetChunk(int x, int y)
        {
            NbtFile     file = new NbtFile();
            NbtCompound c    = new NbtCompound("__ROOT__");

            c.Tags.Add(new NbtInt("x", x));
            c.Tags.Add(new NbtInt("y", y));
            c.Tags.Add(new NbtInt("z", 0));
            c.Tags.Add(new NbtByteArray("c", GetChunkData(x, y)));
            file.RootTag = c;
            byte[] endresult;
            using (MemoryStream ms = new MemoryStream())
            {
                file.SaveFile(ms, true);
                endresult = ms.ToArray();
            }
            return(endresult);
        }
Esempio n. 9
0
        public void TestNbtListType()
        {
            var file = new NbtFile();
            file.RootTag = new NbtCompound("ListTypeTest");

            NbtTagType mytype = NbtTagType.TAG_Compound;

            NbtList list = new NbtList("Entities", null, mytype);
            file.RootTag.Tags.Add(list);

            file.SaveFile("TestFiles/NbtListType.nbt");

            NbtFile read = new NbtFile();
            read.LoadFile("TestFiles/NbtListType.nbt");
            Assert.NotNull(read);
            Console.WriteLine(read.RootTag.ToString());

            NbtList readlist = (NbtList)read.RootTag.Tags.ToArray()[0];
            Assert.NotNull(readlist);

            Assert.AreEqual(mytype, readlist.ListType);
        }
Esempio n. 10
0
        public override void Save(string Folder)
        {
            string  f  = Path.Combine(Folder, "DefaultMapGenerator.dat");
            NbtFile nf = new NbtFile(f);

            nf.RootTag = new NbtCompound("__ROOT__");
            NbtCompound c = new NbtCompound("DefaultMapGenerator");

            c.Add(new NbtByte("GenerateCaves", (byte)(GenerateCaves ? 1 : 0)));
            c.Add(new NbtByte("GenerateDungeons", (byte)(GenerateDungeons ? 1 : 0)));
            c.Add(new NbtByte("GenerateOres", (byte)(GenerateOres ? 1 : 0)));
            c.Add(new NbtByte("GenerateWater", (byte)(GenerateWater ? 1 : 0)));
            c.Add(new NbtByte("HellMode", (byte)(HellMode ? 1 : 0)));
            c.Add(new NbtByte("GenerateTrees", (byte)(GenerateTrees ? 1 : 0)));
            c.Add(new NbtDouble("Frequency", Frequency));
            c.Add(new NbtByte("NoiseQuality", (byte)NoiseQuality));
            c.Add(new NbtInt("OctaveCount", OctaveCount));
            c.Add(new NbtDouble("Lacunarity", Lacunarity));
            c.Add(new NbtDouble("Persistance", Persistance));
            c.Add(new NbtDouble("ContinentNoiseFrequency", ContinentNoiseFrequency));
            c.Add(new NbtDouble("CaveThreshold", CaveThreshold));
            nf.RootTag.Add(c);
            nf.SaveFile(f);
        }
Esempio n. 11
0
        public void TestNbtSmallFileSavingUncompressedStream()
        {
            var file = new NbtFile
                           {
                               RootTag = new NbtCompound("hello world", new NbtTag[]
                                                                            {
                                                                                new NbtString("name", "Bananrama")
                                                                            })
                           };

            var nbtStream = new MemoryStream();
            file.SaveFile(nbtStream, false);

            FileStream testFileStream = File.OpenRead("TestFiles/test.nbt");

            FileAssert.AreEqual(testFileStream, nbtStream);
        }