+function worktable.craft_output_recipe(pos, start_i, pagenum, stackname, recipe_num, filter)
+ local meta = minetest.get_meta(pos)
+ local inv = meta:get_inventory()
+ local inventory_size = #meta:to_table().inventory.inv_items_list
+ local pagemax = math.floor((inventory_size - 1) / (8*4) + 1)
+
+ local formspec = [[ size[8,8;]
+ list[context;item_craft_input;3,6.3;1,1;]
+ tablecolumns[color;text;color;text]
+ tableoptions[background=#00000000;highlight=#00000000;border=false]
+ button[5.5,0;0.7,1;prev;<]
+ button[7.3,0;0.7,1;next;>]
+ button[4,0.2;0.7,0.5;search;?]
+ button[4.6,0.2;0.7,0.5;clearfilter;X]
+ button[0,0;1.5,1;backcraft;< Back]
+ tooltip[search;Search]
+ tooltip[clearfilter;Reset]
+ label[3,5.8;Input] ]]..
+ "list[context;inv_items_list;0,1;8,4;"..tostring(start_i).."]"..
+ "table[6.1,0.2;1.1,0.5;pagenum;#FFFF00,"..tostring(math.floor(pagenum))..
+ ",#FFFFFF,/ "..tostring(pagemax).."]"..
+ "field[1.8,0.32;2.6,1;filter;;"..filter.."]"..xbg
+
+ if stackname then
+ local items_num = #minetest.get_all_craft_recipes(stackname)
+ if recipe_num > items_num then
+ 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
+ local stack_output = minetest.get_all_craft_recipes(stackname)[recipe_num].output
+ local stack_count = stack_output:match("%s(%d+)")
+
+ if items_num > 1 then
+ formspec = formspec.."button[0,5.7;1.6,1;alternate;Alternate]"..
+ "label[0,5.2;Recipe "..recipe_num.." of "..items_num.."]"
+ end
+
+ if stack_count then
+ inv:set_stack("item_craft_input", 1, stackname.." "..stack_count)
+ else
+ inv:set_stack("item_craft_input", 1, stackname)
+ end
+
+ if stack_width == 0 then
+ if #stack_items <= 2 then
+ formspec = formspec.."list[context;craft_output_recipe;5,6.3;2,1;]"
+ inv:set_size("craft_output_recipe", 2)
+ elseif #stack_items > 2 and #stack_items <= 4 then
+ formspec = formspec.."list[context;craft_output_recipe;5,5.3;2,2;]"
+ inv:set_size("craft_output_recipe", 2*2)
+ else
+ formspec = formspec.."list[context;craft_output_recipe;5,5.3;3,3;]"
+ inv:set_size("craft_output_recipe", 3*3)
+ end
+ elseif stack_width == 1 then
+ if #stack_items == 1 then
+ formspec = formspec.."list[context;craft_output_recipe;5,6.3;1,1;]"
+ else
+ formspec = formspec.."list[context;craft_output_recipe;5,5.3;1,"..#stack_items..";]"
+ end
+ inv:set_size("craft_output_recipe", #stack_items)
+ elseif stack_width == 2 then
+ formspec = formspec.."list[context;craft_output_recipe;5,5.3;2,3;]"
+ inv:set_size("craft_output_recipe", 2*3)
+ elseif stack_width == 3 then
+ if stack_type == "cooking" then
+ formspec = formspec..[[ list[context;craft_output_recipe;5,6.3;1,1;]
+ image[4.25,5.9;0.5,0.5;default_furnace_fire_fg.png] ]]
+ inv:set_size("craft_output_recipe", 1)
+ else
+ formspec = formspec.."list[context;craft_output_recipe;5,5.3;3,3;]"
+ inv:set_size("craft_output_recipe", 3*3)
+ end
+ elseif stack_type == "cooking" and stack_width > 3 then
+ formspec = formspec..[[ list[context;craft_output_recipe;5,6.3;1,1;]
+ image[4.25,5.9;0.5,0.5;default_furnace_fire_fg.png] ]]
+
+ inv:set_size("craft_output_recipe", 1)
+ end
+
+ 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
+ def = "wool:white"
+ elseif def:find("dye$") then
+ def = "dye:white"
+ else
+ 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.."$") or
+ ((def:find("dye") or def:find("flower")) and
+ group == def:match("^group:.*,("..group..")")) then
+ def = node
+ end
+ end
+ end
+ end
+ end
+ end
+
+ inv:set_stack("craft_output_recipe", k, def)
+ end
+
+ formspec = formspec..[[ image[4,6.3;1,1;gui_furnace_arrow_bg.png^[transformR90]
+ button[0,6.5;1.6,1;trash;Clear] ]]..
+ "label[0,7.5;"..stackname:sub(1,30).."]"
+ end
+
+ meta:set_string("formspec", formspec)
+end
+
+function worktable.craftguide_update(pos, filter)
+ local meta = minetest.get_meta(pos)
+ local inv = meta:get_inventory()
+ local inv_items_list = {}
+
+ for name, def in pairs(minetest.registered_items) do
+ if not (def.groups.not_in_creative_inventory == 1) and
+ minetest.get_craft_recipe(name).items and
+ def.description and def.description ~= "" and
+ (not filter or def.name:find(filter, 1, true)) then
+ inv_items_list[#inv_items_list+1] = name
+ end
+ end
+ table.sort(inv_items_list)
+
+ inv:set_size("inv_items_list", #inv_items_list)
+ inv:set_list("inv_items_list", inv_items_list)
+end
+
+function worktable.crafting(pos)
+ local meta = minetest.get_meta(pos)
+ local formspec = [[ size[8,7;]
+ list[current_player;main;0,3.3;8,4;]
+ image[5,1;1,1;gui_furnace_arrow_bg.png^[transformR270]
+ button[0,0;1.5,1;back;< Back]
+ button[0,1;1.5,1;craftguide;Guide]
+ list[current_player;craft;2,0;3,3;]
+ list[current_player;craftpreview;6,1;1,1;]
+ listring[current_player;main]
+ listring[current_player;craft] ]]
+ ..xbg..default.get_hotbar_bg(0,3.3)
+
+ meta:set_string("formspec", formspec)