/** * Processes a queue job. */ private bool ProcessQueueJob(TransformationJob job, out ItemStack[] previousState) { previousState = (ItemStack[])this.items.Clone(); List <ItemStack> outputs = job.GetTransformationData().GetAllOutputsAfterProbabilityCalculation(); List <int> assignedSlots = new List <int>(); List <Tuple <int, ItemStack> > stacksToAdd = new List <Tuple <int, ItemStack> >(); bool canAddAll = true; // If there are no ouputs after probability calculation, then congrats, nothing to do, success. if (outputs.Count == 0) { return(true); } foreach (ItemStack output in outputs) { List <Tuple <int, ItemStack> > whereToAdd; if (!InventoryHelper.RoomInSlotsFor(this.items, output, ref assignedSlots, out whereToAdd)) { canAddAll = false; return(false); } stacksToAdd.AddRange(whereToAdd); } if (canAddAll) { foreach (Tuple <int, ItemStack> positionAndStack in stacksToAdd) { if (!InventoryHelper.TryAddItemToSlot(this.items, positionAndStack.Item1, positionAndStack.Item2)) { return(false); } } } return(canAddAll); }