summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAuke Kok <sofar@foo-projects.org>2017-12-15 12:32:53 -0800
committerAuke Kok <sofar@foo-projects.org>2017-12-15 12:32:53 -0800
commit1c0e3c72156d87ad3f6b4ba2c8d537a2f9b622c6 (patch)
treed04cff059fb6d6125b2026607dd0b20287fd7712
parentaac8386b5ae85d232c94128810d3f4df8b32ecaa (diff)
Fix max search area exceeded crash.
find_nodes_in_area is limited to 82^3 nodes, and will abort the server if that is exceeded. Assure we never do.
-rw-r--r--date_palm.lua17
1 files changed, 11 insertions, 6 deletions
diff --git a/date_palm.lua b/date_palm.lua
index 0c40b72..f8b3e42 100644
--- a/date_palm.lua
+++ b/date_palm.lua
@@ -223,13 +223,18 @@ local function find_fruit_trunks_near(ftpos, sect)
return nil
end
+ local basevec = { x = ftpos.x + 2 * sect.x * sect_hr,
+ y = ftpos.y,
+ z = ftpos.z + 2 * sect.z * sect_hr}
+ -- find_nodes_in_area is limited to 82^3, make sure to not overrun it
+ local sizevec = { x = sect_hr, y = sect_vr, z = sect_hr }
+ if sect_hr * sect_hr * sect_vr > 41^3 then
+ sizevec = vector.apply(sizevec, function(a) return math.min(a, 41) end)
+ end
+
local all_palms = minetest.find_nodes_in_area(
- { x = ftpos.x + 2 * sect.x * sect_hr - sect_hr,
- y = ftpos.y - sect_vr,
- z = ftpos.z + 2 * sect.z * sect_hr - sect_hr },
- { x = ftpos.x + 2 * sect.x * sect_hr + sect_hr,
- y = ftpos.y + sect_vr,
- z = ftpos.z + 2 * sect.z * sect_hr + sect_hr },
+ vector.subtract(basevec, sizevec),
+ vector.add(basevec, sizevec),
{"moretrees:date_palm_mfruit_trunk", "moretrees:date_palm_ffruit_trunk"})
-- Collect different palms in separate lists.