diff --git a/craft_guide/api_craft_guide.lua b/craft_guide/api_craft_guide.lua index 59f6b49..e1f0b30 100644 --- a/craft_guide/api_craft_guide.lua +++ b/craft_guide/api_craft_guide.lua @@ -18,6 +18,7 @@ craft_guide = {} -- define api variables craft_guide.crafts = {} +craft_guide.groups = {} -- log @@ -227,90 +228,90 @@ craft_guide.update_recipe = function(meta, player, stack, alternate) -- cook if craft.type == "cooking" then - inv:set_stack("cook", 1, craft.recipe) + inv:set_stack("cook", 1, craft_guide.get_item_name(craft.recipe)) meta:set_string("formspec",craft_guide.get_craft_guide_formspec(meta)) return end -- fuel if craft.type == "fuel" then - inv:set_stack("fuel", 1, craft.recipe) + inv:set_stack("fuel", 1, craft_guide.get_item_name(craft.recipe)) meta:set_string("formspec",craft_guide.get_craft_guide_formspec(meta)) return end -- build (shaped or shapeless) if craft.recipe[1] then if (type(craft.recipe[1]) == "string") then - inv:set_stack("build", 1, craft.recipe[1]) + inv:set_stack("build", 1, craft_guide.get_item_name(craft.recipe[1])) else if craft.recipe[1][1] then - inv:set_stack("build", 1, craft.recipe[1][1]) + inv:set_stack("build", 1, craft_guide.get_item_name(craft.recipe[1][1])) end if craft.recipe[1][2] then - inv:set_stack("build", 2, craft.recipe[1][2]) + inv:set_stack("build", 2, craft_guide.get_item_name(craft.recipe[1][2])) end if craft.recipe[1][3] then - inv:set_stack("build", 3, craft.recipe[1][3]) + inv:set_stack("build", 3, craft_guide.get_item_name(craft.recipe[1][3])) end end end if craft.recipe[2] then if (type(craft.recipe[2]) == "string") then - inv:set_stack("build", 2, craft.recipe[2]) + inv:set_stack("build", 2, craft_guide.get_item_name(craft.recipe[2])) else if craft.recipe[2][1] then - inv:set_stack("build", 4, craft.recipe[2][1]) + inv:set_stack("build", 4, craft_guide.get_item_name(craft.recipe[2][1])) end if craft.recipe[2][2] then - inv:set_stack("build", 5, craft.recipe[2][2]) + inv:set_stack("build", 5, craft_guide.get_item_name(craft.recipe[2][2])) end if craft.recipe[2][3] then - inv:set_stack("build", 6, craft.recipe[2][3]) + inv:set_stack("build", 6, craft_guide.get_item_name(craft.recipe[2][3])) end end end if craft.recipe[3] then if (type(craft.recipe[3]) == "string") then - inv:set_stack("build", 3, craft.recipe[3]) + inv:set_stack("build", 3, craft_guide.get_item_name(craft.recipe[3])) else if craft.recipe[3][1] then - inv:set_stack("build", 7, craft.recipe[3][1]) + inv:set_stack("build", 7, craft_guide.get_item_name(craft.recipe[3][1])) end if craft.recipe[3][2] then - inv:set_stack("build", 8, craft.recipe[3][2]) + inv:set_stack("build", 8, craft_guide.get_item_name(craft.recipe[3][2])) end if craft.recipe[3][3] then - inv:set_stack("build", 9, craft.recipe[3][3]) + inv:set_stack("build", 9, craft_guide.get_item_name(craft.recipe[3][3])) end end end if craft.recipe[4] then if (type(craft.recipe[4]) == "string") then - inv:set_stack("build", 4, craft.recipe[4]) + inv:set_stack("build", 4, craft_guide.get_item_name(craft.recipe[4])) end end if craft.recipe[5] then if (type(craft.recipe[5]) == "string") then - inv:set_stack("build", 5, craft.recipe[5]) + inv:set_stack("build", 5, craft_guide.get_item_name(craft.recipe[5])) end end if craft.recipe[6] then if (type(craft.recipe[6]) == "string") then - inv:set_stack("build", 6, craft.recipe[6]) + inv:set_stack("build", 6, craft_guide.get_item_name(craft.recipe[6])) end end if craft.recipe[7] then if (type(craft.recipe[7]) == "string") then - inv:set_stack("build", 7, craft.recipe[7]) + inv:set_stack("build", 7, craft_guide.get_item_name(craft.recipe[7])) end end if craft.recipe[8] then if (type(craft.recipe[8]) == "string") then - inv:set_stack("build", 8, craft.recipe[8]) + inv:set_stack("build", 8, craft_guide.get_item_name(craft.recipe[8])) end end if craft.recipe[9] then if (type(craft.recipe[9]) == "string") then - inv:set_stack("build", 9, craft.recipe[9]) + inv:set_stack("build", 9, craft_guide.get_item_name(craft.recipe[9])) end end meta:set_string("formspec",craft_guide.get_craft_guide_formspec(meta)) @@ -388,3 +389,31 @@ craft_guide.allow_metadata_inventory_take = function(pos, listname, index, stack return 0 end + +-- get an item name, if it's a group then get an item in the group +craft_guide.get_item_name = function(item_name) + if string.find(item_name, "group:") then + if #craft_guide.groups == 0 then + craft_guide.load_item_groups() + end + if craft_guide.groups[string.sub(item_name, 7)] ~= nil then + item_name = craft_guide.groups[string.sub(item_name, 7)].item_name + end + end + return item_name +end + + +-- load the item groups table +craft_guide.load_item_groups = function() + for name,def in pairs(minetest.registered_items) do + if name ~= nil and def ~= nil and dump(name) ~= "\"\"" and dump(def) ~= "\"\"" then + for group,_ in pairs(def.groups) do + if craft_guide.groups[group] == nil then + craft_guide.groups[group] = {} + craft_guide.groups[group].item_name = name + end + end + end + end +end \ No newline at end of file