From 04b1dccb5ecdc2ee20638afe2c787897fa0c9519 Mon Sep 17 00:00:00 2001 From: kilbith Date: Mon, 4 Jan 2016 11:41:15 +0100 Subject: [PATCH] Various clean-ups and update inv size on clicking on [Guide] button instead after constructing --- crafts.lua | 2 +- worktable.lua | 32 ++++++++++++-------------------- 2 files changed, 13 insertions(+), 21 deletions(-) diff --git a/crafts.lua b/crafts.lua index b35ea56..84f8bef 100644 --- a/crafts.lua +++ b/crafts.lua @@ -403,7 +403,7 @@ minetest.register_craft({ output = "xdecor:wood_tile 2", recipe = { {"", "group:wood", ""}, - {"group:wood", "group:wood", "group:wood"}, + {"group:wood", "", "group:wood"}, {"", "group:wood", ""} } }) diff --git a/worktable.lua b/worktable.lua index 9e7a751..c6c576a 100644 --- a/worktable.lua +++ b/worktable.lua @@ -67,19 +67,15 @@ function worktable.craft_output_recipe(pos, start_i, pagenum, stackname, recipe_ 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+)") + local stack_count = stack_output:match("%s(%d+)") or 1 + + inv:set_stack("item_craft_input", 1, stackname.." "..stack_count) 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_type == "cooking" or table.maxn(stack_items) == 1 then if stack_type == "cooking" then formspec = formspec.."image[4.25,5.9;0.5,0.5;default_furnace_fire_fg.png]" @@ -107,20 +103,18 @@ function worktable.craft_output_recipe(pos, start_i, pagenum, stackname, recipe_ if def and def:find("^group:") then if def:find("wool$") or def:find("dye$") then def = def:match(":([%w_]+)")..":white" + elseif minetest.registered_items["default:"..def:match("^group:([%w_,]+)$")] then + def = def:gsub("group", "default") 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 + 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 @@ -220,7 +214,6 @@ function worktable.construct(pos) meta:set_string("infotext", "Work Table") worktable.main(pos) - worktable.craftguide_update(pos, nil) end function worktable.fields(pos, _, fields, sender) @@ -241,7 +234,6 @@ function worktable.fields(pos, _, fields, sender) end worktable.crafting(pos) elseif fields.craftguide then - if not meta:to_table().inventory.inv_items_list then return end -- legacy code worktable.craftguide_update(pos, nil) worktable.craft_output_recipe(pos, 0, 1, nil, 1, "") elseif fields.alternate then