From f2d17916a29de47b3962f08891d7656d0c05c907 Mon Sep 17 00:00:00 2001 From: kilbith Date: Sun, 3 Jan 2016 15:07:12 +0100 Subject: [PATCH] Crafting guide : simplify group to node determination --- hive.lua | 2 +- worktable.lua | 39 +++++++++------------------------------ 2 files changed, 10 insertions(+), 31 deletions(-) diff --git a/hive.lua b/hive.lua index 5ff1139..c942c18 100644 --- a/hive.lua +++ b/hive.lua @@ -39,7 +39,7 @@ xdecor.register("hive", { minetest.register_abm({ nodenames = {"xdecor:hive"}, - interval = 20, chance = 10, + interval = 30, chance = 10, action = function(pos, _, _, _) local inv = minetest.get_meta(pos):get_inventory() local honeystack = inv:get_stack("honey", 1) diff --git a/worktable.lua b/worktable.lua index c5a0143..c67b5d7 100644 --- a/worktable.lua +++ b/worktable.lua @@ -122,39 +122,20 @@ function worktable.craft_output_recipe(pos, start_i, pagenum, stackname, recipe_ 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 inv:get_stack("craft_output_recipe", k):is_empty() or - node:find("^default:") 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 @@ -162,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]