Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches

◆ SaveChests()

static int Terraria.IO.WorldFile.SaveChests ( BinaryWriter writer)
inlinestatic

Definition at line 1533 of file WorldFile.cs.

1534 {
1535 short num = 0;
1536 for (int i = 0; i < 8000; i++)
1537 {
1538 Chest chest = Main.chest[i];
1539 if (chest == null)
1540 {
1541 continue;
1542 }
1543 bool flag = false;
1544 for (int j = chest.x; j <= chest.x + 1; j++)
1545 {
1546 for (int k = chest.y; k <= chest.y + 1; k++)
1547 {
1548 if (j < 0 || k < 0 || j >= Main.maxTilesX || k >= Main.maxTilesY)
1549 {
1550 flag = true;
1551 break;
1552 }
1553 Tile tile = Main.tile[j, k];
1554 if (!tile.active() || !Main.tileContainer[tile.type])
1555 {
1556 flag = true;
1557 break;
1558 }
1559 }
1560 }
1561 if (flag)
1562 {
1563 Main.chest[i] = null;
1564 }
1565 else
1566 {
1567 num++;
1568 }
1569 }
1570 writer.Write(num);
1571 writer.Write((short)40);
1572 for (int i = 0; i < 8000; i++)
1573 {
1574 Chest chest = Main.chest[i];
1575 if (chest == null)
1576 {
1577 continue;
1578 }
1579 writer.Write(chest.x);
1580 writer.Write(chest.y);
1581 writer.Write(chest.name);
1582 for (int l = 0; l < 40; l++)
1583 {
1584 Item item = chest.item[l];
1586 {
1587 writer.Write((short)0);
1588 continue;
1589 }
1590 if (item.stack < 0)
1591 {
1592 item.stack = 1;
1593 }
1594 writer.Write((short)item.stack);
1595 if (item.stack > 0)
1596 {
1597 writer.Write(item.netID);
1598 writer.Write(item.prefix);
1599 }
1600 }
1601 }
1602 return (int)writer.BaseStream.Position;
1603 }
static bool[] ItemsThatShouldNotBeInInventory
Definition ItemID.cs:57

References Terraria.Tile.active(), Terraria.Main.chest, System.item, Terraria.Chest.item, Terraria.ID.ItemID.Sets.ItemsThatShouldNotBeInInventory, Terraria.Main.maxTilesX, Terraria.Main.maxTilesY, Terraria.Chest.name, Terraria.Main.tile, Terraria.Main.tileContainer, Terraria.Tile.type, System.writer, Terraria.Chest.x, and Terraria.Chest.y.

Referenced by Terraria.IO.WorldFile.SaveWorld_Version2().