Skip to content

Commit

Permalink
Intersects_protection(): Remove from Minetest Game
Browse files Browse the repository at this point in the history
Add compatibility code with deprecation warning.
  • Loading branch information
paramat committed Feb 3, 2018
1 parent 496a1a2 commit 8f85ca5
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 41 deletions.
40 changes: 0 additions & 40 deletions mods/default/functions.lua
Expand Up @@ -497,46 +497,6 @@ minetest.register_abm({
})


--
-- Checks if specified volume intersects a protected volume
--

function default.intersects_protection(minp, maxp, player_name, interval)
-- 'interval' is the largest allowed interval for the 3D lattice of checks

-- 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 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
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

for zf = minp.z, maxp.z, d.z do
local z = math.floor(zf + 0.5)
for yf = minp.y, maxp.y, d.y do
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
end
end
end
end

return false
end


--
-- Coral death near air
--
Expand Down
7 changes: 7 additions & 0 deletions mods/default/legacy.lua
Expand Up @@ -37,3 +37,10 @@ end

-- Chests
default.register_chest = default.chest.register_chest

-- Check for a volume intersecting protection
function default.intersects_protection(minp, maxp, player_name, interval)
minetest.log("warning", "default.intersects_protection() is " ..
"deprecated, use minetest.intersects_protection() instead.")
minetest.intersects_protection(minp, maxp, player_name, interval)
end
2 changes: 1 addition & 1 deletion mods/default/trees.lua
Expand Up @@ -490,7 +490,7 @@ function default.sapling_on_place(itemstack, placer, pointed_thing,
return itemstack
end
-- Check tree volume for protection
if default.intersects_protection(
if minetest.intersects_protection(
vector.add(pos, minp_relative),
vector.add(pos, maxp_relative),
player_name,
Expand Down

0 comments on commit 8f85ca5

Please sign in to comment.