public static TileSaveData DeserializeData(TagCompound tag) { var output = new TileSaveData( tag.GetString("Tile"), tag.GetString("Wall"), tag.GetShort("FrameX"), tag.GetShort("FrameY"), tag.GetInt("WallWireData"), tag.GetShort("PackedLiquidData") ); if (tag.ContainsKey("TEType")) { output.TEType = tag.GetString("TEType"); output.TEData = tag.Get <TagCompound>("TEData"); } return(output); }
internal static unsafe bool Generate(TagCompound tag, Point16 pos, bool ignoreNull = false) { List <TileSaveData> data = (List <TileSaveData>)tag.GetList <TileSaveData>("TileData"); if (data is null) { StructureHelper.Instance.Logger.Warn("Corrupt or Invalid structure data."); return(false); } int width = tag.GetInt("Width"); int height = tag.GetInt("Height"); for (int x = 0; x <= width; x++) { for (int y = 0; y <= height; y++) { bool isNullTile = false; bool isNullWall = false; int index = y + x * (height + 1); TileSaveData d = data[index]; Tile tile = Framing.GetTileSafely(pos.X + x, pos.Y + y); if (!int.TryParse(d.Tile, out int type)) { string[] parts = d.Tile.Split(); if (parts[0] == "StructureHelper" && parts[1] == "NullBlock" && !ignoreNull) { isNullTile = true; } else if (parts.Length > 1 && ModLoader.GetMod(parts[0]) != null && ModLoader.GetMod(parts[0]).TryFind <ModTile>(parts[1], out ModTile modTileType)) { type = modTileType.Type; } else { type = 0; } } if (!int.TryParse(d.Wall, out int wallType)) { string[] parts = d.Wall.Split(); if (parts[0] == "StructureHelper" && parts[1] == "NullWall" && !ignoreNull) { isNullWall = true; } else if (parts.Length > 1 && ModLoader.GetMod(parts[0]) != null && ModLoader.GetMod(parts[0]).TryFind <ModWall>(parts[1], out ModWall modWallType)) { wallType = modWallType.Type; } else { wallType = 0; } } if (!d.Active) { isNullTile = false; } if (!isNullTile || ignoreNull) //leave everything else about the tile alone if its a null block { tile.ClearEverything(); tile.TileType = (ushort)type; tile.TileFrameX = d.FrameX; tile.TileFrameY = d.FrameY; fixed(void *ptr = &tile.Get <TileWallWireStateData>()) { var intPtr = (int *)(ptr); intPtr++; *intPtr = d.WallWireData; } fixed(void *ptr = &tile.Get <LiquidData>()) { var shortPtr = (short *)ptr; *shortPtr = d.PackedLiquidData; } if (!d.Active) { tile.HasTile = false; } if (d.TEType != "") //place and load a tile entity { if (d.TEType != "") { if (d.TEType == "StructureHelper ChestEntity" && !ignoreNull) { GenerateChest(new Point16(pos.X + x, pos.Y + y), d.TEData); } else { int typ; if (!int.TryParse(d.TEType, out typ)) { string[] parts = d.TEType.Split(); typ = ModLoader.GetMod(parts[0]).Find <ModTileEntity>(parts[1]).Type; } TileEntity.PlaceEntityNet(pos.X + x, pos.Y + y, typ); if (d.TEData != null && typ > 2) { (TileEntity.ByPosition[new Point16(pos.X + x, pos.Y + y)] as ModTileEntity).LoadData(d.TEData); } } } } else if ((type == TileID.Containers || TileID.Sets.BasicChest[tile.TileType]) && d.FrameX % 36 == 0 && d.FrameY % 36 == 0) //generate an empty chest if there is no chest data { Chest.CreateChest(pos.X + x, pos.Y + y); } } if (!isNullWall || ignoreNull) //leave the wall alone if its a null wall { tile.WallType = (ushort)wallType; } } } return(true); }