From e946616772d68f6646710b5c69c237df3ed641c6 Mon Sep 17 00:00:00 2001 From: "madmaxoft@gmail.com" Date: Tue, 14 Aug 2012 08:33:09 +0000 Subject: [PATCH] Shift-click completed in survival inventory window git-svn-id: http://mc-server.googlecode.com/svn/trunk@732 0a769ca7-a7f5-676a-18bf-c427514a06d6 --- source/cInventory.cpp | 2 +- source/cSurvivalInventory.cpp | 37 ++++++++++++++++++++++++++++++++++- 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/source/cInventory.cpp b/source/cInventory.cpp index 1f4405470..8750b5368 100644 --- a/source/cInventory.cpp +++ b/source/cInventory.cpp @@ -348,7 +348,7 @@ int cInventory::MoveItem(ENUM_ITEM_ID a_ItemType, short a_ItemDamage, int a_Coun { int MaxCount = ItemHandler(a_ItemType)->GetMaxStackSize(); ASSERT(m_Slots[i].m_ItemCount <= MaxCount); - int NumToMove = std::min(a_Count, MaxCount); + int NumToMove = std::min(a_Count, MaxCount - m_Slots[i].m_ItemCount); m_Slots[i].m_ItemCount += NumToMove; m_Slots[i].m_ItemHealth = a_ItemDamage; m_Slots[i].m_ItemID = a_ItemType; diff --git a/source/cSurvivalInventory.cpp b/source/cSurvivalInventory.cpp index 62808a17d..50c750100 100644 --- a/source/cSurvivalInventory.cpp +++ b/source/cSurvivalInventory.cpp @@ -151,7 +151,42 @@ void cSurvivalInventory::ShiftClicked(cPacket_WindowClick * a_ClickPacket) void cSurvivalInventory::ShiftClickedCraftingResult(short a_Slot) { - // TODO + // Craft until either the recipe changes (due to ingredients) or there's not enough storage for the result + cItem * CraftingResult = GetSlot(SLOT_CRAFTING_RESULT); + if ((CraftingResult == NULL) || CraftingResult->IsEmpty()) + { + return; + } + cItem ResultCopy = *CraftingResult; + int HowManyItemsWillFit = HowManyCanFit(CraftingResult->m_ItemID, CraftingResult->m_ItemHealth, SLOT_INVENTORY_MIN, SLOT_INVENTORY_MAX); + HowManyItemsWillFit += HowManyCanFit(CraftingResult->m_ItemID, CraftingResult->m_ItemHealth, SLOT_HOTBAR_MIN, SLOT_HOTBAR_MAX); + int HowManyPassesWillFit = HowManyItemsWillFit / CraftingResult->m_ItemCount; + for (int i = 0; i < HowManyPassesWillFit; i++) + { + // First try moving into the hotbar: + int NumMoved = MoveItem(CraftingResult->m_ItemID, CraftingResult->m_ItemHealth, CraftingResult->m_ItemCount, SLOT_HOTBAR_MIN, SLOT_HOTBAR_MAX); + + // If something didn't fit, move into main inventory: + if (NumMoved < CraftingResult->m_ItemCount) + { + MoveItem(CraftingResult->m_ItemID, CraftingResult->m_ItemHealth, CraftingResult->m_ItemCount - NumMoved, SLOT_INVENTORY_MIN, SLOT_INVENTORY_MAX); + } + + // "Use" the crafting recipe once: + cCraftingGrid Grid(m_Slots + SLOT_CRAFTING_MIN, 2, 2); + cCraftingRecipe Recipe(Grid); + cRoot::Get()->GetCraftingRecipes()->GetRecipe(m_Owner, Grid, Recipe); + Recipe.ConsumeIngredients(Grid); + Grid.CopyToItems(m_Slots + c_CraftOffset + 1); + cRoot::Get()->GetCraftingRecipes()->GetRecipe(m_Owner, Grid, Recipe); + m_Slots[SLOT_CRAFTING_RESULT] = Recipe.GetResult(); + + // If the recipe changed, abort: + if (!Recipe.GetResult().Equals(ResultCopy)) + { + break; + } + } }