summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim <t4im@users.noreply.github.com>2015-01-28 00:33:07 +0100
committerTim <t4im@users.noreply.github.com>2015-01-28 00:33:07 +0100
commite92ac0f7b3588e183c1fa47c23109592e28ae04e (patch)
tree27ebc0ee2d6de128297461d4dd0e4d58a7af5300
parent78e081cf259f6f939cb965675d48dcc647d0ff01 (diff)
downloadpipeworks-e92ac0f7b3588e183c1fa47c23109592e28ae04e.tar
pipeworks-e92ac0f7b3588e183c1fa47c23109592e28ae04e.tar.gz
pipeworks-e92ac0f7b3588e183c1fa47c23109592e28ae04e.tar.bz2
pipeworks-e92ac0f7b3588e183c1fa47c23109592e28ae04e.tar.xz
pipeworks-e92ac0f7b3588e183c1fa47c23109592e28ae04e.zip
abstract adding of virtual items
-rw-r--r--autocrafter.lua14
1 files changed, 8 insertions, 6 deletions
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