/// <summary>Writes the nbt's content to the <see cref="Stream"/></summary> /// <param name="tag">The tag to write to the <see cref="Stream"/></param> /// <param name="Context">The context to write to</param> public void WriteContent(NBTTagList tag, SerializationContext Context) { NBTTagType SubTagType = tag.SubType; ITagWriter Writer = NBTWriter.GetWriter(SubTagType); if (Writer == null) { throw new Exception($"Cannot find writer for {SubTagType}"); } Int32 Count = tag.Count; if (SubTagType == NBTTagType.List) { /*SubTag = new NBTTagList(SubTagType); * SubTag.SetInformation(NBTTagInformation.ListSubtype, (NBTTagType)Context.Stream.ReadByte()); * SubTag.SetInformation(NBTTagInformation.ListSize, Context.ReadInt32()); * Reader.ReadContent(SubTag, Context); * tag[I] = SubTag;*/ Context.Stream.WriteByte((Byte)tag.GetInformation(NBTTagInformation.ListSubtype)); Context.WriteInt32((Int32)tag.GetInformation(NBTTagInformation.ListSize)); } else { for (Int32 I = 0; I < Count; I++) { Writer.WriteContent(tag[I], Context); } } }
/// <summary>Writes the nbt's content to the <see cref="Stream"/></summary> /// <param name="tag">The tag to write to the <see cref="Stream"/></param> /// <param name="Context">The context to write to</param> public void WriteContent(ITag tag, SerializationContext Context) { Object O = tag.GetInformation(NBTTagInformation.ListSubtype); if (O == null) { throw new Exception("Cannot read list sub type"); } var SubTagType = (NBTTagType)O; ITagWriter Writer = NBTWriter.GetWriter(SubTagType); if (Writer == null) { throw new Exception($"Cannot find writer for {SubTagType}"); } Int32 Count = tag.Count; if (SubTagType == NBTTagType.List) { for (Int32 I = 0; I < Count; I++) { ITag Item = tag[I]; Context.Stream.WriteByte((Byte)Item.GetInformation(NBTTagInformation.ListSubtype)); Context.WriteInt32((Int32)Item.GetInformation(NBTTagInformation.ListSize)); Writer.WriteContent(Item, Context); } } else { for (Int32 I = 0; I < Count; I++) { Writer.WriteContent(tag[I], Context); } } }