public static void Craft(IInventory inventory, Recipe recipe) { if (!CanCraft(inventory, recipe)) { return; } inventory.RemoveItemStacks(recipe.Ingredients); inventory.AddItemStacks(new[] { recipe.Result }); }
public void CrossInventoryExchange(IItemStackSlot @from, IItemStackSlot to) { IInventory fromInventory = from.Inventory; IInventory toInventory = to.Inventory; ItemStack fromStack = fromInventory.RemoveStackAtSlot(from.InventoryIndex); if (to.ItemStack.IsEmpty) { toInventory.AddStackAtSlot(fromStack, to.InventoryIndex); } else { ItemStack toStack = toInventory.RemoveStackAtSlot(to.InventoryIndex); fromInventory.AddItemStacks(new[] { toInventory.AddStackAtSlot(fromStack, to.InventoryIndex) }); toInventory.AddItemStacks(new[] { fromInventory.AddStackAtSlot(toStack, from.InventoryIndex) }); } }