1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-06-27 16:36:03 +00:00

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>
This commit is contained in:
Lars Müller 2020-09-04 20:49:07 +02:00 committed by GitHub
parent 4ba5046308
commit 050964bed6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 209 additions and 138 deletions

View file

@ -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);