2015-01-08 22:21:44 +01:00
|
|
|
|
2015-03-16 02:30:48 +01:00
|
|
|
--plants to place in openfarming
|
2016-05-05 15:25:08 +02:00
|
|
|
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",
|
2015-03-16 22:08:35 +01:00
|
|
|
}
|
2015-03-16 02:30:48 +01:00
|
|
|
|
2014-10-28 18:01:32 +01:00
|
|
|
-- Returns a list of areas that include the provided position
|
|
|
|
function areas:getAreasAtPos(pos)
|
|
|
|
local a = {}
|
2015-01-08 22:21:44 +01:00
|
|
|
local px, py, pz = pos.x, pos.y, pos.z
|
2015-10-27 11:40:52 +01:00
|
|
|
if self.store then
|
|
|
|
local areas = self.store:get_areas_for_pos(pos, false, true)
|
|
|
|
for store_id, store_area in pairs(areas) do
|
|
|
|
local id = tonumber(store_area.data)
|
|
|
|
a[id] = self.areas[id]
|
|
|
|
end
|
|
|
|
else
|
|
|
|
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
|
|
|
|
a[id] = area
|
|
|
|
end
|
2014-10-28 18:01:32 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
return a
|
|
|
|
end
|
|
|
|
|
2015-10-27 11:40:52 +01:00
|
|
|
function areas:getAreasForArea(pos1, pos2)
|
|
|
|
local res = {}
|
|
|
|
if self.store then
|
|
|
|
local areas = self.store:get_areas_in_area(pos1,
|
|
|
|
pos2, true, false, true)
|
|
|
|
for store_id, store_area in pairs(areas) do
|
|
|
|
local id = tonumber(store_area.data)
|
|
|
|
res[id] = self.areas[id]
|
|
|
|
end
|
|
|
|
else
|
|
|
|
for id, area in pairs(self.areas) do
|
|
|
|
local p1, p2 = area.pos1, area.pos2
|
|
|
|
if (p1.x <= pos2.x and p2.x >= pos1.x) and
|
|
|
|
(p1.y <= pos2.y and p2.y >= pos1.y) and
|
|
|
|
(p1.z <= pos2.z and p2.z >= pos1.z) then
|
|
|
|
-- Found an intersecting area.
|
|
|
|
res[id] = area
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return res
|
|
|
|
end
|
|
|
|
|
2014-10-28 18:01:32 +01:00
|
|
|
-- Checks if the area is unprotected or owned by you
|
|
|
|
function areas:canInteract(pos, name)
|
|
|
|
if minetest.check_player_privs(name, self.adminPrivs) then
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
local owned = false
|
2014-11-02 20:26:31 +01:00
|
|
|
if pos == nil then return not owned end -- pour éviter crash avec nénuphar
|
2014-10-28 18:01:32 +01:00
|
|
|
for _, area in pairs(self:getAreasAtPos(pos)) do
|
|
|
|
if area.owner == name or area.open then
|
|
|
|
return true
|
2015-03-02 19:19:42 +01:00
|
|
|
elseif area.openfarming then
|
2015-03-16 02:30:48 +01:00
|
|
|
-- if area is openfarming
|
2015-03-02 19:19:42 +01:00
|
|
|
local node = minetest.get_node(pos).name
|
2015-03-16 02:30:48 +01:00
|
|
|
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
|
2015-06-10 17:14:58 +02:00
|
|
|
|
2015-10-26 23:48:36 +01:00
|
|
|
--on_dig
|
|
|
|
if minetest.get_item_group(node, "plant") == 1 and (wstack == "hand" or minetest.registered_tools[wstack]) then
|
2015-03-02 19:19:42 +01:00
|
|
|
return true
|
|
|
|
end
|
2015-06-10 17:14:58 +02:00
|
|
|
|
2015-10-26 23:48:36 +01:00
|
|
|
--on_place
|
2016-05-05 15:25:08 +02:00
|
|
|
if plants[wstack] ~= nil and plants[wstack] == node then
|
2015-03-16 02:30:48 +01:00
|
|
|
return true
|
|
|
|
end
|
2015-06-10 17:14:58 +02:00
|
|
|
|
2015-03-16 02:30:48 +01:00
|
|
|
owned = true
|
2014-10-28 18:01:32 +01:00
|
|
|
else
|
|
|
|
owned = true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return not owned
|
|
|
|
end
|
|
|
|
|
|
|
|
-- Returns a table (list) of all players that own an area
|
|
|
|
function areas:getNodeOwners(pos)
|
|
|
|
local owners = {}
|
|
|
|
for _, area in pairs(self:getAreasAtPos(pos)) do
|
|
|
|
table.insert(owners, area.owner)
|
|
|
|
end
|
|
|
|
return owners
|
|
|
|
end
|
|
|
|
|
|
|
|
--- Checks if the area intersects with an area that the player can't interact in.
|
|
|
|
-- Note that this fails and returns false when the specified area is fully
|
2015-01-08 22:21:44 +01:00
|
|
|
-- owned by the player, but with multiple protection zones, none of which
|
2014-10-28 18:01:32 +01:00
|
|
|
-- cover the entire checked area.
|
|
|
|
-- @param name (optional) player name. If not specified checks for any intersecting areas.
|
2015-01-08 22:21:44 +01:00
|
|
|
-- @param allow_open Whether open areas should be counted as is they didn't exist.
|
2014-10-28 18:01:32 +01:00
|
|
|
-- @return Boolean indicating whether the player can interact in that area.
|
|
|
|
-- @return Un-owned intersecting area id, if found.
|
2015-01-08 22:21:44 +01:00
|
|
|
function areas:canInteractInArea(pos1, pos2, name, allow_open)
|
2014-10-28 18:01:32 +01:00
|
|
|
if name and minetest.check_player_privs(name, self.adminPrivs) then
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
areas:sortPos(pos1, pos2)
|
2015-10-27 11:40:52 +01:00
|
|
|
|
|
|
|
local areas = self:getAreasForArea(pos1, pos2)
|
|
|
|
for id, area in pairs(areas) do
|
|
|
|
-- First check for a fully enclosing owned area.
|
|
|
|
-- A little optimization: isAreaOwner isn't necessary
|
|
|
|
-- here since we're iterating through all relevant areas.
|
|
|
|
if area.owner == name and
|
|
|
|
self:isSubarea(pos1, pos2, id) then
|
|
|
|
return true
|
2014-10-28 18:01:32 +01:00
|
|
|
end
|
2015-10-27 11:40:52 +01:00
|
|
|
|
|
|
|
-- Then check for intersecting (non-owned) areas.
|
|
|
|
-- Return if the area is closed or open areas aren't
|
|
|
|
-- allowed, and the area isn't owned.
|
|
|
|
if (not allow_open or not area.open) and
|
|
|
|
(not name or not self:isAreaOwner(id, name)) then
|
|
|
|
return false, id
|
2014-10-28 18:01:32 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
2015-09-18 20:11:56 +02:00
|
|
|
|
2016-02-25 12:40:02 +01:00
|
|
|
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:getAreasForArea(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
|
|
|
|
|
2015-09-18 20:11:56 +02:00
|
|
|
|
2016-03-05 16:37:10 +01:00
|
|
|
--MFF crabman(5/03/2016 ) return special area pos if a spawn is set.
|
2016-01-08 00:53:14 +01:00
|
|
|
--1 party (2 party in beds mod)
|
2016-03-05 16:37:10 +01:00
|
|
|
function areas:getSpawn(pos)
|
|
|
|
for _, area in pairs(areas:getAreasAtPos(pos)) do
|
|
|
|
if area.spawn and area.spawn.x then
|
|
|
|
return area.spawn
|
2015-09-18 20:11:56 +02:00
|
|
|
end
|
|
|
|
end
|
2016-03-05 16:37:10 +01:00
|
|
|
return nil
|
2016-01-08 00:53:14 +01:00
|
|
|
end
|