internal void Update() { HandlerCache.Clear(); for (int i = 0; i < Tiles.Count; i++) { Duct duct = Tiles[i]; ItemHandler handler = duct.Module?.GetHandler(); if (handler != null) { if (HandlerCache.ContainsKey(handler)) { HandlerCache[handler].Add(duct.Module); } else { HandlerCache.Add(handler, new List <BaseModule> { duct.Module }); } } } //Main.NewText("Tracking " + HandlerCache.Count + " handlers and " + HandlerCache.Sum(pair => pair.Value.Count) + " modules"); for (int i = 0; i < NetworkItems.Count; i++) { NetworkItem item = NetworkItems[i]; item.Update(); if (item.item == null || item.item.IsAir) { NetworkItems.Remove(item); } } }
public bool PullItem(int type, int count, Duct destination) { foreach (ProviderModule module in ProviderModules) { ItemHandler handler = module.GetHandler(); if (handler == null) { continue; } int available = module.GetAvailableItems(type); if (available <= 0) { continue; } for (int i = 0; i < handler.Slots; i++) { Item item = handler.Items[i]; if (item.IsAir || item.type != type) { continue; } int extractedAmount = Utility.Min(count, item.stack, available); if (extractedAmount <= 0) { continue; } NetworkItem networkItem = new NetworkItem(handler.ExtractItem(i, extractedAmount), module.Parent, destination); NetworkItems.Add(networkItem); ItemCache[item.netID] -= extractedAmount; if (ItemCache[item.netID] <= 0) { ItemCache.Remove(item.type); } UpdateUIs(); count -= extractedAmount; available -= extractedAmount; if (count <= 0) { return(true); } } } return(false); }