mirror of
https://github.com/minetest-mods/areas.git
synced 2024-12-27 11:10:40 +01:00
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:
parent
e1e719b1d6
commit
dedd0ebf6e
33
api.lua
33
api.lua
@ -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)
|
||||||
|
Loading…
Reference in New Issue
Block a user