jumpdrive-cd2025/is_area_protected.lua

43 lines
1.1 KiB
Lua
Raw Normal View History

2018-09-19 13:49:01 +02:00
local has_areas_mod = minetest.get_modpath("areas")
local has_protector_mod = minetest.get_modpath("protector")
2018-09-19 11:14:41 +02:00
2018-11-13 10:25:32 +01:00
local protector_radius = (tonumber(minetest.setting_get("protector_radius")) or 5)
2018-09-19 13:49:01 +02:00
jumpdrive.is_area_protected = function(pos1, pos2, playername)
2019-07-16 14:00:38 +02:00
if minetest.is_area_protected then
-- use area protection check
2019-07-20 15:37:56 +02:00
if minetest.is_area_protected(pos1, pos2, playername, 8) then
2019-07-16 14:00:38 +02:00
return true
end
elseif has_protector_mod then
-- use improvised find_nodes check
2018-11-13 10:25:32 +01:00
local radius_vector = {x=protector_radius, y=protector_radius, z=protector_radius}
2018-09-19 13:49:01 +02:00
local protectors = minetest.find_nodes_in_area(
vector.subtract(pos1, radius_vector),
vector.add(pos2, radius_vector),
{"protector:protect", "protector:protect2"}
)
if protectors then
2018-09-19 17:10:57 +02:00
for _,pos in pairs(protectors) do
2018-09-19 13:49:01 +02:00
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
2018-09-19 17:10:57 +02:00
end