Add handler for other mods to advise protection

* Allow other mods to register a handler to display protected areas in the hud
* remove the protector mod specific code from this areas code
This commit is contained in:
Tai @ Flex 2016-11-26 12:14:30 +00:00
parent e1e719b1d6
commit dedd0ebf6e
1 changed files with 14 additions and 19 deletions

33
api.lua
View File

@ -1,30 +1,25 @@
local protection_detectors = {}
local get_protector_area = function(pos) areas.register_protector_detector = function(handler)
-- Add protector to the hud protection_detectors[#protection_detectors+1] = handler
local res = {} end
local radius = (tonumber(minetest.setting_get("protector_radius")) or 5)
local protectors = minetest.find_nodes_in_area( local detect_extra_protection = function(pos,res)
{x=pos.x -radius , y=pos.y -radius , z=pos.z -radius}, if #protection_detectors <= 0 then
{x=pos.x +radius , y=pos.y +radius , z=pos.z +radius}, return res
{"protector:protect","protector:protect2"} end
)
for _,npos in pairs(protectors) do for idx=1,#protection_detectors do
local node = minetest.get_node(npos) local func = protection_detectors[idx]
local meta = minetest.get_meta(npos) res = func(pos,res)
local nodeowner = meta:get_string("owner")
if minetest.is_protected(pos,nodeowner) then
res["protector"] = {name="("..node.name..")",owner=nodeowner}
break
end
end end
return res return res
end end
-- //
--- Returns a list of areas that include the provided position. --- Returns a list of areas that include the provided position.
function areas:getAreasAtPos(pos) function areas:getAreasAtPos(pos)
local res = {} local res = {}
--res = get_protector_area(pos) res = detect_extra_protection(pos,res)
if self.store then if self.store then
local a = self.store:get_areas_for_pos(pos, false, true) local a = self.store:get_areas_for_pos(pos, false, true)