From 4979289ea6ce7b1342fb76564db33c63f5dcae4e Mon Sep 17 00:00:00 2001 From: Alexander Weber Date: Mon, 14 Jan 2019 20:27:52 +0100 Subject: [PATCH] initial version --- depends.txt | 2 ++ init.lua | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+) create mode 100644 depends.txt create mode 100644 init.lua diff --git a/depends.txt b/depends.txt new file mode 100644 index 0000000..27d7bf4 --- /dev/null +++ b/depends.txt @@ -0,0 +1,2 @@ +craftguide +doc_items diff --git a/init.lua b/init.lua new file mode 100644 index 0000000..e12be86 --- /dev/null +++ b/init.lua @@ -0,0 +1,51 @@ +local reg_items = minetest.registered_items + +local function item_has_groups(item_groups, groups) + for i = 1, #groups do + local group = groups[i] + if not item_groups[group] then + return + end + end + return true +end + +local function revealed_show_recipe(recipe, playername) + local revealed = doc.data.players[playername].stored_data.revealed + for _, item in pairs(recipe.items) do + local is_revealed_item + if item:sub(1,6) == "group:" then + local groups = item:sub(7):split(",") + for cid, items in pairs(revealed) do + for item in pairs(items) do + if item_has_groups(reg_items[item].groups, groups) then + is_revealed_item = true + end + end + end + else + for cid, items in pairs(revealed) do + if items[item] then + is_revealed_item = true + end + end + end + + if not is_revealed_item then + return + end + end + return true +end + + +function craftguide.progressive_filter_recipes(recipes, player) + local filtered = {} + for i = 1, #recipes do + local recipe = recipes[i] + if revealed_show_recipe(recipe, player:get_player_name()) then + filtered[#filtered + 1] = recipe + end + end + return filtered +end