Ejemplo n.º 1
0
        public void TestWriteRead()
        {
            var stream = new MemoryStream();
            var writer = new PrimitiveWriter(stream);
            var blob   = new NbtBlob("Hey",
                                     new Tag.Compound
            {
                ["abc"] = new Tag.Int(10),
                ["bcd"] = new Tag.List
                {
                    new Tag.Compound
                    {
                        ["hey"] = new Tag.ByteArray(new byte[] { 1, 2, 3, 4 })
                    }
                }
            });

            writer.WriteNbtBlob(blob);
            stream.Seek(0, SeekOrigin.Begin);
            _output.WriteLine(blob.Root.ToString());
            var blob2 = new PrimitiveReader(stream).ReadNbtBlob();

            _output.WriteLine(blob2.Root.ToString());
            Assert.Equal(10, blob2.Root.Get <Tag.Int>("abc").Value);
            Assert.Equal(3, blob2.Root.Get <Tag.List>("bcd").Get <Tag.Compound>(0).Get <Tag.ByteArray>("hey")[2]);
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Writes a Gzip Compressed NbtBlob to stream.
 /// </summary>
 /// <exception cref="NBTException">Invalid Nbt</exception>
 public static void WriteCompressedNbtBlob(this Stream stream, NbtBlob blob)
 {
     using (var compress = new GZipStream(stream, CompressionMode.Compress, true))
     {
         var writer = new PrimitiveWriter(compress);
         writer.WriteNbtBlob(blob);
     }
 }
Ejemplo n.º 3
0
 public static void WriteItemStackProto(this PrimitiveWriter writer, ItemStack itemStack)
 {
     if (itemStack.IsEmpty)
     {
         writer.WriteShort(-1);
         return;
     }
     writer.WriteShort(itemStack.Item.Id);
     writer.WriteByte(itemStack.Count);
     writer.WriteShort(itemStack.Damage);
     writer.WriteNbtBlob(itemStack.Nbt);
 }
Ejemplo n.º 4
0
 public override void Write(PrimitiveWriter writer)
 {
     writer.WriteBlockPosProto(Location);
     writer.WriteByte(Action);
     writer.WriteNbtBlob(NbtData);
 }