summaryrefslogtreecommitdiffstats
path: root/src/Inventory.cpp
diff options
context:
space:
mode:
authorAlexander Harkness <me@bearbin.net>2015-05-27 13:21:17 +0200
committerAlexander Harkness <me@bearbin.net>2015-05-27 13:21:17 +0200
commitda4a76bb5043d072513b74823dc79279c75dd70c (patch)
tree5c46cca70beb5e0b0d0161b5ccb306425e6426dd /src/Inventory.cpp
parentMerge pull request #2143 from jammet/patch-6 (diff)
parentFixes #2041 (diff)
downloadcuberite-da4a76bb5043d072513b74823dc79279c75dd70c.tar
cuberite-da4a76bb5043d072513b74823dc79279c75dd70c.tar.gz
cuberite-da4a76bb5043d072513b74823dc79279c75dd70c.tar.bz2
cuberite-da4a76bb5043d072513b74823dc79279c75dd70c.tar.lz
cuberite-da4a76bb5043d072513b74823dc79279c75dd70c.tar.xz
cuberite-da4a76bb5043d072513b74823dc79279c75dd70c.tar.zst
cuberite-da4a76bb5043d072513b74823dc79279c75dd70c.zip
Diffstat (limited to 'src/Inventory.cpp')
-rw-r--r--src/Inventory.cpp30
1 files changed, 26 insertions, 4 deletions
diff --git a/src/Inventory.cpp b/src/Inventory.cpp
index c595da5b0..f08dd1896 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,30 @@ 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);
+ 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 +153,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);