summaryrefslogtreecommitdiffstats
path: root/source
diff options
context:
space:
mode:
authormadmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6>2012-08-14 16:41:57 +0200
committermadmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6>2012-08-14 16:41:57 +0200
commit004401a70aafe3526a48d50cae94bea41c1d5176 (patch)
treed431ee37bfa427ca3aadc005bd3dd06860475ed0 /source
parentCrafting window crafting grid shift-click handling (diff)
downloadcuberite-004401a70aafe3526a48d50cae94bea41c1d5176.tar
cuberite-004401a70aafe3526a48d50cae94bea41c1d5176.tar.gz
cuberite-004401a70aafe3526a48d50cae94bea41c1d5176.tar.bz2
cuberite-004401a70aafe3526a48d50cae94bea41c1d5176.tar.lz
cuberite-004401a70aafe3526a48d50cae94bea41c1d5176.tar.xz
cuberite-004401a70aafe3526a48d50cae94bea41c1d5176.tar.zst
cuberite-004401a70aafe3526a48d50cae94bea41c1d5176.zip
Diffstat (limited to '')
-rw-r--r--source/cCraftingWindow.cpp62
1 files changed, 53 insertions, 9 deletions
diff --git a/source/cCraftingWindow.cpp b/source/cCraftingWindow.cpp
index a41eede70..40e41f2c4 100644
--- a/source/cCraftingWindow.cpp
+++ b/source/cCraftingWindow.cpp
@@ -18,6 +18,21 @@
+/* These numbers are valid for the underlying cInventory object, because that's where we're sending the
+MoveItem() and HowManyCanFit() function calls
+*/
+enum
+{
+ SLOT_INVENTORY_MIN = 9,
+ SLOT_INVENTORY_MAX = 35,
+ SLOT_HOTBAR_MIN = 36,
+ SLOT_HOTBAR_MAX = 44
+} ;
+
+
+
+
+
cCraftingWindow::cCraftingWindow( cWindowOwner* a_Owner, bool a_bInventoryVisible )
: cWindow(a_Owner, a_bInventoryVisible, cWindow::Workbench, 1)
{
@@ -162,7 +177,44 @@ void cCraftingWindow::ShiftClicked(cPacket_WindowClick * a_ClickPacket, cPlayer
void cCraftingWindow::ShiftClickedCraftingResult(short a_Slot, cPlayer & a_Player)
{
- // TODO
+ // Craft until either the recipe changes (due to ingredients) or there's not enough storage for the result
+ cInventory & Inventory = a_Player.GetInventory();
+ cItem * CraftingResult = GetSlot(SLOT_CRAFTING_RESULT);
+ if ((CraftingResult == NULL) || CraftingResult->IsEmpty())
+ {
+ return;
+ }
+ cItem ResultCopy = *CraftingResult;
+ int HowManyItemsWillFit = Inventory.HowManyCanFit(CraftingResult->m_ItemID, CraftingResult->m_ItemHealth, SLOT_INVENTORY_MIN, SLOT_INVENTORY_MAX);
+ HowManyItemsWillFit += Inventory.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 = Inventory.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)
+ {
+ NumMoved += Inventory.MoveItem(CraftingResult->m_ItemID, CraftingResult->m_ItemHealth, CraftingResult->m_ItemCount - NumMoved, SLOT_INVENTORY_MIN, SLOT_INVENTORY_MAX);
+ ASSERT(NumMoved == CraftingResult->m_ItemCount); // We checked earlier that we can fit this many items
+ }
+
+ // "Use" the crafting recipe once:
+ cCraftingGrid Grid(GetSlots() + 1, 3, 3);
+ cCraftingRecipe Recipe(Grid);
+ cRoot::Get()->GetCraftingRecipes()->GetRecipe(&a_Player, Grid, Recipe);
+ Recipe.ConsumeIngredients(Grid);
+ Grid.CopyToItems(GetSlots() + 1);
+ cRoot::Get()->GetCraftingRecipes()->GetRecipe(&a_Player, Grid, Recipe);
+ GetSlots()[SLOT_CRAFTING_RESULT] = Recipe.GetResult();
+
+ // If the recipe changed, abort:
+ if (!Recipe.GetResult().Equals(ResultCopy))
+ {
+ break;
+ }
+ }
}
@@ -171,14 +223,6 @@ void cCraftingWindow::ShiftClickedCraftingResult(short a_Slot, cPlayer & a_Playe
void cCraftingWindow::ShiftClickedCraftingGrid(short a_Slot, cPlayer & a_Player)
{
- enum
- {
- SLOT_INVENTORY_MIN = 9,
- SLOT_INVENTORY_MAX = 35,
- SLOT_HOTBAR_MIN = 36,
- SLOT_HOTBAR_MAX = 44
- } ;
-
cInventory & Inventory = a_Player.GetInventory();
cItem * Item = GetSlot(a_Slot);
if ((Item == NULL) || Item->IsEmpty())