@@ -22,9 +22,12 @@ with this program; if not, write to the Free Software Foundation, Inc.,
22
22
#include " common/c_converter.h"
23
23
#include " common/c_content.h"
24
24
#include " lua_api/l_item.h"
25
+ #include " lua_api/l_inventory.h"
25
26
#include " server.h"
26
27
#include " log.h"
27
28
#include " util/pointedthing.h"
29
+ #include " inventory.h"
30
+ #include " inventorymanager.h"
28
31
29
32
bool ScriptApiItem::item_OnDrop (ItemStack &item,
30
33
ServerActiveObject *dropper, v3f pos)
@@ -86,6 +89,54 @@ bool ScriptApiItem::item_OnUse(ItemStack &item,
86
89
return true ;
87
90
}
88
91
92
+ bool ScriptApiItem::item_OnCraft (ItemStack &item, ServerActiveObject *user,
93
+ const InventoryList *old_craft_grid, const InventoryLocation &craft_inv)
94
+ {
95
+ SCRIPTAPI_PRECHECKHEADER
96
+
97
+ lua_getglobal (L, " minetest" );
98
+ lua_getfield (L, -1 , " on_craft" );
99
+ LuaItemStack::create (L, item);
100
+ objectrefGetOrCreate (user);
101
+
102
+ // Push inventory list
103
+ std::vector<ItemStack> items;
104
+ for (u32 i=0 ; i<old_craft_grid->getSize (); i++)
105
+ items.push_back (old_craft_grid->getItem (i));
106
+ push_items (L, items);
107
+
108
+ InvRef::create (L, craft_inv);
109
+ if (lua_pcall (L, 4 , 1 , 0 ))
110
+ scriptError (" error: %s" , lua_tostring (L, -1 ));
111
+ if (!lua_isnil (L, -1 ))
112
+ item = read_item (L,-1 , getServer ());
113
+ return true ;
114
+ }
115
+
116
+ bool ScriptApiItem::item_CraftPredict (ItemStack &item, ServerActiveObject *user,
117
+ const InventoryList *old_craft_grid, const InventoryLocation &craft_inv)
118
+ {
119
+ SCRIPTAPI_PRECHECKHEADER
120
+
121
+ lua_getglobal (L, " minetest" );
122
+ lua_getfield (L, -1 , " craft_predict" );
123
+ LuaItemStack::create (L, item);
124
+ objectrefGetOrCreate (user);
125
+
126
+ // Push inventory list
127
+ std::vector<ItemStack> items;
128
+ for (u32 i=0 ; i<old_craft_grid->getSize (); i++)
129
+ items.push_back (old_craft_grid->getItem (i));
130
+ push_items (L, items);
131
+
132
+ InvRef::create (L, craft_inv);
133
+ if (lua_pcall (L, 4 , 1 , 0 ))
134
+ scriptError (" error: %s" , lua_tostring (L, -1 ));
135
+ if (!lua_isnil (L, -1 ))
136
+ item = read_item (L,-1 , getServer ());
137
+ return true ;
138
+ }
139
+
89
140
// Retrieves minetest.registered_items[name][callbackname]
90
141
// If that is nil or on error, return false and stack is unchanged
91
142
// If that is a function, returns true and pushes the
0 commit comments