summaryrefslogtreecommitdiffstats
path: root/src/Inventory.cpp
diff options
context:
space:
mode:
authortycho <work.tycho@gmail.com>2015-05-28 12:05:41 +0200
committertycho <work.tycho@gmail.com>2015-05-28 12:05:41 +0200
commite19693e529bf26e62a54f60c167d1b4870d7d44a (patch)
tree0b2cb131fa2f009723dd0ecd739ff911a369c763 /src/Inventory.cpp
parentFix warnings in cPath (diff)
parentMerge pull request #2151 from SafwatHalaby/wolf (diff)
downloadcuberite-e19693e529bf26e62a54f60c167d1b4870d7d44a.tar
cuberite-e19693e529bf26e62a54f60c167d1b4870d7d44a.tar.gz
cuberite-e19693e529bf26e62a54f60c167d1b4870d7d44a.tar.bz2
cuberite-e19693e529bf26e62a54f60c167d1b4870d7d44a.tar.lz
cuberite-e19693e529bf26e62a54f60c167d1b4870d7d44a.tar.xz
cuberite-e19693e529bf26e62a54f60c167d1b4870d7d44a.tar.zst
cuberite-e19693e529bf26e62a54f60c167d1b4870d7d44a.zip
Diffstat (limited to 'src/Inventory.cpp')
-rw-r--r--src/Inventory.cpp31
1 files changed, 26 insertions, 5 deletions
diff --git a/src/Inventory.cpp b/src/Inventory.cpp
index 079743e90..6b3c8e62f 100644
--- a/src/Inventory.cpp
+++ b/src/Inventory.cpp
@@ -98,7 +98,7 @@ int cInventory::HowManyCanFit(const cItem & a_ItemStack, int a_BeginSlotNum, int
-int cInventory::AddItem(const cItem & a_Item, bool a_AllowNewStacks, bool a_tryToFillEquippedFirst)
+int cInventory::AddItem(const cItem & a_Item, bool a_AllowNewStacks)
{
cItem ToAdd(a_Item);
int res = 0;
@@ -116,8 +116,29 @@ int cInventory::AddItem(const cItem & a_Item, bool a_AllowNewStacks, bool a_tryT
}
}
- res += m_HotbarSlots.AddItem(ToAdd, a_AllowNewStacks, a_tryToFillEquippedFirst ? m_EquippedSlotNum : -1);
- ToAdd.m_ItemCount = a_Item.m_ItemCount - static_cast<char>(res);
+ for (int SlotIdx = 0; SlotIdx < m_InventorySlots.GetNumSlots(); ++SlotIdx)
+ {
+ auto & Slot = m_InventorySlots.GetSlot(SlotIdx);
+ if (Slot.IsEqual(a_Item))
+ {
+ cItemHandler Handler(Slot.m_ItemType);
+ int AmountToAdd = std::min(static_cast<char>(Handler.GetMaxStackSize() - Slot.m_ItemCount), ToAdd.m_ItemCount);
+ res += AmountToAdd;
+
+ cItem SlotAdjusted(Slot);
+ SlotAdjusted.m_ItemCount += AmountToAdd;
+ m_InventorySlots.SetSlot(SlotIdx, SlotAdjusted);
+
+ ToAdd.m_ItemCount -= AmountToAdd;
+ if (ToAdd.m_ItemCount == 0)
+ {
+ return res;
+ }
+ }
+ }
+
+ res += m_HotbarSlots.AddItem(ToAdd, a_AllowNewStacks);
+ ToAdd.m_ItemCount = a_Item.m_ItemCount - res;
if (ToAdd.m_ItemCount == 0)
{
return res;
@@ -131,12 +152,12 @@ int cInventory::AddItem(const cItem & a_Item, bool a_AllowNewStacks, bool a_tryT
-int cInventory::AddItems(cItems & a_ItemStackList, bool a_AllowNewStacks, bool a_tryToFillEquippedFirst)
+int cInventory::AddItems(cItems & a_ItemStackList, bool a_AllowNewStacks)
{
int TotalAdded = 0;
for (cItems::iterator itr = a_ItemStackList.begin(); itr != a_ItemStackList.end();)
{
- int NumAdded = AddItem(*itr, a_AllowNewStacks, a_tryToFillEquippedFirst);
+ int NumAdded = AddItem(*itr, a_AllowNewStacks);
if (itr->m_ItemCount == NumAdded)
{
itr = a_ItemStackList.erase(itr);