From 5b50003c319802678d22c35d0da30efcf64d731f Mon Sep 17 00:00:00 2001 From: Pedro Gimeno Date: Tue, 29 Mar 2016 05:03:17 +0200 Subject: [PATCH] Allow excluding items made for the circular saw from the recipes list The circular saw in the moreblocks mod adds many recipes that take smaller blocks and output a bigger block. This commit adds an option (unified_inventory.exclude_saw_recipes) to not list the recipes of items that are made for the saw. It may be imperfect because the saw items are not very uniquely named. --- api.lua | 39 ++++++++++++++++++++++++++++++++++++++- depends.txt | 2 +- 2 files changed, 39 insertions(+), 2 deletions(-) diff --git a/api.lua b/api.lua index 59296db..9fd129c 100644 --- a/api.lua +++ b/api.lua @@ -7,6 +7,28 @@ minetest.after(0.01, function() if not rev_aliases[target] then rev_aliases[target] = {} end table.insert(rev_aliases[target], source) end + + local circular_saw_patterns = {} + if minetest.setting_getbool("unified_inventory.exclude_saw_recipes") + and rawget(_G, "circular_saw") then + -- Make a list of different patterns that when found in a node + -- name, it's assumed to mean that they are registered by the + -- circular saw. At the time of writing, that list is: + -- ":stair_", ":panel_", ":micro_", ":slab_", ":slope_" + -- Unfortunately, "" is included as a suffix, which prevents + -- refining the search by matching by suffix too. + + local circular_saw_words = {} + -- Find unique prefix words in circular_saw.names + for _, v in ipairs(circular_saw.names) do + circular_saw_words[v[1]] = true + end + + -- Make a sequence with the unique names + for k, _ in pairs(circular_saw_words) do + circular_saw_patterns[#circular_saw_patterns + 1] = ":" .. k .. "_" + end + end unified_inventory.items_list = {} for name, def in pairs(minetest.registered_items) do if (not def.groups.not_in_creative_inventory or @@ -21,16 +43,31 @@ minetest.after(0.01, function() for _, recipe in ipairs(recipes) do local unknowns + local has_non_saw_element for _,chk in pairs(recipe.items) do local groupchk = string.find(chk, "group:") if (not groupchk and not minetest.registered_items[chk]) or (groupchk and not unified_inventory.get_group_item(string.gsub(chk, "group:", "")).item) then unknowns = true + break -- no point checking further + end + + local found + -- check if node name matches any of the patterns + for _,v in ipairs(circular_saw_patterns) do + if chk:find(v, 1, true) then + found = true + break + end + end + if not found then + has_non_saw_element = true + break end end - if not unknowns then + if not unknowns and has_non_saw_element then unified_inventory.register_craft(recipe) end end diff --git a/depends.txt b/depends.txt index a1ea556..8feab91 100644 --- a/depends.txt +++ b/depends.txt @@ -1,4 +1,4 @@ creative? intllib? datastorage? - +moreblocks?