From cd0c434e006ce604001099f7731bb23ebc498cf2 Mon Sep 17 00:00:00 2001 From: kilbith Date: Wed, 3 Feb 2016 20:24:24 +0100 Subject: [PATCH] Work Table : better ordering of functions --- worktable.lua | 39 ++++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/worktable.lua b/worktable.lua index 0a26f8c..ed1fb4a 100644 --- a/worktable.lua +++ b/worktable.lua @@ -143,6 +143,21 @@ function worktable.craftguide_items(meta, filter) return items_list end +function worktable.get_output(inv, input, name) + if inv:is_empty("input") then + inv:set_list("forms", {}) return + end + + local output = {} + for _, n in pairs(worktable.defs) do + local count = math.min(n[2] * input:get_count(), input:get_stack_max()) + local item = name.."_"..n[1] + if not n[3] then item = "stairs:"..n[1].."_"..name:match(":(.*)") end + output[#output+1] = item.." "..count + end + inv:set_list("forms", output) +end + worktable.formspecs = { crafting = function(meta) meta:set_string("formspec", [[ size[8,7;] @@ -268,31 +283,12 @@ function worktable.take(_, listname, _, stack, player) return stack:get_count() end -function worktable.on_move(pos, _, _, to_list, _, count) - local inv = minetest.get_meta(pos):get_inventory() - if to_list == "trash" then inv:set_list("trash", {}) end -end function worktable.move(pos, _, _, to_list, _, count) if to_list == "storage" or to_list == "trash" then return count end return 0 end -function worktable.get_output(inv, input, name) - if inv:is_empty("input") then - inv:set_list("forms", {}) return - end - - local output = {} - for _, n in pairs(worktable.defs) do - local count = math.min(n[2] * input:get_count(), input:get_stack_max()) - local item = name.."_"..n[1] - if not n[3] then item = "stairs:"..n[1].."_"..name:match(":(.*)") end - output[#output+1] = item.." "..count - end - inv:set_list("forms", output) -end - function worktable.on_put(pos, listname, _, stack) local inv = minetest.get_meta(pos):get_inventory() if listname == "input" then @@ -318,6 +314,11 @@ function worktable.on_take(pos, listname, index, stack) end end +function worktable.on_move(pos, _, _, to_list, _, count) + local inv = minetest.get_meta(pos):get_inventory() + if to_list == "trash" then inv:set_list("trash", {}) end +end + xdecor.register("worktable", { description = "Work Table", groups = {cracky=2, choppy=2, oddly_breakable_by_hand=1},