aboutsummaryrefslogtreecommitdiff
path: root/src/script
diff options
context:
space:
mode:
authorred-001 <red-001@outlook.ie>2017-05-04 21:52:58 +0100
committerLoïc Blot <nerzhul@users.noreply.github.com>2017-05-04 22:52:58 +0200
commitd6cf5450a897b00e5ed0d053f14108c94dfb3701 (patch)
treeed37c0065bd401b4e552477a2ddb31b1795d982e /src/script
parent6fb27d3b2e7c497ae443538dbc4dc9f64ad2f8e9 (diff)
downloadminetest-d6cf5450a897b00e5ed0d053f14108c94dfb3701.tar.gz
minetest-d6cf5450a897b00e5ed0d053f14108c94dfb3701.tar.bz2
minetest-d6cf5450a897b00e5ed0d053f14108c94dfb3701.zip
Add option to also check the center to `find_node_near` (#5255)
* Add option to also check the center to `find_node_near`
Diffstat (limited to 'src/script')
-rw-r--r--src/script/lua_api/l_env.cpp16
-rw-r--r--src/script/lua_api/l_env.h2
2 files changed, 9 insertions, 9 deletions
diff --git a/src/script/lua_api/l_env.cpp b/src/script/lua_api/l_env.cpp
index 85791f90b..0ded12658 100644
--- a/src/script/lua_api/l_env.cpp
+++ b/src/script/lua_api/l_env.cpp
@@ -599,7 +599,7 @@ int ModApiEnvMod::l_get_gametime(lua_State *L)
}
-// find_node_near(pos, radius, nodenames) -> pos or nil
+// find_node_near(pos, radius, nodenames, search_center) -> pos or nil
// nodenames: eg. {"ignore", "group:tree"} or "default:dirt"
int ModApiEnvMod::l_find_node_near(lua_State *L)
{
@@ -612,27 +612,27 @@ int ModApiEnvMod::l_find_node_near(lua_State *L)
v3s16 pos = read_v3s16(L, 1);
int radius = luaL_checkinteger(L, 2);
std::set<content_t> filter;
- if(lua_istable(L, 3)){
- int table = 3;
+ if (lua_istable(L, 3)) {
lua_pushnil(L);
- while(lua_next(L, table) != 0){
+ while (lua_next(L, 3) != 0) {
// key at index -2 and value at index -1
luaL_checktype(L, -1, LUA_TSTRING);
ndef->getIds(lua_tostring(L, -1), filter);
// removes value, keeps key for next iteration
lua_pop(L, 1);
}
- } else if(lua_isstring(L, 3)){
+ } else if (lua_isstring(L, 3)) {
ndef->getIds(lua_tostring(L, 3), filter);
}
- for (int d=1; d<=radius; d++){
+ int start_radius = (lua_toboolean(L, 4)) ? 0 : 1;
+ for (int d = start_radius; d <= radius; d++) {
std::vector<v3s16> list = FacePositionCache::getFacePositions(d);
for (std::vector<v3s16>::iterator i = list.begin();
- i != list.end(); ++i){
+ i != list.end(); ++i) {
v3s16 p = pos + (*i);
content_t c = env->getMap().getNodeNoEx(p).getContent();
- if (filter.count(c) != 0){
+ if (filter.count(c) != 0) {
push_v3s16(L, p);
return 1;
}
diff --git a/src/script/lua_api/l_env.h b/src/script/lua_api/l_env.h
index 3f688b398..629c6bc39 100644
--- a/src/script/lua_api/l_env.h
+++ b/src/script/lua_api/l_env.h
@@ -116,7 +116,7 @@ private:
// get_day_count() -> int
static int l_get_day_count(lua_State *L);
- // find_node_near(pos, radius, nodenames) -> pos or nil
+ // find_node_near(pos, radius, nodenames, search_center) -> pos or nil
// nodenames: eg. {"ignore", "group:tree"} or "default:dirt"
static int l_find_node_near(lua_State *L);