Add return list of individual counts to find_node_in_area
parent
502e40a649
commit
e50aa4ed06
|
@ -1917,6 +1917,7 @@ and `minetest.auth_reload` call the authetification handler.
|
||||||
* `minetest.find_node_near(pos, radius, nodenames)`: returns pos or `nil`
|
* `minetest.find_node_near(pos, radius, nodenames)`: returns pos or `nil`
|
||||||
* `nodenames`: e.g. `{"ignore", "group:tree"}` or `"default:dirt"`
|
* `nodenames`: e.g. `{"ignore", "group:tree"}` or `"default:dirt"`
|
||||||
* `minetest.find_nodes_in_area(minp, maxp, nodenames)`: returns a list of positions
|
* `minetest.find_nodes_in_area(minp, maxp, nodenames)`: returns a list of positions
|
||||||
|
* returns as second value a table with the count of the individual nodes found
|
||||||
* `nodenames`: e.g. `{"ignore", "group:tree"}` or `"default:dirt"`
|
* `nodenames`: e.g. `{"ignore", "group:tree"}` or `"default:dirt"`
|
||||||
* `minetest.find_nodes_in_area_under_air(minp, maxp, nodenames)`: returns a list of positions
|
* `minetest.find_nodes_in_area_under_air(minp, maxp, nodenames)`: returns a list of positions
|
||||||
* returned positions are nodes with a node air above
|
* returned positions are nodes with a node air above
|
||||||
|
|
|
@ -572,6 +572,8 @@ int ModApiEnvMod::l_find_nodes_in_area(lua_State *L)
|
||||||
ndef->getIds(lua_tostring(L, 3), filter);
|
ndef->getIds(lua_tostring(L, 3), filter);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::map<content_t, u16> individual_count;
|
||||||
|
|
||||||
lua_newtable(L);
|
lua_newtable(L);
|
||||||
u64 i = 0;
|
u64 i = 0;
|
||||||
for (s16 x = minp.X; x <= maxp.X; x++)
|
for (s16 x = minp.X; x <= maxp.X; x++)
|
||||||
|
@ -582,9 +584,16 @@ int ModApiEnvMod::l_find_nodes_in_area(lua_State *L)
|
||||||
if (filter.count(c) != 0) {
|
if (filter.count(c) != 0) {
|
||||||
push_v3s16(L, p);
|
push_v3s16(L, p);
|
||||||
lua_rawseti(L, -2, ++i);
|
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
|
// find_nodes_in_area_under_air(minp, maxp, nodenames) -> list of positions
|
||||||
|
|
Loading…
Reference in New Issue