public List <Item> DoCraft(TEStorageHeart heart, List <Item> toWithdraw, Item result) { List <Item> items = new List <Item>(); foreach (Item tryWithdraw in toWithdraw) { Item withdrawn = heart.TryWithdraw(tryWithdraw); if (!withdrawn.IsAir) { items.Add(withdrawn); } if (withdrawn.stack < tryWithdraw.stack) { for (int k = 0; k < items.Count; k++) { heart.DepositItem(items[k]); if (items[k].IsAir) { items.RemoveAt(k); k--; } } return(items); } } items.Clear(); heart.DepositItem(result); if (!result.IsAir) { items.Add(result); } return(items); }
public override void Update() { TEStorageHeart heart = GetHeart(); if (heart != null && !heart.remoteAccesses.Contains(Position)) { heart.remoteAccesses.Add(Position); } }
private bool TryUpgrade(int i, int j) { Player player = Main.player[Main.myPlayer]; Item item = player.inventory[player.selectedItem]; int style = Main.tile[i, j].frameY / 36; bool success = false; if (style == 0 && item.type == mod.ItemType(nameof(UpgradeDemonite))) { SetStyle(i, j, 1); success = true; } else if (style == 0 && item.type == mod.ItemType(nameof(UpgradeCrimtane))) { SetStyle(i, j, 2); success = true; } else if ((style == 1 || style == 2) && item.type == mod.ItemType(nameof(UpgradeHellstone))) { SetStyle(i, j, 3); success = true; } else if (style == 3 && item.type == mod.ItemType(nameof(UpgradeHallowed))) { SetStyle(i, j, 4); success = true; } else if (style == 4 && item.type == mod.ItemType(nameof(UpgradeBlueChlorophyte))) { SetStyle(i, j, 5); success = true; } else if (style == 5 && item.type == mod.ItemType(nameof(UpgradeLuminite))) { SetStyle(i, j, 6); success = true; } else if (style == 6 && item.type == mod.ItemType(nameof(UpgradeTerra))) { SetStyle(i, j, 7); success = true; } if (success) { TEStorageUnit storageUnit = (TEStorageUnit)TileEntity.ByPosition[new Point16(i, j)]; storageUnit.UpdateTileFrame(); NetMessage.SendTileRange(Main.myPlayer, i, j, 2, 2); TEStorageHeart heart = storageUnit.GetHeart(); if (heart != null) { if (Main.netMode == NetmodeID.SinglePlayer) { heart.ResetCompactStage(); } else if (Main.netMode == NetmodeID.MultiplayerClient) { NetHelper.SendResetCompactStage(heart.ID); } } item.stack--; if (item.stack <= 0) { item.SetDefaults(0); } if (player.selectedItem == 58) { Main.mouseItem = item.Clone(); } } return(success); }
public void ResetAndSearch() { List <Point16> oldStorageUnits = new List <Point16>(storageUnits); storageUnits.Clear(); HashSet <Point16> hashStorageUnits = new HashSet <Point16>(); HashSet <Point16> explored = new HashSet <Point16>(); explored.Add(Position); Queue <Point16> toExplore = new Queue <Point16>(); foreach (Point16 point in AdjacentComponents()) { toExplore.Enqueue(point); } bool changed = false; while (toExplore.Count > 0) { Point16 explore = toExplore.Dequeue(); if (!explored.Contains(explore) && explore != TStorageComponent.killTile) { explored.Add(explore); if (TileEntity.ByPosition.ContainsKey(explore) && TileEntity.ByPosition[explore] is TEAbstractStorageUnit) { TEAbstractStorageUnit storageUnit = (TEAbstractStorageUnit)TileEntity.ByPosition[explore]; if (storageUnit.Link(Position)) { NetHelper.SendTEUpdate(storageUnit.ID, storageUnit.Position); changed = true; } storageUnits.Add(explore); hashStorageUnits.Add(explore); } foreach (Point16 point in AdjacentComponents(explore)) { toExplore.Enqueue(point); } } } sockets = GetCraftingSockets(); foreach (Point16 oldStorageUnit in oldStorageUnits) { if (!hashStorageUnits.Contains(oldStorageUnit)) { if (TileEntity.ByPosition.ContainsKey(oldStorageUnit) && TileEntity.ByPosition[oldStorageUnit] is TEAbstractStorageUnit) { TileEntity storageUnit = TileEntity.ByPosition[oldStorageUnit]; ((TEAbstractStorageUnit)storageUnit).Unlink(); NetHelper.SendTEUpdate(storageUnit.ID, storageUnit.Position); } changed = true; } } if (changed) { TEStorageHeart heart = GetHeart(); if (heart != null) { heart.ResetCompactStage(); } NetHelper.SendTEUpdate(ID, Position); if (Main.netMode != NetmodeID.Server) { MagicStorageTwo.Instance.guiM.Refresh(); } } }