internal static List <TagCompound> SaveChests() { var list = new List <TagCompound>(); for (int k = 0; k < 1000; k++) { var chest = Main.chest[k]; if (chest == null) { continue; } var itemTagList = PlayerIO.SaveInventory(chest.item); if (itemTagList == null) //doesn't need mod saving { continue; } list.Add(new TagCompound { ["items"] = itemTagList, ["x"] = chest.x, ["y"] = chest.y }); } return(list); }
internal static List <TagCompound> SaveChestInventory() { var list = new List <TagCompound>(); const short MaxChestSaveCount = 8000; //As of Vanilla 1.4.0.1 for (int k = 0; k < MaxChestSaveCount; k++) { var chest = Main.chest[k]; if (chest == null) // chest doesn't exist { continue; } var itemTagListModded = PlayerIO.SaveInventory(chest.item); // list of mod only items in inventory if (itemTagListModded == null) // Doesn't need additional saving beyond vanilla { continue; } TagCompound tag = new TagCompound { ["items"] = itemTagListModded, ["x"] = chest.x, ["y"] = chest.y, }; list.Add(tag); } return(list); }
internal static void LoadChestInventory(IList <TagCompound> list) { foreach (var tag in list) { int cID = Chest.FindChest(tag.GetInt("x"), tag.GetInt("y")); if (cID >= 0) { var chest = Main.chest[cID]; PlayerIO.LoadInventory(chest.item, tag.GetList <TagCompound>("items")); } } }
internal static void LoadChests(IList <TagCompound> list) { foreach (var tag in list) { int x = tag.GetInt("x"); int y = tag.GetInt("y"); int chest = Chest.FindChest(x, y); if (chest < 0) { chest = Chest.CreateChest(x, y); } if (chest >= 0) { PlayerIO.LoadInventory(Main.chest[chest].item, tag.GetList <TagCompound>("items")); } } }
internal static void ReadChest(BinaryReader reader) { int x = reader.ReadInt32(); int y = reader.ReadInt32(); int chest = Chest.FindChest(x, y); if (chest < 0) { chest = Chest.CreateChest(x, y); } if (chest >= 0) { PlayerIO.ReadInventory(Main.chest[chest].item, reader, true); } else { PlayerIO.ReadInventory(new Item[40], reader, true); } }
internal static bool WriteChest(Chest chest, BinaryWriter writer) { bool flag; byte[] data; using (MemoryStream stream = new MemoryStream()) { using (BinaryWriter invWriter = new BinaryWriter(stream)) { flag = PlayerIO.WriteInventory(chest.item, invWriter, true); invWriter.Flush(); data = stream.ToArray(); } } if (flag) { writer.Write(chest.x); writer.Write(chest.y); writer.Write(data); } return(flag); }