1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-06-27 16:36:03 +00:00

Allow defining player's inventory form in Lua

This commit is contained in:
Perttu Ahola 2012-07-19 14:09:16 +03:00
parent 02fb912a95
commit 16ad10e62f
10 changed files with 129 additions and 10 deletions

View file

@ -2864,6 +2864,32 @@ private:
return 1;
}
// set_inventory_formspec(self, formspec)
static int l_set_inventory_formspec(lua_State *L)
{
ObjectRef *ref = checkobject(L, 1);
Player *player = getplayer(ref);
if(player == NULL) return 0;
std::string formspec = luaL_checkstring(L, 2);
player->inventory_formspec = formspec;
get_server(L)->reportInventoryFormspecModified(player->getName());
lua_pushboolean(L, true);
return 1;
}
// get_inventory_formspec(self) -> formspec
static int l_get_inventory_formspec(lua_State *L)
{
ObjectRef *ref = checkobject(L, 1);
Player *player = getplayer(ref);
if(player == NULL) return 0;
std::string formspec = player->inventory_formspec;
lua_pushlstring(L, formspec.c_str(), formspec.size());
return 1;
}
public:
ObjectRef(ServerActiveObject *object):
m_object(object)
@ -2960,6 +2986,8 @@ const luaL_reg ObjectRef::methods[] = {
method(ObjectRef, get_look_dir),
method(ObjectRef, get_look_pitch),
method(ObjectRef, get_look_yaw),
method(ObjectRef, set_inventory_formspec),
method(ObjectRef, get_inventory_formspec),
{0,0}
};