summaryrefslogtreecommitdiff
path: root/src/script/lua_api/l_client.cpp
diff options
context:
space:
mode:
authorred-001 <red-001@outlook.ie>2017-01-31 13:18:52 +0000
committerLoïc Blot <nerzhul@users.noreply.github.com>2017-03-13 23:56:05 +0100
commit88df9fb5b6c78df9485e8bf3750e2608bd78e14c (patch)
treed823267e244592a7603dc3baffff49818765a853 /src/script/lua_api/l_client.cpp
parent44ca9c9cb2079fa97068adb8ee894c5ae13a9975 (diff)
downloadminetest-88df9fb5b6c78df9485e8bf3750e2608bd78e14c.tar.gz
minetest-88df9fb5b6c78df9485e8bf3750e2608bd78e14c.tar.bz2
minetest-88df9fb5b6c78df9485e8bf3750e2608bd78e14c.zip
Add `get_wielded_item`
Diffstat (limited to 'src/script/lua_api/l_client.cpp')
-rw-r--r--src/script/lua_api/l_client.cpp19
1 files changed, 19 insertions, 0 deletions
diff --git a/src/script/lua_api/l_client.cpp b/src/script/lua_api/l_client.cpp
index 41e33889c..1673a62ce 100644
--- a/src/script/lua_api/l_client.cpp
+++ b/src/script/lua_api/l_client.cpp
@@ -25,6 +25,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "gettext.h"
#include "common/c_converter.h"
#include "common/c_content.h"
+#include "lua_api/l_item.h"
int ModApiClient::l_get_current_modname(lua_State *L)
{
@@ -132,6 +133,23 @@ int ModApiClient::l_get_node_or_nil(lua_State *L)
return 1;
}
+int ModApiClient::l_get_wielded_item(lua_State *L)
+{
+ Client *client = getClient(L);
+
+ Inventory local_inventory(client->idef());
+ client->getLocalInventory(local_inventory);
+
+ InventoryList *mlist = local_inventory.getList("main");
+
+ if (mlist && client->getPlayerItem() < mlist->getSize()) {
+ LuaItemStack::create(L, mlist->getItem(client->getPlayerItem()));
+ } else {
+ LuaItemStack::create(L, ItemStack());
+ }
+ return 1;
+}
+
void ModApiClient::Initialize(lua_State *L, int top)
{
API_FCT(get_current_modname);
@@ -143,4 +161,5 @@ void ModApiClient::Initialize(lua_State *L, int top)
API_FCT(gettext);
API_FCT(get_node);
API_FCT(get_node_or_nil);
+ API_FCT(get_wielded_item);
}