]> git.lizzy.rs Git - dragonfireclient.git/blobdiff - src/inventorymanager.cpp
Merge pull request #14 from corarona/master
[dragonfireclient.git] / src / inventorymanager.cpp
index 6b5a79fd94c58f834e4e6377b38419a5ef2a932e..b6f4649014ae6c4635e4d3878cb0f7771df3d72e 100644 (file)
@@ -29,7 +29,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include "util/strfnd.h"
 #include "util/basic_macros.h"
 
-#define PLAYER_TO_SA(p) p->getEnv()->getScriptIface()
+#define PLAYER_TO_SA(p)   p->getEnv()->getScriptIface()
 
 /*
        InventoryLocation
@@ -46,19 +46,19 @@ void InventoryLocation::serialize(std::ostream &os) const
 {
        switch (type) {
        case InventoryLocation::UNDEFINED:
-               os << "undefined";
+               os<<"undefined";
                break;
        case InventoryLocation::CURRENT_PLAYER:
-               os << "current_player";
+               os<<"current_player";
                break;
        case InventoryLocation::PLAYER:
-               os << "player:" << name;
+               os<<"player:"<<name;
                break;
        case InventoryLocation::NODEMETA:
-               os << "nodemeta:" << p.X << "," << p.Y << "," << p.Z;
+               os<<"nodemeta:"<<p.X<<","<<p.Y<<","<<p.Z;
                break;
        case InventoryLocation::DETACHED:
-               os << "detached:" << name;
+               os<<"detached:"<<name;
                break;
        default:
                FATAL_ERROR("Unhandled inventory location type");
@@ -88,8 +88,7 @@ void InventoryLocation::deSerialize(std::istream &is)
                type = InventoryLocation::DETACHED;
                std::getline(is, name, '\n');
        } else {
-               infostream << "Unknown InventoryLocation type=\"" << tname << "\""
-                          << std::endl;
+               infostream<<"Unknown InventoryLocation type=\""<<tname<<"\""<<std::endl;
                throw SerializationError("Unknown InventoryLocation type");
        }
 }
@@ -128,7 +127,8 @@ InventoryAction *InventoryAction::deSerialize(std::istream &is)
        IMoveAction
 */
 
-IMoveAction::IMoveAction(std::istream &is, bool somewhere) : move_somewhere(somewhere)
+IMoveAction::IMoveAction(std::istream &is, bool somewhere) :
+               move_somewhere(somewhere)
 {
        std::string ts;
 
@@ -154,23 +154,21 @@ IMoveAction::IMoveAction(std::istream &is, bool somewhere) : move_somewhere(some
        }
 }
 
-void IMoveAction::apply(
-               InventoryManager *mgr, ServerActiveObject *player, IGameDef *gamedef)
+void IMoveAction::apply(InventoryManager *mgr, ServerActiveObject *player, IGameDef *gamedef)
 {
        Inventory *inv_from = mgr->getInventory(from_inv);
        Inventory *inv_to = mgr->getInventory(to_inv);
 
        if (!inv_from) {
                infostream << "IMoveAction::apply(): FAIL: source inventory not found: "
-                          << "from_inv=\"" << from_inv.dump() << "\""
-                          << ", to_inv=\"" << to_inv.dump() << "\"" << std::endl;
+                       << "from_inv=\""<<from_inv.dump() << "\""
+                       << ", to_inv=\"" << to_inv.dump() << "\"" << std::endl;
                return;
        }
        if (!inv_to) {
-               infostream << "IMoveAction::apply(): FAIL: destination inventory not "
-                             "found: "
-                          << "from_inv=\"" << from_inv.dump() << "\""
-                          << ", to_inv=\"" << to_inv.dump() << "\"" << std::endl;
+               infostream << "IMoveAction::apply(): FAIL: destination inventory not found: "
+                       << "from_inv=\"" << from_inv.dump() << "\""
+                       << ", to_inv=\"" << to_inv.dump() << "\"" << std::endl;
                return;
        }
 
@@ -182,14 +180,14 @@ void IMoveAction::apply(
        */
        if (!list_from) {
                infostream << "IMoveAction::apply(): FAIL: source list not found: "
-                          << "from_inv=\"" << from_inv.dump() << "\""
-                          << ", from_list=\"" << from_list << "\"" << std::endl;
+                       << "from_inv=\"" << from_inv.dump() << "\""
+                       << ", from_list=\"" << from_list << "\"" << std::endl;
                return;
        }
        if (!list_to) {
                infostream << "IMoveAction::apply(): FAIL: destination list not found: "
-                          << "to_inv=\"" << to_inv.dump() << "\""
-                          << ", to_list=\"" << to_list << "\"" << std::endl;
+                       << "to_inv=\""<<to_inv.dump() << "\""
+                       << ", to_list=\"" << to_list << "\"" << std::endl;
                return;
        }
 
@@ -200,11 +198,14 @@ void IMoveAction::apply(
                move_somewhere = false;
 
                infostream << "IMoveAction::apply(): moving item somewhere"
-                          << " msom=" << move_somewhere << " count=" << count
-                          << " from inv=\"" << from_inv.dump() << "\""
-                          << " list=\"" << from_list << "\""
-                          << " i=" << from_i << " to inv=\"" << to_inv.dump() << "\""
-                          << " list=\"" << to_list << "\"" << std::endl;
+                       << " msom=" << move_somewhere
+                       << " count=" << count
+                       << " from inv=\"" << from_inv.dump() << "\""
+                       << " list=\"" << from_list << "\""
+                       << " i=" << from_i
+                       << " to inv=\"" << to_inv.dump() << "\""
+                       << " list=\"" << to_list << "\""
+                       << std::endl;
 
                // Try to add the item to destination list
                s16 dest_size = list_to->getSize();
@@ -234,17 +235,17 @@ void IMoveAction::apply(
        }
 
        if ((u16)to_i > list_to->getSize()) {
-               infostream << "IMoveAction::apply(): FAIL: destination index out of "
-                             "bounds: "
-                          << "to_i=" << to_i << ", size=" << list_to->getSize()
-                          << std::endl;
+               infostream << "IMoveAction::apply(): FAIL: destination index out of bounds: "
+                       << "to_i=" << to_i
+                       << ", size=" << list_to->getSize() << std::endl;
                return;
        }
        /*
                Do not handle rollback if both inventories are that of the same player
        */
-       bool ignore_rollback = (from_inv.type == InventoryLocation::PLAYER &&
-                               from_inv == to_inv);
+       bool ignore_rollback = (
+               from_inv.type == InventoryLocation::PLAYER &&
+               from_inv == to_inv);
 
        /*
                Collect information of endpoints
@@ -260,28 +261,25 @@ void IMoveAction::apply(
        /* Query detached inventories */
 
        // Move occurs in the same detached inventory
-       if (from_inv.type == InventoryLocation::DETACHED && from_inv == to_inv) {
+       if (from_inv.type == InventoryLocation::DETACHED &&
+                       from_inv == to_inv) {
                src_can_take_count = PLAYER_TO_SA(player)->detached_inventory_AllowMove(
-                               *this, try_take_count, player);
+                       *this, try_take_count, player);
                dst_can_put_count = src_can_take_count;
        } else {
                // Destination is detached
                if (to_inv.type == InventoryLocation::DETACHED) {
                        ItemStack src_item = list_from->getItem(from_i);
                        src_item.count = try_take_count;
-                       dst_can_put_count =
-                                       PLAYER_TO_SA(player)->detached_inventory_AllowPut(
-                                                       *this, src_item, player);
+                       dst_can_put_count = PLAYER_TO_SA(player)->detached_inventory_AllowPut(
+                               *this, src_item, player);
                }
                // Source is detached
                if (from_inv.type == InventoryLocation::DETACHED) {
                        ItemStack src_item = list_from->getItem(from_i);
                        src_item.count = try_take_count;
-                       src_can_take_count =
-                                       PLAYER_TO_SA(player)
-                                                       ->detached_inventory_AllowTake(
-                                                                       *this, src_item,
-                                                                       player);
+                       src_can_take_count = PLAYER_TO_SA(player)->detached_inventory_AllowTake(
+                               *this, src_item, player);
                }
        }
 
@@ -289,54 +287,50 @@ void IMoveAction::apply(
 
        // Both endpoints are nodemeta
        // Move occurs in the same nodemeta inventory
-       if (from_inv.type == InventoryLocation::NODEMETA && from_inv == to_inv) {
+       if (from_inv.type == InventoryLocation::NODEMETA &&
+                       from_inv == to_inv) {
                src_can_take_count = PLAYER_TO_SA(player)->nodemeta_inventory_AllowMove(
-                               *this, try_take_count, player);
+                       *this, try_take_count, player);
                dst_can_put_count = src_can_take_count;
        } else {
                // Destination is nodemeta
                if (to_inv.type == InventoryLocation::NODEMETA) {
                        ItemStack src_item = list_from->getItem(from_i);
                        src_item.count = try_take_count;
-                       dst_can_put_count =
-                                       PLAYER_TO_SA(player)->nodemeta_inventory_AllowPut(
-                                                       *this, src_item, player);
+                       dst_can_put_count = PLAYER_TO_SA(player)->nodemeta_inventory_AllowPut(
+                               *this, src_item, player);
                }
                // Source is nodemeta
                if (from_inv.type == InventoryLocation::NODEMETA) {
                        ItemStack src_item = list_from->getItem(from_i);
                        src_item.count = try_take_count;
-                       src_can_take_count =
-                                       PLAYER_TO_SA(player)
-                                                       ->nodemeta_inventory_AllowTake(
-                                                                       *this, src_item,
-                                                                       player);
+                       src_can_take_count = PLAYER_TO_SA(player)->nodemeta_inventory_AllowTake(
+                               *this, src_item, player);
                }
        }
 
        // Query player inventories
 
        // Move occurs in the same player inventory
-       if (from_inv.type == InventoryLocation::PLAYER && from_inv == to_inv) {
+       if (from_inv.type == InventoryLocation::PLAYER &&
+                       from_inv == to_inv) {
                src_can_take_count = PLAYER_TO_SA(player)->player_inventory_AllowMove(
-                               *this, try_take_count, player);
+                       *this, try_take_count, player);
                dst_can_put_count = src_can_take_count;
        } else {
                // Destination is a player
                if (to_inv.type == InventoryLocation::PLAYER) {
                        ItemStack src_item = list_from->getItem(from_i);
                        src_item.count = try_take_count;
-                       dst_can_put_count =
-                                       PLAYER_TO_SA(player)->player_inventory_AllowPut(
-                                                       *this, src_item, player);
+                       dst_can_put_count = PLAYER_TO_SA(player)->player_inventory_AllowPut(
+                               *this, src_item, player);
                }
                // Source is a player
                if (from_inv.type == InventoryLocation::PLAYER) {
                        ItemStack src_item = list_from->getItem(from_i);
                        src_item.count = try_take_count;
-                       src_can_take_count =
-                                       PLAYER_TO_SA(player)->player_inventory_AllowTake(
-                                                       *this, src_item, player);
+                       src_can_take_count = PLAYER_TO_SA(player)->player_inventory_AllowTake(
+                               *this, src_item, player);
                }
        }
 
@@ -361,13 +355,15 @@ void IMoveAction::apply(
                if (to_inv.type == InventoryLocation::PLAYER)
                        list_to->setModified();
 
-               infostream << "IMoveAction::apply(): move was completely disallowed:"
-                          << " count=" << old_count << " from inv=\"" << from_inv.dump()
-                          << "\""
-                          << " list=\"" << from_list << "\""
-                          << " i=" << from_i << " to inv=\"" << to_inv.dump() << "\""
-                          << " list=\"" << to_list << "\""
-                          << " i=" << to_i << std::endl;
+               infostream<<"IMoveAction::apply(): move was completely disallowed:"
+                               <<" count="<<old_count
+                               <<" from inv=\""<<from_inv.dump()<<"\""
+                               <<" list=\""<<from_list<<"\""
+                               <<" i="<<from_i
+                               <<" to inv=\""<<to_inv.dump()<<"\""
+                               <<" list=\""<<to_list<<"\""
+                               <<" i="<<to_i
+                               <<std::endl;
                return;
        }
 
@@ -383,19 +379,19 @@ void IMoveAction::apply(
                same as source), nothing happens
        */
        bool did_swap = false;
-       move_count = list_from->moveItem(from_i, list_to, to_i, count,
-                       !caused_by_move_somewhere, &did_swap);
+       move_count = list_from->moveItem(from_i,
+               list_to, to_i, count, !caused_by_move_somewhere, &did_swap);
 
        // If source is infinite, reset it's stack
        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.
+               // 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 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()) {
@@ -420,12 +416,16 @@ void IMoveAction::apply(
        }
 
        infostream << "IMoveAction::apply(): moved"
-                  << " msom=" << move_somewhere << " caused=" << caused_by_move_somewhere
-                  << " count=" << count << " from inv=\"" << from_inv.dump() << "\""
-                  << " list=\"" << from_list << "\""
-                  << " i=" << from_i << " to inv=\"" << to_inv.dump() << "\""
-                  << " list=\"" << to_list << "\""
-                  << " i=" << to_i << std::endl;
+                       << " msom=" << move_somewhere
+                       << " caused=" << caused_by_move_somewhere
+                       << " count=" << count
+                       << " from inv=\"" << from_inv.dump() << "\""
+                       << " list=\"" << from_list << "\""
+                       << " i=" << from_i
+                       << " to inv=\"" << to_inv.dump() << "\""
+                       << " list=\"" << to_list << "\""
+                       << " 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
@@ -448,8 +448,8 @@ void IMoveAction::apply(
                                from_inv.serialize(os);
                                loc = os.str();
                        }
-                       action.setModifyInventoryStack(
-                                       loc, from_list, from_i, false, src_item);
+                       action.setModifyInventoryStack(loc, from_list, from_i, false,
+                                       src_item);
                        rollback->reportAction(action);
                }
                // If destination is not infinite, record item put
@@ -461,8 +461,8 @@ void IMoveAction::apply(
                                to_inv.serialize(os);
                                loc = os.str();
                        }
-                       action.setModifyInventoryStack(
-                                       loc, to_list, to_i, true, src_item);
+                       action.setModifyInventoryStack(loc, to_list, to_i, true,
+                                       src_item);
                        rollback->reportAction(action);
                }
        }
@@ -474,54 +474,60 @@ void IMoveAction::apply(
        /* Detached inventories */
 
        // Both endpoints are same detached
-       if (from_inv.type == InventoryLocation::DETACHED && from_inv == to_inv) {
-               PLAYER_TO_SA(player)->detached_inventory_OnMove(*this, count, player);
+       if (from_inv.type == InventoryLocation::DETACHED &&
+                       from_inv == to_inv) {
+               PLAYER_TO_SA(player)->detached_inventory_OnMove(
+                               *this, count, player);
        } else {
                // Destination is detached
                if (to_inv.type == InventoryLocation::DETACHED) {
                        PLAYER_TO_SA(player)->detached_inventory_OnPut(
-                                       *this, src_item, player);
+                               *this, src_item, player);
                }
                // Source is detached
                if (from_inv.type == InventoryLocation::DETACHED) {
                        PLAYER_TO_SA(player)->detached_inventory_OnTake(
-                                       *this, src_item, player);
+                               *this, src_item, player);
                }
        }
 
        /* Node metadata inventories */
 
        // Both endpoints are same nodemeta
-       if (from_inv.type == InventoryLocation::NODEMETA && from_inv == to_inv) {
-               PLAYER_TO_SA(player)->nodemeta_inventory_OnMove(*this, count, player);
+       if (from_inv.type == InventoryLocation::NODEMETA &&
+                       from_inv == to_inv) {
+               PLAYER_TO_SA(player)->nodemeta_inventory_OnMove(
+                       *this, count, player);
        } else {
                // Destination is nodemeta
                if (to_inv.type == InventoryLocation::NODEMETA) {
                        PLAYER_TO_SA(player)->nodemeta_inventory_OnPut(
-                                       *this, src_item, player);
+                               *this, src_item, player);
                }
                // Source is nodemeta
                if (from_inv.type == InventoryLocation::NODEMETA) {
                        PLAYER_TO_SA(player)->nodemeta_inventory_OnTake(
-                                       *this, src_item, player);
+                               *this, src_item, player);
                }
        }
 
        // Player inventories
 
        // Both endpoints are same player inventory
-       if (from_inv.type == InventoryLocation::PLAYER && from_inv == to_inv) {
-               PLAYER_TO_SA(player)->player_inventory_OnMove(*this, count, player);
+       if (from_inv.type == InventoryLocation::PLAYER &&
+                       from_inv == to_inv) {
+               PLAYER_TO_SA(player)->player_inventory_OnMove(
+                       *this, count, player);
        } else {
                // Destination is player inventory
                if (to_inv.type == InventoryLocation::PLAYER) {
                        PLAYER_TO_SA(player)->player_inventory_OnPut(
-                                       *this, src_item, player);
+                               *this, src_item, player);
                }
                // Source is player inventory
                if (from_inv.type == InventoryLocation::PLAYER) {
                        PLAYER_TO_SA(player)->player_inventory_OnTake(
-                                       *this, src_item, player);
+                               *this, src_item, player);
                }
        }
 
@@ -581,14 +587,13 @@ IDropAction::IDropAction(std::istream &is)
        from_i = stoi(ts);
 }
 
-void IDropAction::apply(
-               InventoryManager *mgr, ServerActiveObject *player, IGameDef *gamedef)
+void IDropAction::apply(InventoryManager *mgr, ServerActiveObject *player, IGameDef *gamedef)
 {
        Inventory *inv_from = mgr->getInventory(from_inv);
 
        if (!inv_from) {
-               infostream << "IDropAction::apply(): FAIL: source inventory not found: "
-                          << "from_inv=\"" << from_inv.dump() << "\"" << std::endl;
+               infostream<<"IDropAction::apply(): FAIL: source inventory not found: "
+                               <<"from_inv=\""<<from_inv.dump()<<"\""<<std::endl;
                return;
        }
 
@@ -598,15 +603,15 @@ void IDropAction::apply(
                If a list doesn't exist or the source item doesn't exist
        */
        if (!list_from) {
-               infostream << "IDropAction::apply(): FAIL: source list not found: "
-                          << "from_inv=\"" << from_inv.dump() << "\"" << std::endl;
+               infostream<<"IDropAction::apply(): FAIL: source list not found: "
+                               <<"from_inv=\""<<from_inv.dump()<<"\""<<std::endl;
                return;
        }
        if (list_from->getItem(from_i).empty()) {
-               infostream << "IDropAction::apply(): FAIL: source item not found: "
-                          << "from_inv=\"" << from_inv.dump() << "\""
-                          << ", from_list=\"" << from_list << "\""
-                          << " from_i=" << from_i << std::endl;
+               infostream<<"IDropAction::apply(): FAIL: source item not found: "
+                               <<"from_inv=\""<<from_inv.dump()<<"\""
+                               <<", from_list=\""<<from_list<<"\""
+                               <<" from_i="<<from_i<<std::endl;
                return;
        }
 
@@ -631,15 +636,15 @@ void IDropAction::apply(
        switch (from_inv.type) {
        case InventoryLocation::DETACHED:
                src_can_take_count = PLAYER_TO_SA(player)->detached_inventory_AllowTake(
-                               *this, src_item, player);
+                       *this, src_item, player);
                break;
        case InventoryLocation::NODEMETA:
                src_can_take_count = PLAYER_TO_SA(player)->nodemeta_inventory_AllowTake(
-                               *this, src_item, player);
+                       *this, src_item, player);
                break;
        case InventoryLocation::PLAYER:
                src_can_take_count = PLAYER_TO_SA(player)->player_inventory_AllowTake(
-                               *this, src_item, player);
+                       *this, src_item, player);
                break;
        default:
                break;
@@ -654,11 +659,12 @@ void IDropAction::apply(
        // Drop the item
        ItemStack item1 = list_from->getItem(from_i);
        item1.count = take_count;
-       if (PLAYER_TO_SA(player)->item_OnDrop(item1, player, player->getBasePosition())) {
+       if(PLAYER_TO_SA(player)->item_OnDrop(item1, player,
+                               player->getBasePosition())) {
                int actually_dropped_count = take_count - item1.count;
 
                if (actually_dropped_count == 0) {
-                       infostream << "Actually dropped no items" << std::endl;
+                       infostream<<"Actually dropped no items"<<std::endl;
 
                        // Revert client prediction. See 'clientApply'
                        if (from_inv.type == InventoryLocation::PLAYER)
@@ -669,22 +675,22 @@ void IDropAction::apply(
                // If source isn't infinite
                if (src_can_take_count != -1) {
                        // Take item from source list
-                       ItemStack item2 = list_from->takeItem(
-                                       from_i, actually_dropped_count);
+                       ItemStack item2 = list_from->takeItem(from_i, actually_dropped_count);
 
                        if (item2.count != actually_dropped_count)
-                               errorstream << "Could not take dropped count of items"
-                                           << std::endl;
+                               errorstream<<"Could not take dropped count of items"<<std::endl;
                }
 
                src_item.count = actually_dropped_count;
                mgr->setInventoryModified(from_inv);
        }
 
-       infostream << "IDropAction::apply(): dropped "
-                  << " from inv=\"" << from_inv.dump() << "\""
-                  << " list=\"" << from_list << "\""
-                  << " i=" << from_i << std::endl;
+       infostream<<"IDropAction::apply(): dropped "
+                       <<" from inv=\""<<from_inv.dump()<<"\""
+                       <<" list=\""<<from_list<<"\""
+                       <<" i="<<from_i
+                       <<std::endl;
+
 
        /*
                Report drop to endpoints
@@ -692,13 +698,16 @@ void IDropAction::apply(
 
        switch (from_inv.type) {
        case InventoryLocation::DETACHED:
-               PLAYER_TO_SA(player)->detached_inventory_OnTake(*this, src_item, player);
+               PLAYER_TO_SA(player)->detached_inventory_OnTake(
+                       *this, src_item, player);
                break;
        case InventoryLocation::NODEMETA:
-               PLAYER_TO_SA(player)->nodemeta_inventory_OnTake(*this, src_item, player);
+               PLAYER_TO_SA(player)->nodemeta_inventory_OnTake(
+                       *this, src_item, player);
                break;
        case InventoryLocation::PLAYER:
-               PLAYER_TO_SA(player)->player_inventory_OnTake(*this, src_item, player);
+               PLAYER_TO_SA(player)->player_inventory_OnTake(
+                       *this, src_item, player);
                break;
        default:
                break;
@@ -719,8 +728,8 @@ void IDropAction::apply(
                                from_inv.serialize(os);
                                loc = os.str();
                        }
-                       action.setModifyInventoryStack(
-                                       loc, from_list, from_i, false, src_item);
+                       action.setModifyInventoryStack(loc, from_list, from_i,
+                                       false, src_item);
                        rollback->reportAction(action);
                }
        }
@@ -768,14 +777,14 @@ ICraftAction::ICraftAction(std::istream &is)
        craft_inv.deSerialize(ts);
 }
 
-void ICraftAction::apply(
-               InventoryManager *mgr, ServerActiveObject *player, IGameDef *gamedef)
+void ICraftAction::apply(InventoryManager *mgr,
+       ServerActiveObject *player, IGameDef *gamedef)
 {
        Inventory *inv_craft = mgr->getInventory(craft_inv);
 
        if (!inv_craft) {
                infostream << "ICraftAction::apply(): FAIL: inventory not found: "
-                          << "craft_inv=\"" << craft_inv.dump() << "\"" << std::endl;
+                               << "craft_inv=\"" << craft_inv.dump() << "\"" << std::endl;
                return;
        }
 
@@ -788,17 +797,17 @@ void ICraftAction::apply(
        */
        if (!list_craft) {
                infostream << "ICraftAction::apply(): FAIL: craft list not found: "
-                          << "craft_inv=\"" << craft_inv.dump() << "\"" << std::endl;
+                               << "craft_inv=\"" << craft_inv.dump() << "\"" << std::endl;
                return;
        }
        if (!list_craftresult) {
                infostream << "ICraftAction::apply(): FAIL: craftresult list not found: "
-                          << "craft_inv=\"" << craft_inv.dump() << "\"" << std::endl;
+                               << "craft_inv=\"" << craft_inv.dump() << "\"" << std::endl;
                return;
        }
        if (list_craftresult->getSize() < 1) {
                infostream << "ICraftAction::apply(): FAIL: craftresult list too short: "
-                          << "craft_inv=\"" << craft_inv.dump() << "\"" << std::endl;
+                               << "craft_inv=\"" << craft_inv.dump() << "\"" << std::endl;
                return;
        }
 
@@ -816,8 +825,7 @@ void ICraftAction::apply(
                std::vector<ItemStack> temp;
                // Decrement input and add crafting output
                getCraftingResult(inv_craft, crafted, temp, true, gamedef);
-               PLAYER_TO_SA(player)->item_OnCraft(
-                               crafted, player, &saved_craft_list, craft_inv);
+               PLAYER_TO_SA(player)->item_OnCraft(crafted, player, &saved_craft_list, craft_inv);
                list_craftresult->addItem(0, crafted);
                mgr->setInventoryModified(craft_inv);
 
@@ -826,8 +834,7 @@ void ICraftAction::apply(
                for (auto &itemstack : temp) {
                        for (auto &output_replacement : output_replacements) {
                                if (itemstack.name == output_replacement.name) {
-                                       itemstack = output_replacement.addItem(
-                                                       itemstack, itemdef);
+                                       itemstack = output_replacement.addItem(itemstack, itemdef);
                                        if (itemstack.empty())
                                                continue;
                                }
@@ -835,8 +842,10 @@ void ICraftAction::apply(
                        output_replacements.push_back(itemstack);
                }
 
-               actionstream << player->getDescription() << " crafts "
-                            << crafted.getItemString() << std::endl;
+               actionstream << player->getDescription()
+                               << " crafts "
+                               << crafted.getItemString()
+                               << std::endl;
 
                // Decrement counter
                if (count_remaining == 1)
@@ -847,8 +856,7 @@ void ICraftAction::apply(
 
                // Get next crafting result
                getCraftingResult(inv_craft, crafted, temp, false, gamedef);
-               PLAYER_TO_SA(player)->item_CraftPredict(
-                               crafted, player, list_craft, craft_inv);
+               PLAYER_TO_SA(player)->item_CraftPredict(crafted, player, list_craft, craft_inv);
                found = !crafted.empty();
        }
 
@@ -862,21 +870,20 @@ void ICraftAction::apply(
                u16 count = output_replacement.count;
                do {
                        PLAYER_TO_SA(player)->item_OnDrop(output_replacement, player,
-                                       player->getBasePosition());
+                               player->getBasePosition());
                        if (count >= output_replacement.count) {
-                               errorstream << "Couldn't drop replacement stack "
-                                           << output_replacement.getItemString()
-                                           << " because drop loop didn't "
-                                              "decrease count."
-                                           << std::endl;
+                               errorstream << "Couldn't drop replacement stack " <<
+                                       output_replacement.getItemString() << " because drop loop didn't "
+                                       "decrease count." << std::endl;
 
                                break;
                        }
                } while (!output_replacement.empty());
        }
 
-       infostream << "ICraftAction::apply(): crafted "
-                  << " craft_inv=\"" << craft_inv.dump() << "\"" << std::endl;
+       infostream<<"ICraftAction::apply(): crafted "
+                       <<" craft_inv=\""<<craft_inv.dump()<<"\""
+                       <<std::endl;
 }
 
 void ICraftAction::clientApply(InventoryManager *mgr, IGameDef *gamedef)
@@ -885,10 +892,11 @@ void ICraftAction::clientApply(InventoryManager *mgr, IGameDef *gamedef)
        // to make lag less apparent.
 }
 
+
 // Crafting helper
 bool getCraftingResult(Inventory *inv, ItemStack &result,
-               std::vector<ItemStack> &output_replacements, bool decrementInput,
-               IGameDef *gamedef)
+               std::vector<ItemStack> &output_replacements,
+               bool decrementInput, IGameDef *gamedef)
 {
        result.clear();
 
@@ -901,7 +909,7 @@ bool getCraftingResult(Inventory *inv, ItemStack &result,
        CraftInput ci;
        ci.method = CRAFT_METHOD_NORMAL;
        ci.width = clist->getWidth() ? clist->getWidth() : 3;
-       for (u16 i = 0; i < clist->getSize(); i++)
+       for (u16 i=0; i < clist->getSize(); i++)
                ci.items.push_back(clist->getItem(i));
 
        // Find out what is crafted and add it to result item slot
@@ -913,10 +921,11 @@ bool getCraftingResult(Inventory *inv, ItemStack &result,
 
        if (found && decrementInput) {
                // CraftInput has been changed, apply changes in clist
-               for (u16 i = 0; i < clist->getSize(); i++) {
+               for (u16 i=0; i < clist->getSize(); i++) {
                        clist->changeItem(i, ci.items[i]);
                }
        }
 
        return found;
 }
+