summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormadmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6>2012-08-14 10:33:09 +0200
committermadmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6>2012-08-14 10:33:09 +0200
commite946616772d68f6646710b5c69c237df3ed641c6 (patch)
tree24b09593dfe63a0bf5db9e9ec59ff482c34aba3d
parentMade cobwebs transparent (diff)
downloadcuberite-e946616772d68f6646710b5c69c237df3ed641c6.tar
cuberite-e946616772d68f6646710b5c69c237df3ed641c6.tar.gz
cuberite-e946616772d68f6646710b5c69c237df3ed641c6.tar.bz2
cuberite-e946616772d68f6646710b5c69c237df3ed641c6.tar.lz
cuberite-e946616772d68f6646710b5c69c237df3ed641c6.tar.xz
cuberite-e946616772d68f6646710b5c69c237df3ed641c6.tar.zst
cuberite-e946616772d68f6646710b5c69c237df3ed641c6.zip
-rw-r--r--source/cInventory.cpp2
-rw-r--r--source/cSurvivalInventory.cpp37
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;
+ }
+ }
}