From ae7a04b56f530a2566cea8cfee971ac39b8f8a5c Mon Sep 17 00:00:00 2001 From: Wuzzy Date: Fri, 30 Aug 2019 01:09:18 +0200 Subject: [PATCH] Crafting: Add group support back --- mods/crafting/api.lua | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/mods/crafting/api.lua b/mods/crafting/api.lua index 7953911..1e6e2d0 100644 --- a/mods/crafting/api.lua +++ b/mods/crafting/api.lua @@ -81,12 +81,21 @@ function crafting.get_crafts(player_inventory) local contains_all = true for c=1, #craftdef.items do local name = craftdef.items[c]:get_name() - -- TODO: Add group support if string.sub(name, 1, 6) == "group:" then - contains_all = false - break - end - if not player_inventory:contains_item("craft_in", craftdef.items[c]) then + local group = string.sub(name, 7) + local gcount = craftdef.items[c]:get_count() + local items_in = player_inventory:get_list("craft_in") + local count = 0 + for i=1, #items_in do + if minetest.get_item_group(items_in[i]:get_name(), group) ~= 0 then + count = count + items_in[i]:get_count() + end + end + if count < gcount then + contains_all = false + break + end + elseif not player_inventory:contains_item("craft_in", craftdef.items[c]) then contains_all = false break end