MoveItemSomewhere double bugfix

-> Fix bug where MoveSomewhere from an infinite source would fill the destination inventory with copies of itself.
-> Fix bug where MoveSomewhere would needlessly call callbacks.
-> Remove trailing whitespaces
master
est31 2015-07-19 02:27:12 +02:00
parent 4046f3e302
commit 7bbb9b066a
2 changed files with 47 additions and 33 deletions

View File

@ -379,21 +379,28 @@ void IMoveAction::apply(InventoryManager *mgr, ServerActiveObject *player, IGame
list_to, to_i, count, !caused_by_move_somewhere); list_to, to_i, count, !caused_by_move_somewhere);
// If source is infinite, reset it's stack // If source is infinite, reset it's stack
if(src_can_take_count == -1){ if (src_can_take_count == -1) {
// If destination stack is of different type and there are leftover // For the caused_by_move_somewhere == true case we didn't force-put the item,
// items, attempt to put the leftover items to a different place in the // which guarantees there is no leftover, and code below would duplicate the
// destination inventory. // (not replaced) to_stack_was item.
// The client-side GUI will try to guess if this happens. if (!caused_by_move_somewhere) {
if(from_stack_was.name != to_stack_was.name){ // If destination stack is of different type and there are leftover
for(u32 i=0; i<list_to->getSize(); i++){ // items, attempt to put the leftover items to a different place in the
if(list_to->getItem(i).empty()){ // destination inventory.
list_to->changeItem(i, to_stack_was); // The client-side GUI will try to guess if this happens.
break; if (from_stack_was.name != to_stack_was.name) {
for (u32 i = 0; i < list_to->getSize(); i++) {
if (list_to->getItem(i).empty()) {
list_to->changeItem(i, to_stack_was);
break;
}
} }
} }
} }
list_from->deleteItem(from_i); if (move_count > 0) {
list_from->addItem(from_i, from_stack_was); list_from->deleteItem(from_i);
list_from->addItem(from_i, from_stack_was);
}
} }
// If destination is infinite, reset it's stack and take count from source // If destination is infinite, reset it's stack and take count from source
if(dst_can_put_count == -1){ if(dst_can_put_count == -1){
@ -416,6 +423,13 @@ void IMoveAction::apply(InventoryManager *mgr, ServerActiveObject *player, IGame
<< " i=" << to_i << " i=" << to_i
<< std::endl; << std::endl;
// If we are inside the move somewhere loop, we don't need to report
// anything if nothing happened (perhaps we don't need to report
// anything for caused_by_move_somewhere == true, but this way its safer)
if (caused_by_move_somewhere && move_count == 0) {
return;
}
/* /*
Record rollback information Record rollback information
*/ */