Formspec: make bgcolor element less confusing and allow setting fullscreen color...
[oweals/minetest.git] / src / inventorymanager.cpp
index 02cb9e3a4ae45accd5178c4a33add8df38012cb0..5a24f95a448fb6fbafc273e183acaeb7fd4cb81f 100644 (file)
@@ -348,6 +348,13 @@ void IMoveAction::apply(InventoryManager *mgr, ServerActiveObject *player, IGame
 
        /* If no items will be moved, don't go further */
        if (count == 0) {
+               // Undo client prediction. See 'clientApply'
+               if (from_inv.type == InventoryLocation::PLAYER)
+                       list_from->setModified();
+
+               if (to_inv.type == InventoryLocation::PLAYER)
+                       list_to->setModified();
+
                infostream<<"IMoveAction::apply(): move was completely disallowed:"
                                <<" count="<<old_count
                                <<" from inv=\""<<from_inv.dump()<<"\""
@@ -646,8 +653,6 @@ void IDropAction::apply(InventoryManager *mgr, ServerActiveObject *player, IGame
        if (src_can_take_count != -1 && src_can_take_count < take_count)
                take_count = src_can_take_count;
 
-       int actually_dropped_count = 0;
-
        // Update item due executed callbacks
        src_item = list_from->getItem(from_i);
 
@@ -656,10 +661,14 @@ void IDropAction::apply(InventoryManager *mgr, ServerActiveObject *player, IGame
        item1.count = take_count;
        if(PLAYER_TO_SA(player)->item_OnDrop(item1, player,
                                player->getBasePosition())) {
-               actually_dropped_count = take_count - item1.count;
+               int actually_dropped_count = take_count - item1.count;
 
                if (actually_dropped_count == 0) {
                        infostream<<"Actually dropped no items"<<std::endl;
+
+                       // Revert client prediction. See 'clientApply'
+                       if (from_inv.type == InventoryLocation::PLAYER)
+                               list_from->setModified();
                        return;
                }
 
@@ -670,9 +679,10 @@ void IDropAction::apply(InventoryManager *mgr, ServerActiveObject *player, IGame
 
                        if (item2.count != actually_dropped_count)
                                errorstream<<"Could not take dropped count of items"<<std::endl;
-
-                       mgr->setInventoryModified(from_inv);
                }
+
+               src_item.count = actually_dropped_count;
+               mgr->setInventoryModified(from_inv);
        }
 
        infostream<<"IDropAction::apply(): dropped "
@@ -681,7 +691,6 @@ void IDropAction::apply(InventoryManager *mgr, ServerActiveObject *player, IGame
                        <<" i="<<from_i
                        <<std::endl;
 
-       src_item.count = actually_dropped_count;
 
        /*
                Report drop to endpoints
@@ -852,7 +861,7 @@ void ICraftAction::apply(InventoryManager *mgr,
        }
 
        // Put the replacements in the inventory or drop them on the floor, if
-       // the invenotry is full
+       // the inventory is full
        for (auto &output_replacement : output_replacements) {
                if (list_main)
                        output_replacement = list_main->addItem(output_replacement);