175
175
176
176
-- Checks if specified volume intersects a protected volume
177
177
178
- function core .intersects_protection (minp , maxp , player_name , interval )
178
+ function core .is_area_protected (minp , maxp , player_name , interval )
179
179
-- 'interval' is the largest allowed interval for the 3D lattice of checks.
180
180
181
181
-- Compute the optimal float step 'd' for each axis so that all corners and
@@ -188,14 +188,18 @@ function core.intersects_protection(minp, maxp, player_name, interval)
188
188
local d = {}
189
189
190
190
for _ , c in pairs ({" x" , " y" , " z" }) do
191
+ if minp [c ] > maxp [c ] then
192
+ -- Repair positions: 'minp' > 'maxp'
193
+ local tmp = maxp [c ]
194
+ maxp [c ] = minp [c ]
195
+ minp [c ] = tmp
196
+ end
197
+
191
198
if maxp [c ] > minp [c ] then
192
199
d [c ] = (maxp [c ] - minp [c ]) /
193
200
math.ceil ((maxp [c ] - minp [c ]) / interval ) - 1e-4
194
- elseif maxp [ c ] == minp [ c ] then
201
+ else
195
202
d [c ] = 1 -- Any value larger than 0 to avoid division by zero
196
- else -- maxp[c] < minp[c], print error and treat as protection intersected
197
- minetest .log (" error" , " maxp < minp in 'minetest.intersects_protection()'" )
198
- return true
199
203
end
200
204
end
201
205
@@ -205,13 +209,13 @@ function core.intersects_protection(minp, maxp, player_name, interval)
205
209
local y = math.floor (yf + 0.5 )
206
210
for xf = minp .x , maxp .x , d .x do
207
211
local x = math.floor (xf + 0.5 )
208
- if core .is_protected ({x = x , y = y , z = z }, player_name ) then
209
- return true
212
+ local pos = {x = x , y = y , z = z }
213
+ if core .is_protected (pos , player_name ) then
214
+ return pos
210
215
end
211
216
end
212
217
end
213
218
end
214
-
215
219
return false
216
220
end
217
221
0 commit comments