Exemple #1
0
        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);
                }
            }

            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"));
            }
        }
Exemple #2
0
        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"));
            }
        }