diff options
author | Howaner <franzi.moos@googlemail.com> | 2014-06-24 16:19:22 +0200 |
---|---|---|
committer | Howaner <franzi.moos@googlemail.com> | 2014-06-24 16:19:22 +0200 |
commit | 2dd7a0373be83ab917c3c115af519b42ce30e2a9 (patch) | |
tree | 57fc8d18d9d2d2cddbd08a4c329971f0052facd8 /src/Entities | |
parent | Fix pickup combining over the maximum stack size. (diff) | |
download | cuberite-2dd7a0373be83ab917c3c115af519b42ce30e2a9.tar cuberite-2dd7a0373be83ab917c3c115af519b42ce30e2a9.tar.gz cuberite-2dd7a0373be83ab917c3c115af519b42ce30e2a9.tar.bz2 cuberite-2dd7a0373be83ab917c3c115af519b42ce30e2a9.tar.lz cuberite-2dd7a0373be83ab917c3c115af519b42ce30e2a9.tar.xz cuberite-2dd7a0373be83ab917c3c115af519b42ce30e2a9.tar.zst cuberite-2dd7a0373be83ab917c3c115af519b42ce30e2a9.zip |
Diffstat (limited to '')
-rw-r--r-- | src/Entities/Pickup.cpp | 23 |
1 files changed, 20 insertions, 3 deletions
diff --git a/src/Entities/Pickup.cpp b/src/Entities/Pickup.cpp index 88d961106..6cab79b91 100644 --- a/src/Entities/Pickup.cpp +++ b/src/Entities/Pickup.cpp @@ -41,12 +41,29 @@ public: cItem & Item = ((cPickup *)a_Entity)->GetItem(); if ((Distance < 1.2) && Item.IsEqual(m_Pickup->GetItem())) { - if ((Item.m_ItemCount + m_Pickup->GetItem().m_ItemCount) <= Item.GetMaxStackSize()) + char CombineCount = Item.m_ItemCount; + if ((CombineCount + m_Pickup->GetItem().m_ItemCount) > Item.GetMaxStackSize()) + { + CombineCount = Item.GetMaxStackSize() - m_Pickup->GetItem().m_ItemCount; + } + + if (CombineCount <= 0) + { + return false; + } + + m_Pickup->GetItem().AddCount(CombineCount); + Item.m_ItemCount -= CombineCount; + + if (Item.m_ItemCount <= 0) { - m_Pickup->GetItem().AddCount(Item.m_ItemCount); a_Entity->Destroy(); - m_FoundMatchingPickup = true; } + else + { + a_Entity->GetWorld()->BroadcastEntityMetadata(*a_Entity); + } + m_FoundMatchingPickup = true; } return false; } |