forked from mt-mods/jumpdrive
-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
is_area_protected.lua
50 lines (41 loc) · 1.26 KB
/
is_area_protected.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
local has_areas_mod = minetest.get_modpath("areas")
local has_protector_mod = minetest.get_modpath("protector")
local protector_radius = (tonumber(minetest.settings:get("protector_radius")) or 5)
jumpdrive.is_area_protected = function(pos1, pos2, playername)
local radius_vector = {x=protector_radius, y=protector_radius, z=protector_radius}
local check_pos1 = vector.subtract(pos1, radius_vector)
local check_pos2 = vector.add(pos2, radius_vector)
-- preload area with voxel manip
minetest.get_voxel_manip(check_pos1, check_pos2)
if minetest.is_area_protected then
-- use area protection check
if minetest.is_area_protected(pos1, pos2, playername, 8) then
return true
end
elseif has_protector_mod then
-- use improvised find_nodes check
local protectors = minetest.find_nodes_in_area(
check_pos1, check_pos2, {
"protector:protect",
"protector:protect2",
"priv_protector:protector",
"xp_redo:protector"
}
)
if protectors then
for _,pos in pairs(protectors) do
if minetest.is_protected(pos, playername) then
return true
end
end
end
end
if has_areas_mod then
if not areas:canInteractInArea(pos1, pos2, playername, true) then
-- player can't interact
return true
end
end
-- no protection
return false
end