diff options
author | Perttu Ahola <celeron55@gmail.com> | 2011-12-03 18:37:50 +0200 |
---|---|---|
committer | Perttu Ahola <celeron55@gmail.com> | 2011-12-03 18:37:50 +0200 |
commit | f23616acafc3e1503d594b6e324cb72c325a9567 (patch) | |
tree | ecced6fa471358d7e958ace6b63b662ee597b2c8 | |
parent | 7d37913ea4f83807c508cec81b39744d69f481f8 (diff) | |
download | minetest-f23616acafc3e1503d594b6e324cb72c325a9567.tar.gz minetest-f23616acafc3e1503d594b6e324cb72c325a9567.tar.bz2 minetest-f23616acafc3e1503d594b6e324cb72c325a9567.zip |
add EnvRef:get_node_or_nil()
-rw-r--r-- | src/scriptapi.cpp | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/src/scriptapi.cpp b/src/scriptapi.cpp index 3fe69e709..ab1b3d824 100644 --- a/src/scriptapi.cpp +++ b/src/scriptapi.cpp @@ -2308,6 +2308,29 @@ private: return 1; } + // EnvRef:get_node_or_nil(pos) + // pos = {x=num, y=num, z=num} + static int l_get_node_or_nil(lua_State *L) + { + //infostream<<"EnvRef::l_get_node()"<<std::endl; + EnvRef *o = checkobject(L, 1); + ServerEnvironment *env = o->m_env; + if(env == NULL) return 0; + // pos + v3s16 pos = readpos(L, 2); + // Do it + try{ + MapNode n = env->getMap().getNode(pos); + // Return node + pushnode(L, n, env->getGameDef()->ndef()); + return 1; + } catch(InvalidPositionException &e) + { + lua_pushnil(L); + return 1; + } + } + // EnvRef:add_luaentity(pos, entityname) // pos = {x=num, y=num, z=num} static int l_add_luaentity(lua_State *L) @@ -2476,6 +2499,7 @@ const luaL_reg EnvRef::methods[] = { method(EnvRef, add_node), method(EnvRef, remove_node), method(EnvRef, get_node), + method(EnvRef, get_node_or_nil), method(EnvRef, add_luaentity), method(EnvRef, add_item), method(EnvRef, add_rat), |