diff options
author | sfan5 <sfan5@live.de> | 2019-09-03 16:36:46 +0200 |
---|---|---|
committer | sfan5 <sfan5@live.de> | 2019-09-03 20:16:36 +0200 |
commit | 45826911048388c8b744961bb9e8de1549559d0a (patch) | |
tree | eff20c990192787130d7b076bd7b757b02be8f13 /src | |
parent | f3acdd3914c977f0c9129a8691287a87d822ee0f (diff) | |
download | minetest-45826911048388c8b744961bb9e8de1549559d0a.tar.gz minetest-45826911048388c8b744961bb9e8de1549559d0a.tar.bz2 minetest-45826911048388c8b744961bb9e8de1549559d0a.zip |
Fix Inventory::moveItemSomewhere()
Diffstat (limited to 'src')
-rw-r--r-- | src/inventory.cpp | 24 |
1 files changed, 5 insertions, 19 deletions
diff --git a/src/inventory.cpp b/src/inventory.cpp index 2a7c32a44..26e6eaa73 100644 --- a/src/inventory.cpp +++ b/src/inventory.cpp @@ -717,27 +717,13 @@ void InventoryList::moveItemSomewhere(u32 i, InventoryList *dest, u32 count) if (item1.empty()) return; - // Try to add the item to destination list - u32 dest_size = dest->getSize(); - // First try all the non-empty slots - for (u32 dest_i = 0; dest_i < dest_size; dest_i++) { - if (!m_items[dest_i].empty()) { - item1 = dest->addItem(dest_i, item1); - if (item1.empty()) return; - } - } + ItemStack leftover; + leftover = dest->addItem(item1); - // Then try all the empty ones - for (u32 dest_i = 0; dest_i < dest_size; dest_i++) { - if (m_items[dest_i].empty()) { - item1 = dest->addItem(dest_i, item1); - if (item1.empty()) return; - } + if (!leftover.empty()) { + // Add the remaining part back to the source item + addItem(i, leftover); } - - // If we reach this, the item was not fully added - // Add the remaining part back to the source item - addItem(i, item1); } u32 InventoryList::moveItem(u32 i, InventoryList *dest, u32 dest_i, |