private Item DoWithdraw(Item item, bool toInventory = false) { if (Main.netMode == NetmodeID.SinglePlayer) { return(heart.TryWithdraw(item)); } NetHelper.SendWithdraw(heart.ID, item, toInventory); return(new Item()); }
public static void DoWithdrawItemForCraft(Recipe self, ref Item item, ref int required) { if (StoragePlayer.Get.StorageAccess.X < 0) { return; } var instance = MagicStoragePlus.Instance.StorageUI; bool changed = false; foreach (Item i in instance.items) { if (required <= 0) { if (changed) { instance.RefreshItems(); } return; } if (item.IsTheSameAs(i) || self.useWood(item.type, i.type) || self.useSand(item.type, i.type) || self.useIronBar(item.type, i.type) || self.usePressurePlate(item.type, i.type) || self.useFragment(item.type, i.type) || self.AcceptedByItemGroups(item.type, i.type)) { int count = Math.Min(required, item.stack); required -= count; var request = i.Clone(); request.stack = count; TEStorageHeart heart = StoragePlayer.GetStorageHeart(); if (Main.netMode == 0) { request = heart.TryWithdraw(request); } else { NetHelper.SendWithdraw(heart.ID, request, NetHelper.StorageOp.WithdrawJustRemove); request = new Item(); } if (!request.IsAir) { request.TurnToAir(); changed = true; } } } if (changed) { instance.RefreshItems(); } }
private static Item DoWithdraw(Item item, bool toInventory = false) { TEStorageHeart heart = GetHeart(); if (Main.netMode == 0) { return(heart.TryWithdraw(item)); } else { NetHelper.SendWithdraw(heart.ID, item, toInventory); return(new Item()); } }
static Item DoWithdraw(Item item, bool toInventory = false) { TEStorageHeart heart = StoragePlayer.GetStorageHeart(); if (Main.netMode == 0) { return(heart.TryWithdraw(item)); } else { var type = toInventory ? NetHelper.StorageOp.WithdrawToInventory : NetHelper.StorageOp.Withdraw; NetHelper.SendWithdraw(heart.ID, item, type); return(new Item()); } }
public void TakeItem(int x, int y, object slot, int amount) { TEStorageHeart targetHeart = FindHeart(x, y); if (targetHeart == null) { return; } Item toWithdraw = ((Item)slot).Clone(); toWithdraw.stack = amount; targetHeart.TryWithdraw(toWithdraw); HandleStorageItemChange(targetHeart); }
internal 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 static void ReceiveStorageOp(BinaryReader reader, int sender) { if (Main.netMode != 2) { return; } int ent = reader.ReadInt32(); if (!TileEntity.ByID.ContainsKey(ent) || !(TileEntity.ByID[ent] is TEStorageHeart)) { return; } TEStorageHeart heart = (TEStorageHeart)TileEntity.ByID[ent]; var op = (StorageOp)reader.ReadByte(); if (op == StorageOp.Deposit) { Item item = ItemIO.Receive(reader, true); heart.DepositItem(item); if (!item.IsAir) { ModPacket packet = PrepareOpResult(op); ItemIO.Send(item, packet, true); packet.Send(sender); } } else if (op == StorageOp.DepositList) { int count = reader.ReadByte(); List <Item> items = new List <Item>(); StartUpdateQueue(); for (int k = 0; k < count; k++) { Item item = ItemIO.Receive(reader, true); heart.DepositItem(item); if (!item.IsAir) { items.Add(item); } } ProcessUpdateQueue(); if (items.Count > 0) { ModPacket packet = PrepareOpResult(op); packet.Write((byte)items.Count); foreach (Item item in items) { ItemIO.Send(item, packet, true); } packet.Send(sender); } } else if (op == StorageOp.Withdraw || op == StorageOp.WithdrawToInventory) { Item item = ItemIO.Receive(reader, true); item = heart.TryWithdraw(item); if (!item.IsAir) { ModPacket packet = PrepareOpResult(op); ItemIO.Send(item, packet, true); packet.Send(sender); } } else if (op == StorageOp.WithdrawJustRemove) { // @Robustness: We assume that nothing could go wrong here. // And maybe nothing could. But still something to look at for potential bugs... Item item = ItemIO.Receive(reader, true); heart.TryWithdraw(item); } SendRefreshNetworkItems(ent); }
public static void ReceiveStorageOperation(BinaryReader reader, int sender) { if (Main.netMode != 2) { return; } int ent = reader.ReadInt32(); if (!TileEntity.ByID.ContainsKey(ent) || !(TileEntity.ByID[ent] is TEStorageHeart)) { return; } TEStorageHeart heart = (TEStorageHeart)TileEntity.ByID[ent]; byte op = reader.ReadByte(); if (op == 0) { Item item = ItemIO.Receive(reader, true); heart.DepositItem(item); if (!item.IsAir) { ModPacket packet = PrepareOperationResult(op); ItemIO.Send(item, packet, true); packet.Send(sender); } } else if (op == 1 || op == 3) { Item item = ItemIO.Receive(reader, true); item = heart.TryWithdraw(item); if (!item.IsAir) { ModPacket packet = PrepareOperationResult(op); ItemIO.Send(item, packet, true); packet.Send(sender); } } else if (op == 2) { int count = reader.ReadByte(); List <Item> items = new List <Item>(); StartUpdateQueue(); for (int k = 0; k < count; k++) { Item item = ItemIO.Receive(reader, true); heart.DepositItem(item); if (!item.IsAir) { items.Add(item); } } ProcessUpdateQueue(); if (items.Count > 0) { ModPacket packet = PrepareOperationResult(op); packet.Write((byte)items.Count); foreach (Item item in items) { ItemIO.Send(item, packet, true); } packet.Send(sender); } } SendRefreshNetworkItems(ent); }
public static void ReceiveStorageOperation(BinaryReader reader, int sender) { int ent = reader.ReadInt32(); byte op = reader.ReadByte(); /* * if (Main.netMode == NetmodeID.Server) * Console.WriteLine($"Receiving Storage Operation {op} from entity {ent}"); * else * Main.NewText($"Receiving Storage Operation {op} from entity {ent}"); */ if (Main.netMode != 2) { //The data still needs to be read for exceptions to not be thrown... if (op == 0 || op == 1 || op == 3) { ItemIO.Receive(reader, true); } else if (op == 3) { int count = reader.ReadByte(); for (int i = 0; i < count; i++) { ItemIO.Receive(reader, true); } } return; } if (!TileEntity.ByID.ContainsKey(ent) || !(TileEntity.ByID[ent] is TEStorageHeart)) { return; } TEStorageHeart heart = (TEStorageHeart)TileEntity.ByID[ent]; if (op == 0) { Item item = ItemIO.Receive(reader, true); heart.DepositItem(item); if (!item.IsAir) { ModPacket packet = PrepareOperationResult(op); ItemIO.Send(item, packet, true); packet.Send(sender); } } else if (op == 1 || op == 3) { Item item = ItemIO.Receive(reader, true); item = heart.TryWithdraw(item); if (!item.IsAir) { ModPacket packet = PrepareOperationResult(op); ItemIO.Send(item, packet, true); packet.Send(sender); } } else if (op == 2) { int count = reader.ReadByte(); List <Item> items = new List <Item>(); StartUpdateQueue(); for (int k = 0; k < count; k++) { Item item = ItemIO.Receive(reader, true); heart.DepositItem(item); if (!item.IsAir) { items.Add(item); } } ProcessUpdateQueue(); if (items.Count > 0) { ModPacket packet = PrepareOperationResult(op); packet.Write((byte)items.Count); foreach (Item item in items) { ItemIO.Send(item, packet, true); } packet.Send(sender); } } SendRefreshNetworkItems(ent); }