diff options
author | Lars Müller <34514239+appgurueu@users.noreply.github.com> | 2020-09-04 20:49:07 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-09-04 20:49:07 +0200 |
commit | 050964bed6005f8d816ddf362b9fc8675581d190 (patch) | |
tree | 3229276c2c989597da4a052aa67373c8b887accb /src/inventory.cpp | |
parent | 4ba5046308d6bdf7b38394770c6f82b6927393f2 (diff) | |
download | hax-minetest-server-050964bed6005f8d816ddf362b9fc8675581d190.tar.gz hax-minetest-server-050964bed6005f8d816ddf362b9fc8675581d190.zip |
Fix inventory swapping not calling all callbacks (#9923)
"Predicts" whether something will be swapped for allow callbacks, then calls callbacks a second time with swapped properties.
Co-authored-by: SmallJoker <SmallJoker@users.noreply.github.com>
Diffstat (limited to 'src/inventory.cpp')
-rw-r--r-- | src/inventory.cpp | 9 |
1 files changed, 4 insertions, 5 deletions
diff --git a/src/inventory.cpp b/src/inventory.cpp index 349ee503d..cf72cb005 100644 --- a/src/inventory.cpp +++ b/src/inventory.cpp @@ -732,17 +732,17 @@ void InventoryList::moveItemSomewhere(u32 i, InventoryList *dest, u32 count) u32 InventoryList::moveItem(u32 i, InventoryList *dest, u32 dest_i, u32 count, bool swap_if_needed, bool *did_swap) { - if(this == dest && i == dest_i) + if (this == dest && i == dest_i) return count; // Take item from source list ItemStack item1; - if(count == 0) + if (count == 0) item1 = changeItem(i, ItemStack()); else item1 = takeItem(i, count); - if(item1.empty()) + if (item1.empty()) return 0; // Try to add the item to destination list @@ -750,8 +750,7 @@ u32 InventoryList::moveItem(u32 i, InventoryList *dest, u32 dest_i, item1 = dest->addItem(dest_i, item1); // If something is returned, the item was not fully added - if(!item1.empty()) - { + if (!item1.empty()) { // If olditem is returned, nothing was added. bool nothing_added = (item1.count == oldcount); |