Пример #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"));
            }
        }
Пример #2
0
            public void LoadData(TagCompound tag, TEntry[] savedEntryLookup)
            {
                using var reader = new BinaryReader(new MemoryStream(tag.GetByteArray(dataKey)));
                var builder = new PosData <ushort> .OrderedSparseLookupBuilder();

                for (int x = 0; x < Main.maxTilesX; x++)
                {
                    for (int y = 0; y < Main.maxTilesY; y++)
                    {
                        ushort saveType = reader.ReadUInt16();
                        if (saveType == 0)
                        {
                            continue;
                        }

                        var entry = savedEntryLookup[saveType];

                        // Set the type to either the existing type or the unloaded type
                        if (entry.IsUnloaded && !canPurgeOldData)
                        {
                            builder.Add(x, y, entry.type);
                        }

                        ReadData(Main.tile[x, y], entry, reader);
                    }
                }

                unloadedEntryLookup = builder.Build();
            }
Пример #3
0
        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();
        }
Пример #4
0
        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);
        }
Пример #5
0
 internal static void LoadLegacy(TagCompound tag, TileEntry[] tileEntriesLookup, WallEntry[] wallEntriesLookup)
 {
     // Retrieve Locational-Specific Data from 'Data' and apply
     using (var memoryStream = new MemoryStream(tag.GetByteArray("data")))
         using (var reader = new BinaryReader(memoryStream)) {
             ReadTileData(reader, tileEntriesLookup, wallEntriesLookup, out var tilePosMapList, out var wallPosMapList);
             Tiles.unloadedEntryLookup = tilePosMapList.ToArray();
             Walls.unloadedEntryLookup = wallPosMapList.ToArray();
         }
 }
Пример #6
0
        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"));
            }
        }
Пример #7
0
        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()}");
                }
            }
        }