public bool TransactionalRemove(EditorItemStack[] editorItemStacks) { // Each transaction consists of a slot ID to identify where the items came from and an // ItemStack which defines what was removed List <Tuple <int, ItemStack> > transactions = new List <Tuple <int, ItemStack> >(); //int[] transactions = new int[editorItemStacks.Length * 3]; bool success = true; // Go through each required item foreach (var itemStack in editorItemStacks) { // Track how many of the item we still need ushort count = itemStack.Count; // Find all of the slots that contain the item we are looking for var slots = GetSlotsForItem(itemStack.Item.Id); // If there are slots with the item we need then: // - Loop over each slot // - Remove as many items from the slot as we can (never removing more than we need) // - if (slots != null) { foreach (var slotIndex in slots) { ISlot slot = _slots[(int)slotIndex]; ushort slotCount = slot.ItemStack.Count; ItemStack removed = null; // If there are more in the slot than we need, remove the exact amount we need if (slotCount > count) { removed = slot.Remove(count); slotCount = count; // reuse the variable to track how many we removed } else { // NOTE: This is where the current error is branching to before executing removed = slot.Remove(); } // If there was an item to remove, track the transaction as (slot affected, number of items removed) if (removed != null) { transactions.Add(new Tuple <int, ItemStack>((int)slotIndex, removed)); } // Reduce the count by the amount of items we just removed from the current slot count -= slotCount; // If we have removed all of the items we need, then stop looping over the slots with the item we needed if (count == 0) { break; } } } // Now that we have either looped over all the slots for the item we currently need, check if we removed the correct amount if (count > 0) { success = false; break; } } if (!success) { Rollback(transactions); } return(success); }
public virtual ItemStack Remove() => _slot.Remove();