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.
master
mckaygerhard 2023-08-06 09:52:36 -04:00
parent 5b37aa6387
commit 35829d7ca6
1 changed files with 27 additions and 8 deletions

View File

@ -1,5 +1,8 @@
-- mods/default/functions.lua
-- Check for a volume intersecting protection
local is_50 = minetest.has_feature("object_use_texture_alpha") or nil
--
-- Sounds
--
@ -482,25 +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
-- 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
-- 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
@ -510,14 +520,23 @@ function default.intersects_protection(minp, maxp, player_name, interval)
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
end
return false
end
end
if not is_50 then
-- older engines backguar compatibility
minetest.is_area_protected = default.intersects_protection
end