3 Copyright (C) 2010-2013 celeron55, Perttu Ahola <celeron55@gmail.com>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as published by
7 the Free Software Foundation; either version 2.1 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public License along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 #include "inventorymanager.h"
22 #include "environment.h"
23 #include "scripting_game.h"
24 #include "serverobject.h"
27 #include "rollback_interface.h"
30 #define PP(x) "("<<(x).X<<","<<(x).Y<<","<<(x).Z<<")"
32 #define PLAYER_TO_SA(p) p->getEnv()->getScriptIface()
38 std::string InventoryLocation::dump() const
40 std::ostringstream os(std::ios::binary);
45 void InventoryLocation::serialize(std::ostream &os) const
48 case InventoryLocation::UNDEFINED:
51 case InventoryLocation::CURRENT_PLAYER:
54 case InventoryLocation::PLAYER:
57 case InventoryLocation::NODEMETA:
58 os<<"nodemeta:"<<p.X<<","<<p.Y<<","<<p.Z;
60 case InventoryLocation::DETACHED:
61 os<<"detached:"<<name;
64 FATAL_ERROR("Unhandled inventory location type");
68 void InventoryLocation::deSerialize(std::istream &is)
71 std::getline(is, tname, ':');
72 if(tname == "undefined")
74 type = InventoryLocation::UNDEFINED;
76 else if(tname == "current_player")
78 type = InventoryLocation::CURRENT_PLAYER;
80 else if(tname == "player")
82 type = InventoryLocation::PLAYER;
83 std::getline(is, name, '\n');
85 else if(tname == "nodemeta")
87 type = InventoryLocation::NODEMETA;
89 std::getline(is, pos, '\n');
91 p.X = stoi(fn.next(","));
92 p.Y = stoi(fn.next(","));
93 p.Z = stoi(fn.next(","));
95 else if(tname == "detached")
97 type = InventoryLocation::DETACHED;
98 std::getline(is, name, '\n');
102 infostream<<"Unknown InventoryLocation type=\""<<tname<<"\""<<std::endl;
103 throw SerializationError("Unknown InventoryLocation type");
107 void InventoryLocation::deSerialize(std::string s)
109 std::istringstream is(s, std::ios::binary);
117 InventoryAction * InventoryAction::deSerialize(std::istream &is)
120 std::getline(is, type, ' ');
122 InventoryAction *a = NULL;
124 if (type == "Move") {
125 a = new IMoveAction(is, false);
126 } else if (type == "MoveSomewhere") {
127 a = new IMoveAction(is, true);
128 } else if (type == "Drop") {
129 a = new IDropAction(is);
130 } else if(type == "Craft") {
131 a = new ICraftAction(is);
141 IMoveAction::IMoveAction(std::istream &is, bool somewhere)
144 move_somewhere = somewhere;
145 caused_by_move_somewhere = false;
148 std::getline(is, ts, ' ');
151 std::getline(is, ts, ' ');
152 from_inv.deSerialize(ts);
154 std::getline(is, from_list, ' ');
156 std::getline(is, ts, ' ');
159 std::getline(is, ts, ' ');
160 to_inv.deSerialize(ts);
162 std::getline(is, to_list, ' ');
165 std::getline(is, ts, ' ');
170 void IMoveAction::apply(InventoryManager *mgr, ServerActiveObject *player, IGameDef *gamedef)
172 Inventory *inv_from = mgr->getInventory(from_inv);
173 Inventory *inv_to = mgr->getInventory(to_inv);
176 infostream << "IMoveAction::apply(): FAIL: source inventory not found: "
177 << "from_inv=\""<<from_inv.dump() << "\""
178 << ", to_inv=\"" << to_inv.dump() << "\"" << std::endl;
182 infostream << "IMoveAction::apply(): FAIL: destination inventory not found: "
183 << "from_inv=\"" << from_inv.dump() << "\""
184 << ", to_inv=\"" << to_inv.dump() << "\"" << std::endl;
188 InventoryList *list_from = inv_from->getList(from_list);
189 InventoryList *list_to = inv_to->getList(to_list);
192 If a list doesn't exist or the source item doesn't exist
195 infostream << "IMoveAction::apply(): FAIL: source list not found: "
196 << "from_inv=\"" << from_inv.dump() << "\""
197 << ", from_list=\"" << from_list << "\"" << std::endl;
201 infostream << "IMoveAction::apply(): FAIL: destination list not found: "
202 << "to_inv=\""<<to_inv.dump() << "\""
203 << ", to_list=\"" << to_list << "\"" << std::endl;
207 if (move_somewhere) {
209 u16 old_count = count;
210 caused_by_move_somewhere = true;
211 move_somewhere = false;
213 infostream << "IMoveAction::apply(): moving item somewhere"
214 << " msom=" << move_somewhere
215 << " count=" << count
216 << " from inv=\"" << from_inv.dump() << "\""
217 << " list=\"" << from_list << "\""
219 << " to inv=\"" << to_inv.dump() << "\""
220 << " list=\"" << to_list << "\""
223 // Try to add the item to destination list
224 s16 dest_size = list_to->getSize();
225 // First try all the non-empty slots
226 for (s16 dest_i = 0; dest_i < dest_size && count > 0; dest_i++) {
227 if (!list_to->getItem(dest_i).empty()) {
229 apply(mgr, player, gamedef);
234 // Then try all the empty ones
235 for (s16 dest_i = 0; dest_i < dest_size && count > 0; dest_i++) {
236 if (list_to->getItem(dest_i).empty()) {
238 apply(mgr, player, gamedef);
245 caused_by_move_somewhere = false;
246 move_somewhere = true;
250 if ((u16)to_i > list_to->getSize()) {
251 infostream << "IMoveAction::apply(): FAIL: destination index out of bounds: "
253 << ", size=" << list_to->getSize() << std::endl;
257 Do not handle rollback if both inventories are that of the same player
259 bool ignore_rollback = (
260 from_inv.type == InventoryLocation::PLAYER &&
261 to_inv.type == InventoryLocation::PLAYER &&
262 from_inv.name == to_inv.name);
265 Collect information of endpoints
268 int try_take_count = count;
269 if(try_take_count == 0)
270 try_take_count = list_from->getItem(from_i).count;
272 int src_can_take_count = 0xffff;
273 int dst_can_put_count = 0xffff;
275 /* Query detached inventories */
277 // Move occurs in the same detached inventory
278 if(from_inv.type == InventoryLocation::DETACHED &&
279 to_inv.type == InventoryLocation::DETACHED &&
280 from_inv.name == to_inv.name)
282 src_can_take_count = PLAYER_TO_SA(player)->detached_inventory_AllowMove(
283 from_inv.name, from_list, from_i,
284 to_list, to_i, try_take_count, player);
285 dst_can_put_count = src_can_take_count;
289 // Destination is detached
290 if(to_inv.type == InventoryLocation::DETACHED)
292 ItemStack src_item = list_from->getItem(from_i);
293 src_item.count = try_take_count;
294 dst_can_put_count = PLAYER_TO_SA(player)->detached_inventory_AllowPut(
295 to_inv.name, to_list, to_i, src_item, player);
297 // Source is detached
298 if(from_inv.type == InventoryLocation::DETACHED)
300 ItemStack src_item = list_from->getItem(from_i);
301 src_item.count = try_take_count;
302 src_can_take_count = PLAYER_TO_SA(player)->detached_inventory_AllowTake(
303 from_inv.name, from_list, from_i, src_item, player);
307 /* Query node metadata inventories */
309 // Both endpoints are nodemeta
310 // Move occurs in the same nodemeta inventory
311 if(from_inv.type == InventoryLocation::NODEMETA &&
312 to_inv.type == InventoryLocation::NODEMETA &&
313 from_inv.p == to_inv.p)
315 src_can_take_count = PLAYER_TO_SA(player)->nodemeta_inventory_AllowMove(
316 from_inv.p, from_list, from_i,
317 to_list, to_i, try_take_count, player);
318 dst_can_put_count = src_can_take_count;
322 // Destination is nodemeta
323 if(to_inv.type == InventoryLocation::NODEMETA)
325 ItemStack src_item = list_from->getItem(from_i);
326 src_item.count = try_take_count;
327 dst_can_put_count = PLAYER_TO_SA(player)->nodemeta_inventory_AllowPut(
328 to_inv.p, to_list, to_i, src_item, player);
330 // Source is nodemeta
331 if(from_inv.type == InventoryLocation::NODEMETA)
333 ItemStack src_item = list_from->getItem(from_i);
334 src_item.count = try_take_count;
335 src_can_take_count = PLAYER_TO_SA(player)->nodemeta_inventory_AllowTake(
336 from_inv.p, from_list, from_i, src_item, player);
340 int old_count = count;
342 /* Modify count according to collected data */
343 count = try_take_count;
344 if(src_can_take_count != -1 && count > src_can_take_count)
345 count = src_can_take_count;
346 if(dst_can_put_count != -1 && count > dst_can_put_count)
347 count = dst_can_put_count;
348 /* Limit according to source item count */
349 if(count > list_from->getItem(from_i).count)
350 count = list_from->getItem(from_i).count;
352 /* If no items will be moved, don't go further */
355 infostream<<"IMoveAction::apply(): move was completely disallowed:"
356 <<" count="<<old_count
357 <<" from inv=\""<<from_inv.dump()<<"\""
358 <<" list=\""<<from_list<<"\""
360 <<" to inv=\""<<to_inv.dump()<<"\""
361 <<" list=\""<<to_list<<"\""
367 ItemStack src_item = list_from->getItem(from_i);
368 src_item.count = count;
369 ItemStack from_stack_was = list_from->getItem(from_i);
370 ItemStack to_stack_was = list_to->getItem(to_i);
375 If something is wrong (source item is empty, destination is the
376 same as source), nothing happens
378 bool did_swap = false;
379 move_count = list_from->moveItem(from_i,
380 list_to, to_i, count, !caused_by_move_somewhere, &did_swap);
382 // If source is infinite, reset it's stack
383 if (src_can_take_count == -1) {
384 // For the caused_by_move_somewhere == true case we didn't force-put the item,
385 // which guarantees there is no leftover, and code below would duplicate the
386 // (not replaced) to_stack_was item.
387 if (!caused_by_move_somewhere) {
388 // If destination stack is of different type and there are leftover
389 // items, attempt to put the leftover items to a different place in the
390 // destination inventory.
391 // The client-side GUI will try to guess if this happens.
392 if (from_stack_was.name != to_stack_was.name) {
393 for (u32 i = 0; i < list_to->getSize(); i++) {
394 if (list_to->getItem(i).empty()) {
395 list_to->changeItem(i, to_stack_was);
401 if (move_count > 0 || did_swap) {
402 list_from->deleteItem(from_i);
403 list_from->addItem(from_i, from_stack_was);
406 // If destination is infinite, reset it's stack and take count from source
407 if(dst_can_put_count == -1){
408 list_to->deleteItem(to_i);
409 list_to->addItem(to_i, to_stack_was);
410 list_from->deleteItem(from_i);
411 list_from->addItem(from_i, from_stack_was);
412 list_from->takeItem(from_i, count);
415 infostream << "IMoveAction::apply(): moved"
416 << " msom=" << move_somewhere
417 << " caused=" << caused_by_move_somewhere
418 << " count=" << count
419 << " from inv=\"" << from_inv.dump() << "\""
420 << " list=\"" << from_list << "\""
422 << " to inv=\"" << to_inv.dump() << "\""
423 << " list=\"" << to_list << "\""
427 // If we are inside the move somewhere loop, we don't need to report
428 // anything if nothing happened (perhaps we don't need to report
429 // anything for caused_by_move_somewhere == true, but this way its safer)
430 if (caused_by_move_somewhere && move_count == 0) {
435 Record rollback information
437 if(!ignore_rollback && gamedef->rollback())
439 IRollbackManager *rollback = gamedef->rollback();
441 // If source is not infinite, record item take
442 if(src_can_take_count != -1){
443 RollbackAction action;
446 std::ostringstream os(std::ios::binary);
447 from_inv.serialize(os);
450 action.setModifyInventoryStack(loc, from_list, from_i, false,
452 rollback->reportAction(action);
454 // If destination is not infinite, record item put
455 if(dst_can_put_count != -1){
456 RollbackAction action;
459 std::ostringstream os(std::ios::binary);
460 to_inv.serialize(os);
463 action.setModifyInventoryStack(loc, to_list, to_i, true,
465 rollback->reportAction(action);
470 Report move to endpoints
473 /* Detached inventories */
475 // Both endpoints are same detached
476 if(from_inv.type == InventoryLocation::DETACHED &&
477 to_inv.type == InventoryLocation::DETACHED &&
478 from_inv.name == to_inv.name)
480 PLAYER_TO_SA(player)->detached_inventory_OnMove(
481 from_inv.name, from_list, from_i,
482 to_list, to_i, count, player);
486 // Destination is detached
487 if(to_inv.type == InventoryLocation::DETACHED)
489 PLAYER_TO_SA(player)->detached_inventory_OnPut(
490 to_inv.name, to_list, to_i, src_item, player);
492 // Source is detached
493 if(from_inv.type == InventoryLocation::DETACHED)
495 PLAYER_TO_SA(player)->detached_inventory_OnTake(
496 from_inv.name, from_list, from_i, src_item, player);
500 /* Node metadata inventories */
502 // Both endpoints are same nodemeta
503 if(from_inv.type == InventoryLocation::NODEMETA &&
504 to_inv.type == InventoryLocation::NODEMETA &&
505 from_inv.p == to_inv.p)
507 PLAYER_TO_SA(player)->nodemeta_inventory_OnMove(
508 from_inv.p, from_list, from_i,
509 to_list, to_i, count, player);
512 // Destination is nodemeta
513 if(to_inv.type == InventoryLocation::NODEMETA)
515 PLAYER_TO_SA(player)->nodemeta_inventory_OnPut(
516 to_inv.p, to_list, to_i, src_item, player);
518 // Source is nodemeta
519 else if(from_inv.type == InventoryLocation::NODEMETA)
521 PLAYER_TO_SA(player)->nodemeta_inventory_OnTake(
522 from_inv.p, from_list, from_i, src_item, player);
526 mgr->setInventoryModified(from_inv, false);
527 if(inv_from != inv_to)
528 mgr->setInventoryModified(to_inv, false);
531 void IMoveAction::clientApply(InventoryManager *mgr, IGameDef *gamedef)
533 // Optional InventoryAction operation that is run on the client
534 // to make lag less apparent.
536 Inventory *inv_from = mgr->getInventory(from_inv);
537 Inventory *inv_to = mgr->getInventory(to_inv);
538 if(!inv_from || !inv_to)
541 InventoryLocation current_player;
542 current_player.setCurrentPlayer();
543 Inventory *inv_player = mgr->getInventory(current_player);
544 if(inv_from != inv_player || inv_to != inv_player)
547 InventoryList *list_from = inv_from->getList(from_list);
548 InventoryList *list_to = inv_to->getList(to_list);
549 if(!list_from || !list_to)
553 list_from->moveItem(from_i, list_to, to_i, count);
555 list_from->moveItemSomewhere(from_i, list_to, count);
557 mgr->setInventoryModified(from_inv);
558 if(inv_from != inv_to)
559 mgr->setInventoryModified(to_inv);
566 IDropAction::IDropAction(std::istream &is)
570 std::getline(is, ts, ' ');
573 std::getline(is, ts, ' ');
574 from_inv.deSerialize(ts);
576 std::getline(is, from_list, ' ');
578 std::getline(is, ts, ' ');
582 void IDropAction::apply(InventoryManager *mgr, ServerActiveObject *player, IGameDef *gamedef)
584 Inventory *inv_from = mgr->getInventory(from_inv);
587 infostream<<"IDropAction::apply(): FAIL: source inventory not found: "
588 <<"from_inv=\""<<from_inv.dump()<<"\""<<std::endl;
592 InventoryList *list_from = inv_from->getList(from_list);
595 If a list doesn't exist or the source item doesn't exist
598 infostream<<"IDropAction::apply(): FAIL: source list not found: "
599 <<"from_inv=\""<<from_inv.dump()<<"\""<<std::endl;
602 if(list_from->getItem(from_i).empty())
604 infostream<<"IDropAction::apply(): FAIL: source item not found: "
605 <<"from_inv=\""<<from_inv.dump()<<"\""
606 <<", from_list=\""<<from_list<<"\""
607 <<" from_i="<<from_i<<std::endl;
612 Do not handle rollback if inventory is player's
614 bool ignore_src_rollback = (from_inv.type == InventoryLocation::PLAYER);
617 Collect information of endpoints
620 int take_count = list_from->getItem(from_i).count;
621 if(count != 0 && count < take_count)
623 int src_can_take_count = take_count;
625 // Source is detached
626 if(from_inv.type == InventoryLocation::DETACHED)
628 ItemStack src_item = list_from->getItem(from_i);
629 src_item.count = take_count;
630 src_can_take_count = PLAYER_TO_SA(player)->detached_inventory_AllowTake(
631 from_inv.name, from_list, from_i, src_item, player);
634 // Source is nodemeta
635 if(from_inv.type == InventoryLocation::NODEMETA)
637 ItemStack src_item = list_from->getItem(from_i);
638 src_item.count = take_count;
639 src_can_take_count = PLAYER_TO_SA(player)->nodemeta_inventory_AllowTake(
640 from_inv.p, from_list, from_i, src_item, player);
643 if(src_can_take_count != -1 && src_can_take_count < take_count)
644 take_count = src_can_take_count;
646 int actually_dropped_count = 0;
648 ItemStack src_item = list_from->getItem(from_i);
651 ItemStack item1 = list_from->getItem(from_i);
652 item1.count = take_count;
653 if(PLAYER_TO_SA(player)->item_OnDrop(item1, player,
654 player->getBasePosition() + v3f(0,1,0)))
656 actually_dropped_count = take_count - item1.count;
658 if(actually_dropped_count == 0){
659 infostream<<"Actually dropped no items"<<std::endl;
663 // If source isn't infinite
664 if(src_can_take_count != -1){
665 // Take item from source list
666 ItemStack item2 = list_from->takeItem(from_i, actually_dropped_count);
668 if(item2.count != actually_dropped_count)
669 errorstream<<"Could not take dropped count of items"<<std::endl;
671 mgr->setInventoryModified(from_inv, false);
675 infostream<<"IDropAction::apply(): dropped "
676 <<" from inv=\""<<from_inv.dump()<<"\""
677 <<" list=\""<<from_list<<"\""
681 src_item.count = actually_dropped_count;
684 Report drop to endpoints
687 // Source is detached
688 if(from_inv.type == InventoryLocation::DETACHED)
690 PLAYER_TO_SA(player)->detached_inventory_OnTake(
691 from_inv.name, from_list, from_i, src_item, player);
694 // Source is nodemeta
695 if(from_inv.type == InventoryLocation::NODEMETA)
697 PLAYER_TO_SA(player)->nodemeta_inventory_OnTake(
698 from_inv.p, from_list, from_i, src_item, player);
702 Record rollback information
704 if(!ignore_src_rollback && gamedef->rollback())
706 IRollbackManager *rollback = gamedef->rollback();
708 // If source is not infinite, record item take
709 if(src_can_take_count != -1){
710 RollbackAction action;
713 std::ostringstream os(std::ios::binary);
714 from_inv.serialize(os);
717 action.setModifyInventoryStack(loc, from_list, from_i,
719 rollback->reportAction(action);
724 void IDropAction::clientApply(InventoryManager *mgr, IGameDef *gamedef)
726 // Optional InventoryAction operation that is run on the client
727 // to make lag less apparent.
729 Inventory *inv_from = mgr->getInventory(from_inv);
733 InventoryLocation current_player;
734 current_player.setCurrentPlayer();
735 Inventory *inv_player = mgr->getInventory(current_player);
736 if(inv_from != inv_player)
739 InventoryList *list_from = inv_from->getList(from_list);
744 list_from->changeItem(from_i, ItemStack());
746 list_from->takeItem(from_i, count);
748 mgr->setInventoryModified(from_inv);
755 ICraftAction::ICraftAction(std::istream &is)
759 std::getline(is, ts, ' ');
762 std::getline(is, ts, ' ');
763 craft_inv.deSerialize(ts);
766 void ICraftAction::apply(InventoryManager *mgr,
767 ServerActiveObject *player, IGameDef *gamedef)
769 Inventory *inv_craft = mgr->getInventory(craft_inv);
772 infostream << "ICraftAction::apply(): FAIL: inventory not found: "
773 << "craft_inv=\"" << craft_inv.dump() << "\"" << std::endl;
777 InventoryList *list_craft = inv_craft->getList("craft");
778 InventoryList *list_craftresult = inv_craft->getList("craftresult");
779 InventoryList *list_main = inv_craft->getList("main");
782 If a list doesn't exist or the source item doesn't exist
785 infostream << "ICraftAction::apply(): FAIL: craft list not found: "
786 << "craft_inv=\"" << craft_inv.dump() << "\"" << std::endl;
789 if (!list_craftresult) {
790 infostream << "ICraftAction::apply(): FAIL: craftresult list not found: "
791 << "craft_inv=\"" << craft_inv.dump() << "\"" << std::endl;
794 if (list_craftresult->getSize() < 1) {
795 infostream << "ICraftAction::apply(): FAIL: craftresult list too short: "
796 << "craft_inv=\"" << craft_inv.dump() << "\"" << std::endl;
801 ItemStack craftresultitem;
802 int count_remaining = count;
803 std::vector<ItemStack> output_replacements;
804 getCraftingResult(inv_craft, crafted, output_replacements, false, gamedef);
805 PLAYER_TO_SA(player)->item_CraftPredict(crafted, player, list_craft, craft_inv);
806 bool found = !crafted.empty();
808 while (found && list_craftresult->itemFits(0, crafted)) {
809 InventoryList saved_craft_list = *list_craft;
811 std::vector<ItemStack> temp;
812 // Decrement input and add crafting output
813 getCraftingResult(inv_craft, crafted, temp, true, gamedef);
814 PLAYER_TO_SA(player)->item_OnCraft(crafted, player, &saved_craft_list, craft_inv);
815 list_craftresult->addItem(0, crafted);
816 mgr->setInventoryModified(craft_inv);
818 // Add the new replacements to the list
819 IItemDefManager *itemdef = gamedef->getItemDefManager();
820 for (std::vector<ItemStack>::iterator it = temp.begin();
821 it != temp.end(); ++it) {
822 for (std::vector<ItemStack>::iterator jt = output_replacements.begin();
823 jt != output_replacements.end(); ++jt) {
824 if (it->name == jt->name) {
825 *it = jt->addItem(*it, itemdef);
830 output_replacements.push_back(*it);
833 actionstream << player->getDescription()
835 << crafted.getItemString()
839 if (count_remaining == 1)
841 else if (count_remaining > 1)
844 // Get next crafting result
845 found = getCraftingResult(inv_craft, crafted, temp, false, gamedef);
846 PLAYER_TO_SA(player)->item_CraftPredict(crafted, player, list_craft, craft_inv);
847 found = !crafted.empty();
850 // Put the replacements in the inventory or drop them on the floor, if
851 // the invenotry is full
852 for (std::vector<ItemStack>::iterator it = output_replacements.begin();
853 it != output_replacements.end(); ++it) {
855 *it = list_main->addItem(*it);
858 u16 count = it->count;
860 PLAYER_TO_SA(player)->item_OnDrop(*it, player,
861 player->getBasePosition() + v3f(0,1,0));
862 if (count >= it->count) {
863 errorstream << "Couldn't drop replacement stack " <<
864 it->getItemString() << " because drop loop didn't "
865 "decrease count." << std::endl;
869 } while (!it->empty());
872 infostream<<"ICraftAction::apply(): crafted "
873 <<" craft_inv=\""<<craft_inv.dump()<<"\""
877 void ICraftAction::clientApply(InventoryManager *mgr, IGameDef *gamedef)
879 // Optional InventoryAction operation that is run on the client
880 // to make lag less apparent.
885 bool getCraftingResult(Inventory *inv, ItemStack& result,
886 std::vector<ItemStack> &output_replacements,
887 bool decrementInput, IGameDef *gamedef)
889 DSTACK(FUNCTION_NAME);
893 // Get the InventoryList in which we will operate
894 InventoryList *clist = inv->getList("craft");
898 // Mangle crafting grid to an another format
900 ci.method = CRAFT_METHOD_NORMAL;
901 ci.width = clist->getWidth() ? clist->getWidth() : 3;
902 for(u16 i=0; i<clist->getSize(); i++)
903 ci.items.push_back(clist->getItem(i));
905 // Find out what is crafted and add it to result item slot
907 bool found = gamedef->getCraftDefManager()->getCraftResult(
908 ci, co, output_replacements, decrementInput, gamedef);
910 result.deSerialize(co.item, gamedef->getItemDefManager());
912 if(found && decrementInput)
914 // CraftInput has been changed, apply changes in clist
915 for(u16 i=0; i<clist->getSize(); i++)
917 clist->changeItem(i, ci.items[i]);