aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTeTpaAka <TeTpaAka@users.noreply.github.com>2015-05-30 20:53:21 +0200
committerest31 <MTest31@outlook.com>2015-06-13 19:39:18 +0200
commite50aa4ed06f36c74a892ec68d576c52ba9dc0b2c (patch)
treea37a101cd9184a8e62528bfa24bb2527df26d95c /src
parent502e40a649137461947c36ea52205f058f81296f (diff)
downloadminetest-e50aa4ed06f36c74a892ec68d576c52ba9dc0b2c.tar.gz
minetest-e50aa4ed06f36c74a892ec68d576c52ba9dc0b2c.tar.bz2
minetest-e50aa4ed06f36c74a892ec68d576c52ba9dc0b2c.zip
Add return list of individual counts to find_node_in_area
Diffstat (limited to 'src')
-rw-r--r--src/script/lua_api/l_env.cpp29
1 files changed, 19 insertions, 10 deletions
diff --git a/src/script/lua_api/l_env.cpp b/src/script/lua_api/l_env.cpp
index 9581d1ef3..50c445d50 100644
--- a/src/script/lua_api/l_env.cpp
+++ b/src/script/lua_api/l_env.cpp
@@ -572,19 +572,28 @@ int ModApiEnvMod::l_find_nodes_in_area(lua_State *L)
ndef->getIds(lua_tostring(L, 3), filter);
}
+ std::map<content_t, u16> individual_count;
+
lua_newtable(L);
u64 i = 0;
- for(s16 x = minp.X; x <= maxp.X; x++)
- for(s16 y = minp.Y; y <= maxp.Y; y++)
- for(s16 z = minp.Z; z <= maxp.Z; z++) {
- v3s16 p(x, y, z);
- content_t c = env->getMap().getNodeNoEx(p).getContent();
- if(filter.count(c) != 0) {
- push_v3s16(L, p);
- lua_rawseti(L, -2, ++i);
- }
+ for (s16 x = minp.X; x <= maxp.X; x++)
+ for (s16 y = minp.Y; y <= maxp.Y; y++)
+ for (s16 z = minp.Z; z <= maxp.Z; z++) {
+ v3s16 p(x, y, z);
+ content_t c = env->getMap().getNodeNoEx(p).getContent();
+ if (filter.count(c) != 0) {
+ push_v3s16(L, p);
+ lua_rawseti(L, -2, ++i);
+ individual_count[c]++;
+ }
}
- return 1;
+ lua_newtable(L);
+ for (std::set<content_t>::iterator it = filter.begin();
+ it != filter.end(); ++it) {
+ lua_pushnumber(L, individual_count[*it]);
+ lua_setfield(L, -2, ndef->get(*it).name.c_str());
+ }
+ return 2;
}
// find_nodes_in_area_under_air(minp, maxp, nodenames) -> list of positions