Example #1
0
 public static void Write(TagCompound root, BinaryWriter writer) => WriteTag("", root, writer);
Example #2
0
        //in Terraria.GameContent.Tile_Entities.TEItemFrame.WriteExtraData
        //  if item is a mod item write 0 as the ID
        internal static TagCompound SaveContainers()
        {
            var ms     = new MemoryStream();
            var writer = new BinaryWriter(ms);

            byte[]                 flags      = new byte[1];
            byte                   numFlags   = 0;
            ISet <int>             headSlots  = new HashSet <int>();
            ISet <int>             bodySlots  = new HashSet <int>();
            ISet <int>             legSlots   = new HashSet <int>();
            IDictionary <int, int> itemFrames = new Dictionary <int, int>();

            for (int i = 0; i < Main.maxTilesX; i++)
            {
                for (int j = 0; j < Main.maxTilesY; j++)
                {
                    Tile tile = Main.tile[i, j];
                    if (tile.active() && (tile.type == TileID.Mannequin || tile.type == TileID.Womannequin))
                    {
                        int slot     = tile.frameX / 100;
                        int position = tile.frameY / 18;
                        if (HasModArmor(slot, position))
                        {
                            if (position == 0)
                            {
                                headSlots.Add(slot);
                            }
                            else if (position == 1)
                            {
                                bodySlots.Add(slot);
                            }
                            else if (position == 2)
                            {
                                legSlots.Add(slot);
                            }
                            flags[0] |= 1;
                            numFlags  = 1;
                        }
                    }
                }
            }
            int tileEntity = 0;

            foreach (KeyValuePair <int, TileEntity> entity in TileEntity.ByID)
            {
                TEItemFrame itemFrame = entity.Value as TEItemFrame;
                if (itemFrame != null && ItemLoader.NeedsModSaving(itemFrame.item))
                {
                    itemFrames.Add(itemFrame.ID, tileEntity);
                    //flags[0] |= 2; legacy
                    numFlags = 1;
                }
                if (!(entity.Value is ModTileEntity))
                {
                    tileEntity++;
                }
            }
            if (numFlags == 0)
            {
                return(null);
            }
            writer.Write(numFlags);
            writer.Write(flags, 0, numFlags);
            if ((flags[0] & 1) == 1)
            {
                writer.Write((ushort)headSlots.Count);
                foreach (int slot in headSlots)
                {
                    writer.Write((ushort)slot);
                    ModItem item = ItemLoader.GetItem(EquipLoader.slotToId[EquipType.Head][slot]);
                    writer.Write(item.mod.Name);
                    writer.Write(item.Name);
                }
                writer.Write((ushort)bodySlots.Count);
                foreach (int slot in bodySlots)
                {
                    writer.Write((ushort)slot);
                    ModItem item = ItemLoader.GetItem(EquipLoader.slotToId[EquipType.Body][slot]);
                    writer.Write(item.mod.Name);
                    writer.Write(item.Name);
                }
                writer.Write((ushort)legSlots.Count);
                foreach (int slot in legSlots)
                {
                    writer.Write((ushort)slot);
                    ModItem item = ItemLoader.GetItem(EquipLoader.slotToId[EquipType.Legs][slot]);
                    writer.Write(item.mod.Name);
                    writer.Write(item.Name);
                }
                WriteContainerData(writer);
            }
            var tag = new TagCompound();

            tag.Set("data", ms.ToArray());

            if (itemFrames.Count > 0)
            {
                tag.Set("itemFrames", itemFrames.Select(entry =>
                                                        new TagCompound {
                    ["id"]   = entry.Value,
                    ["item"] = ItemIO.Save(((TEItemFrame)TileEntity.ByID[entry.Key]).item)
                }
                                                        ).ToList());
            }
            return(tag);
        }
Example #3
0
 public WallEntry(TagCompound tag) : base(tag)
 {
 }