]> git.lizzy.rs Git - minetest.git/blobdiff - src/inventorymanager.cpp
Fix another typo in example configuration
[minetest.git] / src / inventorymanager.cpp
index 6187675d47e2c22002acfb3f2e8bc6166e23c1fc..1c511e9cbe69f7659e70e8a7a1d5e172285af73b 100644 (file)
@@ -20,7 +20,7 @@ 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"
@@ -29,6 +29,8 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 
 #define PP(x) "("<<(x).X<<","<<(x).Y<<","<<(x).Z<<")"
 
+#define PLAYER_TO_SA(p)   p->getEnv()->getScriptIface()
+
 /*
        InventoryLocation
 */
@@ -722,13 +724,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);
+       PLAYER_TO_SA(player)->item_CraftPredict(crafted, player, list_craft, craft_inv);
+       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 +753,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 "