Skip to content

Commit 8f85ca5

Browse files
committedFeb 3, 2018
Intersects_protection(): Remove from Minetest Game
Add compatibility code with deprecation warning.
1 parent 496a1a2 commit 8f85ca5

File tree

3 files changed

+8
-41
lines changed

3 files changed

+8
-41
lines changed
 

‎mods/default/functions.lua

-40
Original file line numberDiff line numberDiff line change
@@ -497,46 +497,6 @@ minetest.register_abm({
497497
})
498498

499499

500-
--
501-
-- Checks if specified volume intersects a protected volume
502-
--
503-
504-
function default.intersects_protection(minp, maxp, player_name, interval)
505-
-- 'interval' is the largest allowed interval for the 3D lattice of checks
506-
507-
-- Compute the optimal float step 'd' for each axis so that all corners and
508-
-- borders are checked. 'd' will be smaller or equal to 'interval'.
509-
-- Subtracting 1e-4 ensures that the max co-ordinate will be reached by the
510-
-- for loop (which might otherwise not be the case due to rounding errors).
511-
local d = {}
512-
for _, c in pairs({"x", "y", "z"}) do
513-
if maxp[c] > minp[c] then
514-
d[c] = (maxp[c] - minp[c]) / math.ceil((maxp[c] - minp[c]) / interval) - 1e-4
515-
elseif maxp[c] == minp[c] then
516-
d[c] = 1 -- Any value larger than 0 to avoid division by zero
517-
else -- maxp[c] < minp[c], print error and treat as protection intersected
518-
minetest.log("error", "maxp < minp in 'default.intersects_protection()'")
519-
return true
520-
end
521-
end
522-
523-
for zf = minp.z, maxp.z, d.z do
524-
local z = math.floor(zf + 0.5)
525-
for yf = minp.y, maxp.y, d.y do
526-
local y = math.floor(yf + 0.5)
527-
for xf = minp.x, maxp.x, d.x do
528-
local x = math.floor(xf + 0.5)
529-
if minetest.is_protected({x = x, y = y, z = z}, player_name) then
530-
return true
531-
end
532-
end
533-
end
534-
end
535-
536-
return false
537-
end
538-
539-
540500
--
541501
-- Coral death near air
542502
--

‎mods/default/legacy.lua

+7
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,10 @@ end
3737

3838
-- Chests
3939
default.register_chest = default.chest.register_chest
40+
41+
-- Check for a volume intersecting protection
42+
function default.intersects_protection(minp, maxp, player_name, interval)
43+
minetest.log("warning", "default.intersects_protection() is " ..
44+
"deprecated, use minetest.intersects_protection() instead.")
45+
minetest.intersects_protection(minp, maxp, player_name, interval)
46+
end

‎mods/default/trees.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -490,7 +490,7 @@ function default.sapling_on_place(itemstack, placer, pointed_thing,
490490
return itemstack
491491
end
492492
-- Check tree volume for protection
493-
if default.intersects_protection(
493+
if minetest.intersects_protection(
494494
vector.add(pos, minp_relative),
495495
vector.add(pos, maxp_relative),
496496
player_name,

0 commit comments

Comments
 (0)
Please sign in to comment.