]> git.lizzy.rs Git - dragonfireclient.git/blobdiff - src/inventorymanager.cpp
Write common mapgen params to map_meta.txt on world initialization
[dragonfireclient.git] / src / inventorymanager.cpp
index 6187675d47e2c22002acfb3f2e8bc6166e23c1fc..ed18126d0dc8538fcb9e0349f15229662ffd090d 100644 (file)
@@ -20,15 +20,18 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include "inventorymanager.h"
 #include "log.h"
 #include "environment.h"
-#include "cpp_api/scriptapi.h"
+#include "scripting_game.h"
 #include "serverobject.h"
 #include "main.h"  // for g_settings
 #include "settings.h"
 #include "craftdef.h"
 #include "rollback_interface.h"
+#include "strfnd.h"
 
 #define PP(x) "("<<(x).X<<","<<(x).Y<<","<<(x).Z<<")"
 
+#define PLAYER_TO_SA(p)   p->getEnv()->getScriptIface()
+
 /*
        InventoryLocation
 */
@@ -365,7 +368,7 @@ void IMoveAction::apply(InventoryManager *mgr, ServerActiveObject *player, IGame
        */
        if(!ignore_rollback && gamedef->rollback())
        {
-               IRollbackReportSink *rollback = gamedef->rollback();
+               IRollbackManager *rollback = gamedef->rollback();
 
                // If source is not infinite, record item take
                if(src_can_take_count != -1){
@@ -377,7 +380,7 @@ void IMoveAction::apply(InventoryManager *mgr, ServerActiveObject *player, IGame
                                loc = os.str();
                        }
                        action.setModifyInventoryStack(loc, from_list, from_i, false,
-                                       src_item.getItemString());
+                                       src_item);
                        rollback->reportAction(action);
                }
                // If destination is not infinite, record item put
@@ -390,7 +393,7 @@ void IMoveAction::apply(InventoryManager *mgr, ServerActiveObject *player, IGame
                                loc = os.str();
                        }
                        action.setModifyInventoryStack(loc, to_list, to_i, true,
-                                       src_item.getItemString());
+                                       src_item);
                        rollback->reportAction(action);
                }
        }
@@ -629,7 +632,7 @@ void IDropAction::apply(InventoryManager *mgr, ServerActiveObject *player, IGame
        */
        if(!ignore_src_rollback && gamedef->rollback())
        {
-               IRollbackReportSink *rollback = gamedef->rollback();
+               IRollbackManager *rollback = gamedef->rollback();
 
                // If source is not infinite, record item take
                if(src_can_take_count != -1){
@@ -641,7 +644,7 @@ void IDropAction::apply(InventoryManager *mgr, ServerActiveObject *player, IGame
                                loc = os.str();
                        }
                        action.setModifyInventoryStack(loc, from_list, from_i,
-                                       false, src_item.getItemString());
+                                       false, src_item);
                        rollback->reportAction(action);
                }
        }
@@ -722,13 +725,19 @@ void ICraftAction::apply(InventoryManager *mgr, ServerActiveObject *player, IGam
        }
 
        ItemStack crafted;
+       ItemStack craftresultitem;
        int count_remaining = count;
-       bool found = getCraftingResult(inv_craft, crafted, false, gamedef);
+       getCraftingResult(inv_craft, crafted, false, gamedef);
+       PLAYER_TO_SA(player)->item_CraftPredict(crafted, player, list_craft, craft_inv);
+       bool found = !crafted.empty();
 
        while(found && list_craftresult->itemFits(0, crafted))
        {
+               InventoryList saved_craft_list = *list_craft;
+               
                // Decrement input and add crafting output
                getCraftingResult(inv_craft, crafted, true, gamedef);
+               PLAYER_TO_SA(player)->item_OnCraft(crafted, player, &saved_craft_list, craft_inv);
                list_craftresult->addItem(0, crafted);
                mgr->setInventoryModified(craft_inv);
 
@@ -745,6 +754,8 @@ void ICraftAction::apply(InventoryManager *mgr, ServerActiveObject *player, IGam
 
                // Get next crafting result
                found = getCraftingResult(inv_craft, crafted, false, gamedef);
+               PLAYER_TO_SA(player)->item_CraftPredict(crafted, player, list_craft, craft_inv);
+               found = !crafted.empty();
        }
 
        infostream<<"ICraftAction::apply(): crafted "