1
0
mirror of https://github.com/moparisthebest/minetest synced 2024-12-22 15:48:48 -05:00

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
This commit is contained in:
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,22 +379,29 @@ void IMoveAction::apply(InventoryManager *mgr, ServerActiveObject *player, IGame
list_to, to_i, count, !caused_by_move_somewhere);
// If source is infinite, reset it's stack
if(src_can_take_count == -1){
if (src_can_take_count == -1) {
// For the caused_by_move_somewhere == true case we didn't force-put the item,
// which guarantees there is no leftover, and code below would duplicate the
// (not replaced) to_stack_was item.
if (!caused_by_move_somewhere) {
// If destination stack is of different type and there are leftover
// items, attempt to put the leftover items to a different place in the
// destination inventory.
// The client-side GUI will try to guess if this happens.
if(from_stack_was.name != to_stack_was.name){
for(u32 i=0; i<list_to->getSize(); i++){
if(list_to->getItem(i).empty()){
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;
}
}
}
}
if (move_count > 0) {
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(dst_can_put_count == -1){
list_to->deleteItem(to_i);
@ -416,6 +423,13 @@ void IMoveAction::apply(InventoryManager *mgr, ServerActiveObject *player, IGame
<< " i=" << to_i
<< 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
*/