From e92ac0f7b3588e183c1fa47c23109592e28ae04e Mon Sep 17 00:00:00 2001 From: Tim Date: Wed, 28 Jan 2015 00:33:07 +0100 Subject: abstract adding of virtual items --- autocrafter.lua | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'autocrafter.lua') diff --git a/autocrafter.lua b/autocrafter.lua index 1f5e547..eab57b9 100644 --- a/autocrafter.lua +++ b/autocrafter.lua @@ -152,6 +152,12 @@ local function set_formspec(meta, enabled) "list[current_player;main;0,7;8,4;]") end +local function add_virtual_item(inv, listname, index, stack) + local stack_copy = ItemStack(stack) + stack_copy:set_count(1) + inv:set_stack(listname, index, stack_copy) +end + minetest.register_node("pipeworks:autocrafter", { description = "Autocrafter", drawtype = "normal", @@ -214,9 +220,7 @@ minetest.register_node("pipeworks:autocrafter", { update_autocrafter(pos) local inv = minetest.get_meta(pos):get_inventory() if listname == "recipe" then - local stack_copy = ItemStack(stack) - stack_copy:set_count(1) - inv:set_stack(listname, index, stack_copy) + add_virtual_item(inv, listname, index, stack) after_recipe_change(pos, inv) return 0 else @@ -246,9 +250,7 @@ minetest.register_node("pipeworks:autocrafter", { after_recipe_change(pos, inv) return 0 elseif to_list == "recipe" then - local stack_copy = ItemStack(stack) - stack_copy:set_count(1) - inv:set_stack(to_list, to_index, stack_copy) + add_virtual_item(inv, to_list, to_index, stack) after_recipe_change(pos, inv) return 0 else -- cgit v1.2.3