]> git.lizzy.rs Git - xdecor.git/blobdiff - worktable.lua
Crafting guide : simplify group to node determination
[xdecor.git] / worktable.lua
index ad8ff89564fb0d33fd1110f26ee8433f2e5fab60..c67b5d74e2ad5377b595886f115870598d3b6c53 100644 (file)
@@ -63,6 +63,7 @@ function worktable.craft_output_recipe(pos, start_i, pagenum, stackname, recipe_
                        recipe_num = 1
                end
 
+               --print(dump(minetest.get_all_craft_recipes(stackname)))
                local stack_width = minetest.get_all_craft_recipes(stackname)[recipe_num].width
                local stack_items = minetest.get_all_craft_recipes(stackname)[recipe_num].items
                local stack_type = minetest.get_all_craft_recipes(stackname)[recipe_num].type
@@ -117,52 +118,24 @@ function worktable.craft_output_recipe(pos, start_i, pagenum, stackname, recipe_
                        inv:set_size("craft_output_recipe", 1)
                end
 
-               local craft, group_nodes = {}, {}
+               local craft = {}
                for k, def in pairs(stack_items) do
                        craft[#craft+1] = def
                        if def and def:find("^group:") then
-                               if def:find("wool") then
+                               if def:find("wool$") then
                                        def = "wool:white"
-                               elseif def:find("dye") then
-                                       local dye_color = def:match(".*_([%w_]+)")
-                                       def = "dye:"..dye_color
-                               elseif def:find("flower") then
-                                       local flower_color = def:match(".*_([%w_]+)")
-                                       if flower_color == "red" then
-                                               def = "flowers:rose"
-                                       elseif flower_color == "yellow" then
-                                               def = "flowers:dandelion_yellow"
-                                       elseif flower_color == "white" then
-                                               def = "flowers:dandelion_white"
-                                       elseif flower_color == "blue" then
-                                               def = "flowers:geranium"
-                                       elseif flower_color == "orange" then
-                                               def = "flowers:tulip"
-                                       elseif flower_color == "violet" then
-                                               def = "flowers:viola"
-                                       elseif def:find("^group:flower$") then
-                                               def = "flowers:rose"
-                                       end
+                               elseif def:find("dye$") then
+                                       def = "dye:white"
                                else
-                                       if minetest.registered_items["default:"..def:match("^group:([%w_,]+)$")] then
+                                       if minetest.registered_items["default:"..def:match("^group:([%w_]+)$")] then
                                                def = def:gsub("group", "default")
                                        else
                                                for node, definition in pairs(minetest.registered_items) do
                                                for group in pairs(definition.groups) do
-                                                       if def:match("^group:"..group) then
-                                                               if node:find("^default:") then
-                                                                       if not minetest.serialize(group_nodes):match(node) then
-                                                                               group_nodes[#group_nodes+1] = node
-                                                                       end
-
-                                                                       for _, n in pairs(group_nodes) do
-                                                                               inv:set_stack("craft_output_recipe", k, n)
-                                                                       end
-                                                               end
-
-                                                               if inv:get_stack("craft_output_recipe", k):is_empty() then
-                                                                       inv:set_stack("craft_output_recipe", k, node)
-                                                               end
+                                                       if def:match("^group:"..group.."$") or
+                                                                       ((def:find("dye") or def:find("flower")) and
+                                                                       group == def:match("^group:.*,("..group..")")) then
+                                                               def = node
                                                        end
                                                end
                                                end
@@ -170,9 +143,7 @@ function worktable.craft_output_recipe(pos, start_i, pagenum, stackname, recipe_
                                end
                        end
 
-                       if not def:find("^group:") then
-                               inv:set_stack("craft_output_recipe", k, def)
-                       end
+                       inv:set_stack("craft_output_recipe", k, def)
                end
 
                formspec = formspec..[[ image[4,6.3;1,1;gui_furnace_arrow_bg.png^[transformR90]
@@ -388,7 +359,6 @@ function worktable.move(pos, from_list, from_index, to_list, to_index, count, _)
        elseif inv:is_empty("item_craft_input") and from_list == "inv_items_list" and
                        to_list == "item_craft_input" then
                local stackname = inv:get_stack(from_list, from_index):get_name()
-               --print(dump(minetest.get_all_craft_recipes(stackname)))
                local formspec = meta:to_table().fields.formspec
                local filter = formspec:match("filter;;([%w_:]+)") or ""
                local start_i = tonumber(formspec:match("inv_items_list;.*;(%d+)%]")) or 0