-- minetest.register_node(name, {lots of stuff})
-- minetest.register_craft({output=item, recipe={...})
-- minetest.register_globalstep(func)
--- minetest.register_on_placenode(func)
--- minetest.register_on_dignode(func)
+-- minetest.register_on_placenode(func(pos, newnode, placer))
+-- minetest.register_on_dignode(func(pos, oldnode, digger))
+-- minetest.register_on_punchnode(func(pos, node, puncher))
--
-- Global objects:
-- minetest.env - environment reference
}
}
-void scriptapi_environment_on_placenode(lua_State *L, v3s16 p, MapNode newnode)
+void scriptapi_environment_on_placenode(lua_State *L, v3s16 p, MapNode newnode,
+ ServerActiveObject *placer)
{
realitycheck(L);
assert(lua_checkstack(L, 20));
// Call function
pushpos(L, p);
pushnode(L, newnode, ndef);
- if(lua_pcall(L, 2, 0, 0))
+ objectref_get_or_create(L, placer);
+ if(lua_pcall(L, 3, 0, 0))
script_error(L, "error: %s\n", lua_tostring(L, -1));
// value removed, keep key for next iteration
}
}
-void scriptapi_environment_on_dignode(lua_State *L, v3s16 p, MapNode oldnode)
+void scriptapi_environment_on_dignode(lua_State *L, v3s16 p, MapNode oldnode,
+ ServerActiveObject *digger)
{
realitycheck(L);
assert(lua_checkstack(L, 20));
// Call function
pushpos(L, p);
pushnode(L, oldnode, ndef);
- if(lua_pcall(L, 2, 0, 0))
+ objectref_get_or_create(L, digger);
+ if(lua_pcall(L, 3, 0, 0))
script_error(L, "error: %s\n", lua_tostring(L, -1));
// value removed, keep key for next iteration
}
}
-void scriptapi_environment_on_punchnode(lua_State *L, v3s16 p, MapNode oldnode)
+void scriptapi_environment_on_punchnode(lua_State *L, v3s16 p, MapNode node,
+ ServerActiveObject *puncher)
{
realitycheck(L);
assert(lua_checkstack(L, 20));
luaL_checktype(L, -1, LUA_TFUNCTION);
// Call function
pushpos(L, p);
- pushnode(L, oldnode, ndef);
- if(lua_pcall(L, 2, 0, 0))
+ pushnode(L, node, ndef);
+ objectref_get_or_create(L, puncher);
+ if(lua_pcall(L, 3, 0, 0))
script_error(L, "error: %s\n", lua_tostring(L, -1));
// value removed, keep key for next iteration
}
// On environment step
void scriptapi_environment_step(lua_State *L, float dtime);
// After adding node
-void scriptapi_environment_on_placenode(lua_State *L, v3s16 p, MapNode newnode);
+void scriptapi_environment_on_placenode(lua_State *L, v3s16 p, MapNode newnode,
+ ServerActiveObject *placer);
// After removing node
-void scriptapi_environment_on_dignode(lua_State *L, v3s16 p, MapNode oldnode);
+void scriptapi_environment_on_dignode(lua_State *L, v3s16 p, MapNode oldnode,
+ ServerActiveObject *digger);
// When punching node
-void scriptapi_environment_on_punchnode(lua_State *L, v3s16 p, MapNode node);
+void scriptapi_environment_on_punchnode(lua_State *L, v3s16 p, MapNode node,
+ ServerActiveObject *puncher);
/* luaentity */
// Returns true if succesfully added into Lua; false otherwise.
/*
Run script hook
*/
- scriptapi_environment_on_punchnode(m_lua, p_under, n);
+ ServerRemotePlayer *srp = (ServerRemotePlayer*)player;
+ scriptapi_environment_on_punchnode(m_lua, p_under, n, srp);
} // action == 0
/*
Run script hook
*/
- scriptapi_environment_on_dignode(m_lua, p_under, n);
+ ServerRemotePlayer *srp = (ServerRemotePlayer*)player;
+ scriptapi_environment_on_dignode(m_lua, p_under, n, srp);
}
/*
/*
Run script hook
*/
- scriptapi_environment_on_placenode(m_lua, p_over, n);
+ ServerRemotePlayer *srp = (ServerRemotePlayer*)player;
+ scriptapi_environment_on_placenode(m_lua, p_over, n, srp);
/*
Calculate special events