default - is_area_protected was renamed from intersects_protection
* backported for working able, renaming compatible function,
https://github.com/minetest/minetest/pull/7073/files#diff-910f021741edbae068c5577bfc681853791aa6dce900b35305972bf5e24941e5R178
for engines that already has it enabled, if not just use
old way function, this backported and enabled
66372e75d9
from default game and also from newer engines build-in lua files
* provide both cases based on engine version, newer just call
the is_area_protected and older just have the code improved,
with aliasing to the improved code.
This commit is contained in:
parent
98e5ebc431
commit
5c5e8058d5
@ -485,28 +485,32 @@ minetest.register_abm({
|
||||
|
||||
|
||||
--
|
||||
-- Checks if specified volume intersects a protected volume
|
||||
-- Checks if specified volume intersects a protected volume, return first node intersected in protected area by player
|
||||
--
|
||||
|
||||
function default.intersects_protection(minp, maxp, player_name, interval)
|
||||
-- 'interval' is the largest allowed interval for the 3D lattice of checks
|
||||
|
||||
if is_50 then
|
||||
-- but newer engines returned first node that intersect area protected or false
|
||||
if is_50 then
|
||||
return minetest.is_area_protected(minp, maxp, player_name, interval)
|
||||
else
|
||||
else
|
||||
-- Compute the optimal float step 'd' for each axis so that all corners and
|
||||
-- borders are checked. 'd' will be smaller or equal to 'interval'.
|
||||
-- Subtracting 1e-4 ensures that the max co-ordinate will be reached by the
|
||||
-- for loop (which might otherwise not be the case due to rounding errors).
|
||||
local d = {}
|
||||
for _, c in pairs({"x", "y", "z"}) do
|
||||
|
||||
if minp[c] > maxp[c] then
|
||||
local tmp = maxp[c]
|
||||
maxp[c] = minp[c]
|
||||
minp[c] = tmp -- Repair positions: 'minp' > 'maxp'
|
||||
end
|
||||
|
||||
if maxp[c] > minp[c] then
|
||||
d[c] = (maxp[c] - minp[c]) / math.ceil((maxp[c] - minp[c]) / interval) - 1e-4
|
||||
elseif maxp[c] == minp[c] then
|
||||
else
|
||||
d[c] = 1 -- Any value larger than 0 to avoid division by zero
|
||||
else -- maxp[c] < minp[c], print error and treat as protection intersected
|
||||
minetest.log("error", "maxp < minp in 'default.intersects_protection()'")
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
||||
@ -516,8 +520,9 @@ else
|
||||
local y = math.floor(yf + 0.5)
|
||||
for xf = minp.x, maxp.x, d.x do
|
||||
local x = math.floor(xf + 0.5)
|
||||
if minetest.is_protected({x = x, y = y, z = z}, player_name) then
|
||||
return true
|
||||
local pos = {x = x, y = y, z = z}
|
||||
if core.is_protected(pos, player_name) then
|
||||
return pos
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -525,8 +530,13 @@ else
|
||||
|
||||
return false
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
if not is_50 then
|
||||
-- older engines backguar compatibility
|
||||
minetest.is_area_protected = default.intersects_protection
|
||||
end
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user