summaryrefslogtreecommitdiffstats
path: root/src/UI/SlotArea.cpp
diff options
context:
space:
mode:
authorTobias Wilken <TooAngel@TooAngel.de>2020-07-14 18:56:42 +0200
committerGitHub <noreply@github.com>2020-07-14 18:56:42 +0200
commit36eab1b3237dbeeaaf5b48808bf0d47eb4bd32e9 (patch)
tree04c224231a800002692a296131af4988dd465845 /src/UI/SlotArea.cpp
parentCustom command depend is automatic (diff)
downloadcuberite-36eab1b3237dbeeaaf5b48808bf0d47eb4bd32e9.tar
cuberite-36eab1b3237dbeeaaf5b48808bf0d47eb4bd32e9.tar.gz
cuberite-36eab1b3237dbeeaaf5b48808bf0d47eb4bd32e9.tar.bz2
cuberite-36eab1b3237dbeeaaf5b48808bf0d47eb4bd32e9.tar.lz
cuberite-36eab1b3237dbeeaaf5b48808bf0d47eb4bd32e9.tar.xz
cuberite-36eab1b3237dbeeaaf5b48808bf0d47eb4bd32e9.tar.zst
cuberite-36eab1b3237dbeeaaf5b48808bf0d47eb4bd32e9.zip
Diffstat (limited to '')
-rw-r--r--src/UI/SlotArea.cpp70
1 files changed, 65 insertions, 5 deletions
diff --git a/src/UI/SlotArea.cpp b/src/UI/SlotArea.cpp
index 0bbfb4b12..1552d4bfe 100644
--- a/src/UI/SlotArea.cpp
+++ b/src/UI/SlotArea.cpp
@@ -665,6 +665,7 @@ void cSlotAreaCrafting::ShiftClickedResult(cPlayer & a_Player)
{
return;
}
+ a_Player.AddKnownItem(Result);
cItem * PlayerSlots = GetPlayerSlots(a_Player) + 1;
for (;;)
{
@@ -780,6 +781,70 @@ void cSlotAreaCrafting::HandleCraftItem(const cItem & a_Result, cPlayer & a_Play
+void cSlotAreaCrafting::LoadRecipe(cPlayer & a_Player, UInt32 a_RecipeId)
+{
+ if (a_RecipeId == 0)
+ {
+ return;
+ }
+ auto Recipe = cRoot::Get()->GetCraftingRecipes()->GetRecipeById(a_RecipeId);
+
+ int NumItems = 0;
+ ClearCraftingGrid(a_Player);
+
+ for (auto itrS = Recipe->m_Ingredients.begin(); itrS != Recipe->m_Ingredients.end(); ++itrS)
+ {
+ cItem * FoundItem = a_Player.GetInventory().FindItem(itrS->m_Item);
+ if (FoundItem == nullptr)
+ {
+ ClearCraftingGrid(a_Player);
+ break;
+ }
+ cItem Item = FoundItem->CopyOne();
+ ++NumItems;
+ int pos = 1 + itrS->x + m_GridSize * itrS->y;
+ // Assuming there are ether shaped or unshaped recipes, no mixed ones
+ if ((itrS->x == -1) && (itrS->y == -1))
+ {
+ pos = NumItems;
+ }
+ // Handle x wildcard
+ else if (itrS->x == -1)
+ {
+ for (int i = 0; i < m_GridSize; i++)
+ {
+ pos = 1 + i + m_GridSize * itrS->y;
+ auto itemCheck = GetSlot(pos, a_Player);
+ if (itemCheck->IsEmpty())
+ {
+ break;
+ }
+ }
+ }
+ SetSlot(pos, a_Player, Item);
+ a_Player.GetInventory().RemoveItem(Item);
+ }
+}
+
+
+
+
+
+void cSlotAreaCrafting::ClearCraftingGrid(cPlayer & a_Player)
+{
+ for (int pos = 1; pos <= m_GridSize * m_GridSize; pos++)
+ {
+ auto Item = GetSlot(pos, a_Player);
+ if (Item->m_ItemCount > 0)
+ {
+ a_Player.GetInventory().AddItem(*Item);
+ SetSlot(pos, a_Player, cItem());
+ }
+ }
+}
+
+
+
////////////////////////////////////////////////////////////////////////////////
// cSlotAreaAnvil:
@@ -2749,8 +2814,3 @@ void cSlotAreaHorse::DistributeStack(cItem & a_ItemStack, cPlayer & a_Player, bo
--a_ItemStack.m_ItemCount;
}
}
-
-
-
-
-