public static void Load(Item item, TagCompound tag) { if (tag.Count == 0) { item.netDefaults(0); return; } string modName = tag.GetString("mod"); if (modName == "Terraria") { item.netDefaults(tag.GetInt("id")); if (tag.ContainsKey("legacyData")) { LoadLegacyModData(item, tag.GetByteArray("legacyData"), tag.GetBool("hasGlobalSaving")); } } else { int type = ModLoader.GetMod(modName)?.ItemType(tag.GetString("name")) ?? 0; if (type > 0) { item.netDefaults(type); if (tag.ContainsKey("legacyData")) { LoadLegacyModData(item, tag.GetByteArray("legacyData"), tag.GetBool("hasGlobalSaving")); } else { item.modItem.Load(tag.GetCompound("data")); } } else { item.netDefaults(ModLoader.GetMod("ModLoader").ItemType("MysteryItem")); ((MysteryItem)item.modItem).Setup(tag); } } item.Prefix(tag.GetByte("prefix")); item.stack = tag.Get <int?>("stack") ?? 1; item.favorited = tag.GetBool("fav"); if (!(item.modItem is MysteryItem)) { LoadGlobals(item, tag.GetList <TagCompound>("globalData")); } }
public static void Load(Item item, TagCompound tag) { string modName = tag.GetString("mod"); if (modName == "") { item.netDefaults(0); return; } if (modName == "Terraria") { item.netDefaults(tag.GetInt("id")); } else { int type = ModLoader.GetMod(modName)?.ItemType(tag.GetString("name")) ?? 0; if (type > 0) { item.netDefaults(type); item.modItem.Load(tag.GetCompound("data")); } else { item.netDefaults(ModContent.ItemType <MysteryItem>()); ((MysteryItem)item.modItem).Setup(tag); } } if (tag.ContainsKey("modPrefixMod") && tag.ContainsKey("modPrefixName")) { string prefixMod = tag.GetString("modPrefixMod"); string prefixName = tag.GetString("modPrefixName"); item.Prefix(ModLoader.GetMod(prefixMod)?.PrefixType(prefixName) ?? 0); } else if (tag.ContainsKey("prefix")) { item.Prefix(tag.GetByte("prefix")); } item.stack = tag.Get <int?>("stack") ?? 1; item.favorited = tag.GetBool("fav"); if (!(item.modItem is MysteryItem)) { LoadGlobals(item, tag.GetList <TagCompound>("globalData")); } }
internal static void LoadTiles(TagCompound tag) { if (!tag.ContainsKey("data")) { return; } var tables = TileTables.Create(); foreach (var tileTag in tag.GetList <TagCompound>("tileMap")) { ushort type = (ushort)tileTag.GetShort("value"); string modName = tileTag.GetString("mod"); string name = tileTag.GetString("name"); tables.tiles[type] = ModContent.TryFind(modName, name, out ModTile tile) ? tile.Type : (ushort)0; if (tables.tiles[type] == 0) { tables.tiles[type] = ModContent.Find <ModTile>("ModLoader/PendingUnloadedTile").Type; tables.tileModNames[type] = modName; tables.tileNames[type] = name; } tables.frameImportant[type] = tileTag.GetBool("framed"); } foreach (var wallTag in tag.GetList <TagCompound>("wallMap")) { ushort type = (ushort)wallTag.GetShort("value"); string modName = wallTag.GetString("mod"); string name = wallTag.GetString("name"); tables.walls[type] = ModContent.TryFind(modName, name, out ModWall wall) ? wall.Type : (ushort)0; } using (var memoryStream = new MemoryStream(tag.GetByteArray("data"))) using (var reader = new BinaryReader(memoryStream)) ReadTileData(reader, tables); WorldIO.ValidateSigns(); }
internal static void LoadTiles(TagCompound tag) { if (!tag.ContainsKey("data")) { return; } var tables = TileTables.Create(); foreach (var tileTag in tag.GetList <TagCompound>("tileMap")) { ushort type = (ushort)tileTag.GetShort("value"); string modName = tileTag.GetString("mod"); string name = tileTag.GetString("name"); Mod mod = ModLoader.GetMod(modName); tables.tiles[type] = mod == null ? (ushort)0 : (ushort)mod.TileType(name); if (tables.tiles[type] == 0) { tables.tiles[type] = (ushort)ModLoader.GetMod("ModLoader").TileType("PendingMysteryTile"); tables.tileModNames[type] = modName; tables.tileNames[type] = name; } tables.frameImportant[type] = tileTag.GetBool("framed"); } foreach (var wallTag in tag.GetList <TagCompound>("wallMap")) { ushort wall = (ushort)wallTag.GetShort("value"); string modName = wallTag.GetString("mod"); string name = wallTag.GetString("name"); Mod mod = ModLoader.GetMod(modName); tables.walls[wall] = mod == null ? (ushort)0 : (ushort)mod.WallType(name); } ReadTileData(new BinaryReader(new MemoryStream(tag.GetByteArray("data"))), tables); }
public static void Load(Item item, TagCompound tag) { string modName = tag.GetString("mod"); if (modName == "") { item.netDefaults(0); return; } if (modName == "Terraria") { item.netDefaults(tag.GetInt("id")); } else { if (ModContent.TryFind(modName, tag.GetString("name"), out ModItem modItem)) { item.SetDefaults(modItem.Type); item.modItem.Load(tag.GetCompound("data")); } else { item.SetDefaults(ModContent.ItemType <UnloadedItem>()); ((UnloadedItem)item.modItem).Setup(tag); } } if (tag.ContainsKey("modPrefixMod") && tag.ContainsKey("modPrefixName")) { item.Prefix(ModContent.TryFind(tag.GetString("modPrefixMod"), tag.GetString("modPrefixName"), out ModPrefix prefix) ? prefix.Type : 0); } else if (tag.ContainsKey("prefix")) { item.Prefix(tag.GetByte("prefix")); } item.stack = tag.Get <int?>("stack") ?? 1; item.favorited = tag.GetBool("fav"); if (!(item.modItem is UnloadedItem)) { LoadGlobals(item, tag.GetList <TagCompound>("globalData")); } }
internal static void LoadContainers(TagCompound tag) { if (tag.ContainsKey("data")) { ReadContainers(new BinaryReader(new MemoryStream(tag.GetByteArray("data")))); } foreach (var frameTag in tag.GetList <TagCompound>("itemFrames")) { TEItemFrame itemFrame = TileEntity.ByID[tag.GetInt("id")] as TEItemFrame; ItemIO.Load(itemFrame.item, frameTag.GetCompound("item")); } }
//NOTE: LoadBasics can't be separated into LoadWalls() and LoadTiles() because of LoadLegacy. internal static void LoadBasics(TagCompound tag) { Tiles.LoadEntries(tag, out var tileEntriesLookup); Walls.LoadEntries(tag, out var wallEntriesLookup); if (!tag.ContainsKey("wallData")) { LoadLegacy(tag, tileEntriesLookup, wallEntriesLookup); } else { Tiles.LoadData(tag, tileEntriesLookup); Walls.LoadData(tag, wallEntriesLookup); } WorldIO.ValidateSigns(); //call this at end }
public override T Deserialize(TagCompound tag) { if (tag.ContainsKey("<type>") && tag.GetString("<type>") != Type.FullName) { var instType = GetType(tag.GetString("<type>")); if (instType != null && Type.IsAssignableFrom(instType) && TryGetSerializer(instType, out TagSerializer instSerializer)) { return((T)instSerializer.Deserialize(tag)); } } if (deserializer == null) { throw new ArgumentException($"Missing deserializer for type '{Type.FullName}'."); } return(deserializer(tag)); }
internal static void LoadContainers(TagCompound tag) { if (tag.ContainsKey("data")) { ReadContainers(new BinaryReader(new MemoryStream(tag.GetByteArray("data")))); } foreach (var frameTag in tag.GetList <TagCompound>("itemFrames")) { if (TileEntity.ByID.TryGetValue(frameTag.GetInt("id"), out TileEntity tileEntity) && tileEntity is TEItemFrame itemFrame) { ItemIO.Load(itemFrame.item, frameTag.GetCompound("item")); } else { Logging.tML.Warn($"Due to a bug in previous versions of tModLoader, the following ItemFrame data has been lost: {frameTag.ToString()}"); } } }
internal static void LoadAnglerQuest(TagCompound tag) { // Don't try to load modded angler quest item if there isn't one if (!tag.ContainsKey("mod")) { return; } if (ModContent.TryFind(tag.GetString("mod"), tag.GetString("itemName"), out ModItem modItem)) { for (int k = 0; k < Main.anglerQuestItemNetIDs.Length; k++) { if (Main.anglerQuestItemNetIDs[k] == modItem.Type) { Main.anglerQuest = k; return; } } } Main.AnglerQuestSwap(); }
internal static void LoadAnglerQuest(TagCompound tag) { // Don't try to load modded angler quest item if there isn't one if (!tag.ContainsKey("mod")) { return; } var mod = ModLoader.GetMod(tag.GetString("mod")); int type = mod?.ItemType(tag.GetString("itemName")) ?? 0; if (type > 0) { for (int k = 0; k < Main.anglerQuestItemNetIDs.Length; k++) { if (Main.anglerQuestItemNetIDs[k] == type) { Main.anglerQuest = k; return; } } } Main.AnglerQuestSwap(); }