From 1cf4e252f9b0c84718a145e163e424c03335a744 Mon Sep 17 00:00:00 2001 From: crabman77 Date: Mon, 2 Mar 2015 19:19:42 +0100 Subject: [PATCH] added news area openfarming added area openfarming, anyone can interact only with farming mod(group plant). added chatcommand area_openfarming "/area_openfarming ". added display in hud when area is open to farming. --- mods/areas/README.md | 4 ++++ mods/areas/api.lua | 7 +++++++ mods/areas/chatcommands.lua | 23 +++++++++++++++++++++++ mods/areas/hud.lua | 2 +- 4 files changed, 35 insertions(+), 1 deletion(-) diff --git a/mods/areas/README.md b/mods/areas/README.md index 86792d2c..5fb85a34 100755 --- a/mods/areas/README.md +++ b/mods/areas/README.md @@ -90,6 +90,10 @@ Chat commands * /area\_pos2 \[X,Y,Z|X Y Z\] Sets area position two to your position or the one supplied. + * `/area_open ` -- Sets the area open, anyone can interact. + + * `/area_openfarming ` -- Sets the area openfarming, anyone can interact only farming mod. + License ------- Copyright (C) 2013 ShadowNinja diff --git a/mods/areas/api.lua b/mods/areas/api.lua index 0311c492..9caedae5 100755 --- a/mods/areas/api.lua +++ b/mods/areas/api.lua @@ -25,6 +25,13 @@ function areas:canInteract(pos, name) 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 and node is in group plant, action is authorized + local node = minetest.get_node(pos).name + if minetest.registered_nodes[node] and minetest.get_item_group(node, "plant") == 1 then + return true + end + return false else owned = true end diff --git a/mods/areas/chatcommands.lua b/mods/areas/chatcommands.lua index aa3d2a0c..eeae74f5 100755 --- a/mods/areas/chatcommands.lua +++ b/mods/areas/chatcommands.lua @@ -285,6 +285,29 @@ minetest.register_chatcommand("area_open", { end }) + +minetest.register_chatcommand("area_openfarming", { + params = "", + description = "Toggle an area open (anyone can interact farming) or closed", + func = function(name, param) + local id = tonumber(param) + if not id then + return false, "Invalid usage, see /help area_openfarming." + end + + if not areas:isAreaOwner(id, name) then + return false, "Area "..id.." does not exist" + .." or is not owned by you." + end + local openfarming = not areas.areas[id].openfarming + -- Save false as nil to avoid inflating the DB. + areas.areas[id].openfarming = openfarming or nil + areas:save() + return true, ("Area %s to farming."):format(openfarming and "opened" or "closed") + end +}) + + minetest.register_chatcommand("move_area", { params = "", description = "Move (or resize) an area to the current positions.", diff --git a/mods/areas/hud.lua b/mods/areas/hud.lua index 4d04030f..1a7e04ef 100755 --- a/mods/areas/hud.lua +++ b/mods/areas/hud.lua @@ -10,7 +10,7 @@ minetest.register_globalstep(function(dtime) for id, area in pairs(areas:getAreasAtPos(pos)) do table.insert(areaStrings, ("%s [%u] (%s%s)") :format(area.name, id, area.owner, - area.open and ":open" or "")) + area.open and ":open" or area.openfarming and ":open to farming" or "")) end local areaString = "Areas:" if #areaStrings > 0 then