From feae9967dcedd4b49170ef6c91b28b25c9ca076f Mon Sep 17 00:00:00 2001 From: sys4 Date: Sat, 28 Dec 2019 02:43:12 +0100 Subject: [PATCH] Ajoute certaines modifications venant de MFF + ajustement HUD MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Aires openfarming * Privilège megabuilder * HUD légèrement modifié pour laisser de la place à celui de factions --- api.lua | 27 +++++++++++++++++++++++++++ chatcommands.lua | 22 ++++++++++++++++++++++ hud.lua | 4 ++-- internal.lua | 48 ++++++++++++++++++++++++++---------------------- 4 files changed, 77 insertions(+), 24 deletions(-) diff --git a/api.lua b/api.lua index 40a9841..3df4eb2 100644 --- a/api.lua +++ b/api.lua @@ -1,5 +1,14 @@ local hudHandlers = {} +---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", +} areas.registered_on_adds = {} areas.registered_on_removes = {} @@ -94,6 +103,24 @@ 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 + 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 elseif areas.factions_available and area.faction_open then local faction_name = factions.get_player_faction(area.owner) if faction_name ~= nil and faction_name == factions.get_player_faction(name) then diff --git a/chatcommands.lua b/chatcommands.lua index faffb03..17910c3 100644 --- a/chatcommands.lua +++ b/chatcommands.lua @@ -286,6 +286,28 @@ minetest.register_chatcommand("area_open", { }) +minetest.register_chatcommand( + "area_openfarming", { + params = "", + description = "Toggle an area as open farming (anyone can harvest and plant) 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 open = not areas.areas[id].openfarming + -- Save false as nil to avoid inflating the DB. + areas.areas[id].openfarming = open or nil + areas:save() + return true, ("Area %s to farming."):format(open and "opened" or "closed") + end +}) + if areas.factions_available then minetest.register_chatcommand("area_faction_open", { params = "", diff --git a/hud.lua b/hud.lua index ffe764e..5a76ac7 100644 --- a/hud.lua +++ b/hud.lua @@ -26,7 +26,7 @@ minetest.register_globalstep(function(dtime) area.faction_open = faction_info table.insert(areaStrings, ("%s [%u] (%s%s%s)") :format(area.name, id, area.owner, - area.open and ":open" or "", + area.open and ":open" or area.openfarming and ":openfarming" or "", faction_info and ":"..faction_info or "")) end @@ -52,7 +52,7 @@ minetest.register_globalstep(function(dtime) name = "Areas", number = 0xFFFFFF, position = {x=0, y=1}, - offset = {x=8, y=-8}, + offset = {x=8, y=-24}, text = areaString, scale = {x=200, y=60}, alignment = {x=1, y=-1}, diff --git a/internal.lua b/internal.lua index 27f85ed..0717c22 100644 --- a/internal.lua +++ b/internal.lua @@ -1,3 +1,5 @@ +-- Mega_builder privilege +minetest.register_privilege("megabuilder", "Can protect an infinite amount of areas.") function areas:player_exists(name) return minetest.get_auth_handler().get_auth(name) ~= nil @@ -216,39 +218,41 @@ function areas:canPlayerAddArea(pos1, pos2, name) .." the necessary privilege." end - local max_size = privs.areas_high_limit and + -- MFF: megabuilders skip checks on size and number of areas + if not privs.megabuilder then + local max_size = privs.areas_high_limit and self.config.self_protection_max_size_high or self.config.self_protection_max_size - if + if (pos2.x - pos1.x) > max_size.x or (pos2.y - pos1.y) > max_size.y or - (pos2.z - pos1.z) > max_size.z then - return false, "Area is too big." - end - - -- Check number of areas the user has and make sure it not above the max - local count = 0 - for _, area in pairs(self.areas) do - if area.owner == name then - count = count + 1 + (pos2.z - pos1.z) > max_size.z then + return false, "Area is too big." end - end - local max_areas = privs.areas_high_limit and + + -- Check number of areas the user has and make sure it not above the max + local count = 0 + for _, area in pairs(self.areas) do + if area.owner == name then + count = count + 1 + end + end + local max_areas = privs.areas_high_limit and self.config.self_protection_max_areas_high or self.config.self_protection_max_areas - if count >= max_areas then - return false, "You have reached the maximum amount of" + if count >= max_areas then + return false, "You have reached the maximum amount of" .." areas that you are allowed to protect." - end + end - -- Check intersecting areas - local can, id = self:canInteractInArea(pos1, pos2, name) - if not can then - local area = self.areas[id] - return false, ("The area intersects with %s [%u] (%s).") + -- Check intersecting areas + local can, id = self:canInteractInArea(pos1, pos2, name) + if not can then + local area = self.areas[id] + return false, ("The area intersects with %s [%u] (%s).") :format(area.name, id, area.owner) + end end - return true end