diff options
author | kwolekr <kwolekr@minetest.net> | 2015-05-05 14:30:46 -0400 |
---|---|---|
committer | kwolekr <kwolekr@minetest.net> | 2015-05-05 16:21:59 -0400 |
commit | b785577f03d00c83236782876def4c900edbba4e (patch) | |
tree | 389f3baa9e4b3d6abcab1d752a248bcdc933b52d /src/script/lua_api/l_env.cpp | |
parent | b45df9d6a73d97671cbdd38d77e9b153a80fb458 (diff) | |
download | minetest-b785577f03d00c83236782876def4c900edbba4e.tar.gz minetest-b785577f03d00c83236782876def4c900edbba4e.tar.bz2 minetest-b785577f03d00c83236782876def4c900edbba4e.zip |
Add core.find_nodes_with_meta() script API
Diffstat (limited to 'src/script/lua_api/l_env.cpp')
-rw-r--r-- | src/script/lua_api/l_env.cpp | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/src/script/lua_api/l_env.cpp b/src/script/lua_api/l_env.cpp index 0fe1ddec3..9581d1ef3 100644 --- a/src/script/lua_api/l_env.cpp +++ b/src/script/lua_api/l_env.cpp @@ -334,6 +334,22 @@ int ModApiEnvMod::l_add_node_level(lua_State *L) return 1; } +// find_nodes_with_meta(pos1, pos2) +int ModApiEnvMod::l_find_nodes_with_meta(lua_State *L) +{ + GET_ENV_PTR; + + std::vector<v3s16> positions = env->getMap().findNodesWithMetadata( + check_v3s16(L, 1), check_v3s16(L, 2)); + + lua_newtable(L); + for (size_t i = 0; i != positions.size(); i++) { + push_v3s16(L, positions[i]); + lua_rawseti(L, -2, i + 1); + } + + return 1; +} // get_meta(pos) int ModApiEnvMod::l_get_meta(lua_State *L) @@ -912,6 +928,7 @@ void ModApiEnvMod::Initialize(lua_State *L, int top) API_FCT(set_node_level); API_FCT(add_node_level); API_FCT(add_entity); + API_FCT(find_nodes_with_meta); API_FCT(get_meta); API_FCT(get_node_timer); API_FCT(get_player_by_name); |