From 7f277db7ac2e5e6f378f3ee4b2d7440d24355065 Mon Sep 17 00:00:00 2001 From: sys4 Date: Thu, 20 Mar 2025 00:08:37 +0100 Subject: [PATCH] Optimize openfarming check --- api.lua | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/api.lua b/api.lua index 8c181ab..bca1508 100644 --- a/api.lua +++ b/api.lua @@ -132,7 +132,7 @@ function areas:getSmallestAreaAtPos(pos) return smallest_area, smallest_id end --- Checks if the area is unprotected, open, owned by player +-- Checks if the area is unprotected, open[farming], owned by player -- or player is part of faction of [smallest] area at position. function areas:canInteract(pos, name) if minetest.check_player_privs(name, self.adminPrivs) then @@ -146,13 +146,13 @@ function areas:canInteract(pos, name) areas_list = self:getAreasAtPos(pos) end local owned = false + local player = minetest.get_player_by_name(name) + local node = minetest.get_node(pos).name for _, area in pairs(areas_list) do -- Player owns the area or area is open if area.owner == name or area.open then return true elseif area.openfarming then -- If area is openfarming - local player = minetest.get_player_by_name(name) - local node = minetest.get_node(pos).name if player and minetest.registered_nodes[node] then local wstack = player:get_wielded_item():get_name() if wstack == "" then wstack = "hand" end