diff --git a/init.lua b/init.lua index e2ba69d..155c139 100644 --- a/init.lua +++ b/init.lua @@ -1,5 +1,11 @@ local reg_items = minetest.registered_items +local revealed_cache = {} + +minetest.register_on_leaveplayer(function(player) + revealed_cache[player:get_player_name()] = nil +end) + local function item_has_groups(item_groups, groups) for i = 1, #groups do local group = groups[i] @@ -11,30 +17,43 @@ local function item_has_groups(item_groups, groups) end local function revealed_show_recipe(recipe, playername) + if not revealed_cache[playername] then + revealed_cache[playername] = {} + end + if revealed_cache[playername][recipe] then + return true + end + local revealed = doc.data.players[playername].stored_data.revealed for _, item in pairs(recipe.items) do - local is_revealed_item + local is_revealed_item = false if item:sub(1,6) == "group:" then local groups = item:sub(7):split(",") for cid, items in pairs(revealed) do for revealed_item in pairs(items) do if reg_items[revealed_item] and item_has_groups(reg_items[revealed_item].groups, groups) then is_revealed_item = true + break end end + if is_revealed_item then + break + end end else for cid, items in pairs(revealed) do if items[item] then is_revealed_item = true + break end end end if not is_revealed_item then - return + return false end end + revealed_cache[playername][recipe] = true return true end