diff options
author | red-001 <red-001@outlook.ie> | 2017-01-30 19:10:37 +0000 |
---|---|---|
committer | Loïc Blot <nerzhul@users.noreply.github.com> | 2017-03-13 23:56:05 +0100 |
commit | 37df9cb7d764891f29b433e80a0d5663fee1a94f (patch) | |
tree | efed423ad2021439267eb5e1e8719fb8514ea6d7 /src/script/lua_api | |
parent | 073f5cf03d95ce1cdf04ce8a0adcaf1fc571d95f (diff) | |
download | minetest-37df9cb7d764891f29b433e80a0d5663fee1a94f.tar.gz minetest-37df9cb7d764891f29b433e80a0d5663fee1a94f.tar.bz2 minetest-37df9cb7d764891f29b433e80a0d5663fee1a94f.zip |
[CSM] Add `get_node` and `get_node_or_nil`
Diffstat (limited to 'src/script/lua_api')
-rw-r--r-- | src/script/lua_api/l_client.cpp | 37 | ||||
-rw-r--r-- | src/script/lua_api/l_client.h | 8 |
2 files changed, 45 insertions, 0 deletions
diff --git a/src/script/lua_api/l_client.cpp b/src/script/lua_api/l_client.cpp index 9a04bd02f..41e33889c 100644 --- a/src/script/lua_api/l_client.cpp +++ b/src/script/lua_api/l_client.cpp @@ -23,6 +23,8 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "util/string.h" #include "cpp_api/s_base.h" #include "gettext.h" +#include "common/c_converter.h" +#include "common/c_content.h" int ModApiClient::l_get_current_modname(lua_State *L) { @@ -97,6 +99,39 @@ int ModApiClient::l_gettext(lua_State *L) return 1; } +// get_node(pos) +// pos = {x=num, y=num, z=num} +int ModApiClient::l_get_node(lua_State *L) +{ + // pos + v3s16 pos = read_v3s16(L, 1); + // Do it + bool pos_ok; + MapNode n = getClient(L)->getNode(pos, &pos_ok); + // Return node + pushnode(L, n, getClient(L)->ndef()); + return 1; +} + +// get_node_or_nil(pos) +// pos = {x=num, y=num, z=num} +int ModApiClient::l_get_node_or_nil(lua_State *L) +{ + // pos + v3s16 pos = read_v3s16(L, 1); + // Do it + bool pos_ok; + MapNode n = getClient(L)->getNode(pos, &pos_ok); + if (pos_ok) { + // Return node + pushnode(L, n, getClient(L)->ndef()); + } + else { + lua_pushnil(L); + } + return 1; +} + void ModApiClient::Initialize(lua_State *L, int top) { API_FCT(get_current_modname); @@ -106,4 +141,6 @@ void ModApiClient::Initialize(lua_State *L, int top) API_FCT(show_formspec); API_FCT(send_respawn); API_FCT(gettext); + API_FCT(get_node); + API_FCT(get_node_or_nil); } diff --git a/src/script/lua_api/l_client.h b/src/script/lua_api/l_client.h index d0e230630..207a5bca0 100644 --- a/src/script/lua_api/l_client.h +++ b/src/script/lua_api/l_client.h @@ -47,6 +47,14 @@ private: // set_last_run_mod(modname) static int l_set_last_run_mod(lua_State *L); + // get_node(pos) + static int l_get_node(lua_State *L); + + // get_node_or_nil(pos) + static int l_get_node_or_nil(lua_State *L); + + + public: static void Initialize(lua_State *L, int top); }; |