Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(Mistake, please delete) #29

Closed
wants to merge 35 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
45afbfe
add protector blocks to hud
taikedz Nov 26, 2016
2f802bf
change from unknown source
taikedz Nov 26, 2016
e1e719b
add mod explicit name
taikedz Nov 26, 2016
dedd0eb
Add handler for other mods to advise protection
taikedz Nov 26, 2016
e4ac30b
support non-numeric IDs
taikedz Nov 26, 2016
6708c96
adjusted handler registration name
taikedz Nov 26, 2016
77a30f9
commentary
taikedz Nov 26, 2016
70ed7e3
add API documentation for modding extension
taikedz Nov 26, 2016
4eda120
rename to explicit variables
taikedz Nov 26, 2016
60d7a41
De-couple from original code
taikedz Nov 26, 2016
73cb4c4
fixed typo in documentation
taikedz Nov 28, 2016
83dcc44
ignore vim cache files
taikedz Nov 28, 2016
812917f
adjust handler registration function name
taikedz Nov 28, 2016
64ec6ff
reinstate the format string unsigned int]
taikedz Nov 28, 2016
bb10d0c
reverting auth change
taikedz Nov 28, 2016
9fc3583
restore code style, adjust further style
taikedz Nov 28, 2016
ea0d14d
added space for stylistic imrpovement
taikedz Nov 28, 2016
5349738
stylistic fixes etc
taikedz Dec 19, 2016
767d8ff
Merge branch 'master' of https://github.com/ShadowNinja/areas
taikedz Dec 19, 2016
ebc6f8b
Cleaning up deprecated calls.
EdwardThorsten Oct 2, 2017
0ec2755
Merge pull request #1 from EdwardThorsten/master
taikedz Oct 2, 2017
d90fa73
Use the new `minetest.safe_file_write` API if possible when saving da…
red-001 Feb 4, 2018
6cad881
update player location
alexerate Feb 5, 2018
b0de983
function anti_lag added
alexerate Feb 5, 2018
0b96f75
Add delay for anti_lag
alexerate Feb 5, 2018
599d935
remove obsolet code
alexerate Feb 6, 2018
52011bd
localisation
alexerate Feb 6, 2018
a9b9543
utf-8
alexerate Feb 6, 2018
93df2f3
make self_protection true by default
alexerate Feb 7, 2018
2095ec9
Improvement from red-001
Feb 16, 2018
86a7b76
Improvements from alexerate
Feb 16, 2018
41bba58
Add improvements by taikedz and EdwardThorsten
Feb 16, 2018
a23d2ba
Manual update due to conflict
Feb 16, 2018
132b528
Manual update due to conflict (part 2)
Feb 16, 2018
1eb4c76
Manual update due to conflict (part 3)
Feb 16, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
*~
*.swp

114 changes: 111 additions & 3 deletions api.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@ function areas:getExternalHudEntries(pos)
return areas
end

--plants to place in openfarming
local plants = { ["farming:blueberries"]="air", ["farming:carrot"]="air", ["farming:coffee_beans"]="air", ["farming:corn"]="air", ["farming:cucumber"]="air",
["farming:melon_slice"]="air", ["farming:potato"]="air", ["farming:pumpkin_slice"]="air", ["farming:raspberries"]="air", ["farming:rhubarb"]="air",
["farming:tomato"]="air", ["farming:seed_cotton"]="air", ["farming:seed_wheat"]="air",["default:papyrus"]="air", ["farming:trellis"]="air",
["farming:grapes"]="farming:trellis", ["farming:beanpole"]="air", ["farming:beans"]="farming:beanpole",
}

--- Returns a list of areas that include the provided position.
function areas:getAreasAtPos(pos)
local res = {}
Expand All @@ -29,9 +36,9 @@ function areas:getAreasAtPos(pos)
for id, area in pairs(self.areas) do
local ap1, ap2 = area.pos1, area.pos2
if
(px >= ap1.x and px <= ap2.x) and
(py >= ap1.y and py <= ap2.y) and
(pz >= ap1.z and pz <= ap2.z) then
(px >= ap1.x and px <= ap2.x) and
(py >= ap1.y and py <= ap2.y) and
(pz >= ap1.z and pz <= ap2.z) then
res[id] = area
end
end
Expand Down Expand Up @@ -73,16 +80,117 @@ function areas:canInteract(pos, name)
return true
end
local owned = false

-- to avoid crash with water lily
if pos == nil then
return not owned
end

for _, area in pairs(self:getAreasAtPos(pos)) do
if area.owner == name or area.open then
return true

elseif area.openfarming then
-- if area is openfarming
local node = minetest.get_node(pos).name
if not minetest.registered_nodes[node] then
return false
end
local player = minetest.get_player_by_name(name)
if not player then
return false
end
local wstack = player:get_wielded_item():get_name()
if wstack == "" then
wstack = "hand"
end

--on_dig
if minetest.get_item_group(node, "plant") == 1 and (wstack == "hand" or minetest.registered_tools[wstack]) then
return true
end

--on_place
if plants[wstack] ~= nil and plants[wstack] == node then
return true
end

owned = true
else
owned = true
end
end
return not owned
end

function areas:canMakeArea(pos1, pos2, name) --MFF crabman(25/02/2016) fix areas in areas
if name and minetest.check_player_privs(name, self.adminPrivs) then
return true
end
areas:sortPos(pos1, pos2)

local id_areas_intersect = {}
local areas = self:getAreasIntersectingArea(pos1, pos2)

if not areas then return true end

for id, area in pairs(areas) do
if area.owner == name and self:isSubarea(pos1, pos2, id) then
return true
end
if not area.open and not self:isAreaOwner(id, name) then
table.insert(id_areas_intersect, id)
end
end

if #id_areas_intersect > 0 then
return false, id_areas_intersect[1]
end

return true
end


--MFF crabman(5/03/2016 ) return special area pos if a spawn is set.
--1 party (2 party in beds mod)
function areas:getSpawn(pos)
for _, area in pairs(areas:getAreasAtPos(pos)) do
if area.spawn and area.spawn.x then
return area.spawn
end
end
return nil
end

--MFF DEBUT crabman(17/09/2015 ) respawn player in special area(event) if a spawn is set.
--1 party (2 party in beds mod)
local dead_players = {}
minetest.register_on_dieplayer(function(player)
local player_name = player:get_player_name()
if not player_name then return end
local pos = player:getpos()
if pos then
dead_players[player_name] = pos
end
end)


function areas:onRespawn(player)
local player_name = player:get_player_name()
if not player_name or not dead_players[player_name] then return false end
local pos = dead_players[player_name]
dead_players[player_name] = nil
if pos then
for _, area in pairs(areas:getAreasAtPos(pos)) do
if area.spawn then
player:setpos(area.spawn)
return true
end
end
end
return false
end

-- Returns a table (list) of all players that own an area
function areas:getNodeOwners(pos)
local owners = {}
Expand Down
47 changes: 47 additions & 0 deletions api.md
Original file line number Diff line number Diff line change
@@ -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
===

Expand Down
Loading