mirror of
https://github.com/minetest-mods/areas.git
synced 2025-03-31 01:30:38 +02:00
Add improvements by taikedz and EdwardThorsten
* add protector blocks to hud * change from unknown source * add mod explicit name * 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 * support non-numeric IDs * adjusted handler registration name * add API documentation for modding extension * rename to explicit variables * De-couple from original code * `api.lua` create separate handler for listing registered nodes, leave the areas list clean * `hud.lua` call second handler separately * `api.md` extended and clarified documentaion * fixed typo in documentation * ignore vim cache files * adjust handler registration function name * reinstate the format string unsigned int] * reverting auth change * restore code style, adjust further style * added space for stylistic imrpovement * stylistic fixes etc * Merge branch 'master' of https://github.com/ShadowNinja/areas *Merge ShadowNinja's version * Cleaning up deprecated calls. * Merge pull request #1 from EdwardThorsten/master *Cleaning up deprecated calls.
This commit is contained in:
commit
41bba581a2
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,2 +1,3 @@
|
|||||||
*~
|
*~
|
||||||
|
*.swp
|
||||||
|
|
||||||
|
6
api.lua
6
api.lua
@ -29,9 +29,9 @@ function areas:getAreasAtPos(pos)
|
|||||||
for id, area in pairs(self.areas) do
|
for id, area in pairs(self.areas) do
|
||||||
local ap1, ap2 = area.pos1, area.pos2
|
local ap1, ap2 = area.pos1, area.pos2
|
||||||
if
|
if
|
||||||
(px >= ap1.x and px <= ap2.x) and
|
(px >= ap1.x and px <= ap2.x) and
|
||||||
(py >= ap1.y and py <= ap2.y) and
|
(py >= ap1.y and py <= ap2.y) and
|
||||||
(pz >= ap1.z and pz <= ap2.z) then
|
(pz >= ap1.z and pz <= ap2.z) then
|
||||||
res[id] = area
|
res[id] = area
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
47
api.md
47
api.md
@ -1,3 +1,50 @@
|
|||||||
|
# API Extension
|
||||||
|
|
||||||
|
Adding your protections to the HUD
|
||||||
|
----------------------------------
|
||||||
|
|
||||||
|
If you are providing an extra protection mod to work in conjunction with the
|
||||||
|
HUD feature of `areas`, you can register a callback to add your mod's code to
|
||||||
|
display your protection's existence.
|
||||||
|
|
||||||
|
Registering a handler:
|
||||||
|
|
||||||
|
* `areas.registerHudHandler(handler) --> nil`
|
||||||
|
|
||||||
|
Handler specification:
|
||||||
|
|
||||||
|
* `handler(pos,area_list) --> new_area_list`
|
||||||
|
* `pos` - the position at which to check for protection coverage by your mod
|
||||||
|
* `area_list` - the current list of protected areas
|
||||||
|
* `new_area_list` - the list of protected areas, updated with your entries
|
||||||
|
|
||||||
|
Area list items:
|
||||||
|
|
||||||
|
The area list item is a map table identified with an ID, and properties
|
||||||
|
|
||||||
|
The ID should be in the format `modname:` and appended with an identifier for the protection.
|
||||||
|
|
||||||
|
Each area list item should be a table with the following properties
|
||||||
|
|
||||||
|
* `owner` - (required) the name of the protection owner
|
||||||
|
* `name` - (optional) the name of the area
|
||||||
|
|
||||||
|
Example
|
||||||
|
-------
|
||||||
|
|
||||||
|
local myhandler = function(pos,area_list)
|
||||||
|
local areaowner = find_my_protections(pos)
|
||||||
|
|
||||||
|
if areaowner then
|
||||||
|
arealist["mymodname:first"] = {
|
||||||
|
name = "Protection name",
|
||||||
|
owner = areaowner,
|
||||||
|
}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
areas.register_hud_handler(myhandler)
|
||||||
|
=======
|
||||||
Areas mod API
|
Areas mod API
|
||||||
===
|
===
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user