summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--autocrafter.lua75
-rw-r--r--autoplace.lua7
-rw-r--r--init.lua2
-rw-r--r--textures/pipeworks_autocrafter.pngbin0 -> 167 bytes
4 files changed, 82 insertions, 2 deletions
diff --git a/autocrafter.lua b/autocrafter.lua
new file mode 100644
index 0000000..71aeccf
--- /dev/null
+++ b/autocrafter.lua
@@ -0,0 +1,75 @@
+
+
+function autocraft(inventory)
+ local recipe=inventory:get_list("recipe")
+ local result
+ local new
+ result,new=minetest.get_craft_result({method="normal",width=3,items=recipe})
+ local input=inventory:get_list("input")
+ if result.item:is_empty() then return end
+ result=result.item
+ local to_use={}
+ for _,item in ipairs(recipe) do
+ if item~=nil and not item:is_empty() then
+ if to_use[item:get_name()]==nil then
+ to_use[item:get_name()]=1
+ else
+ to_use[item:get_name()]=to_use[item:get_name()]+1
+ end
+ end
+ end
+ local stack
+ for itemname,number in pairs(to_use) do
+ stack=ItemStack({name=itemname, count=number})
+ if not inventory:contains_item("src",stack) then return end
+ end
+ for itemname,number in pairs(to_use) do
+ stack=ItemStack({name=itemname, count=number})
+ inventory:remove_item("src",stack)
+ end
+ inventory:add_item("dst",result)
+ print(dump(new))
+end
+
+minetest.register_node("pipeworks:autocrafter",{
+ description = "Autocrafter",
+ drawtype="normal",
+ tiles={"pipeworks_autocrafter.png"},
+ groups={snappy=3,tubedevice=1,tubedevice_receiver=1},
+ tube={insert_object=function(pos,node,stack,direction)
+ local meta=minetest.env:get_meta(pos)
+ local inv=meta:get_inventory()
+ return inv:add_item("src",stack)
+ end,
+ can_insert=function(pos,node,stack,direction)
+ local meta=minetest.env:get_meta(pos)
+ local inv=meta:get_inventory()
+ return inv:room_for_item("src",stack)
+ end,
+ input_inventory="dst"},
+ on_construct = function(pos)
+ local meta = minetest.env:get_meta(pos)
+ meta:set_string("formspec",
+ "size[8,11]"..
+ "list[current_name;recipe;0,0;3,3;]"..
+ "list[current_name;src;0,3;8,3;]"..
+ "list[current_name;dst;4,0;4,3;]"..
+ "list[current_player;main;0,7;8,4;]")
+ meta:set_string("infotext", "Autocrafter")
+ local inv = meta:get_inventory()
+ inv:set_size("src",3*8)
+ inv:set_size("recipe",3*3)
+ inv:set_size("dst",4*3)
+ end,
+ can_dig = function(pos,player)
+ local meta = minetest.env:get_meta(pos);
+ local inv = meta:get_inventory()
+ return (inv:is_empty("src") and inv:is_empty("recipe") and inv:is_empty("dst"))
+ end})
+
+minetest.register_abm({nodenames={"pipeworks:autocrafter"},interval=1,chance=1,
+ action=function(pos,node)
+ local meta=minetest.env:get_meta(pos)
+ local inv=meta:get_inventory()
+ autocraft(inv)
+ end}) \ No newline at end of file
diff --git a/autoplace.lua b/autoplace.lua
index 2b297f2..84c6fde 100644
--- a/autoplace.lua
+++ b/autoplace.lua
@@ -87,7 +87,12 @@ function tube_autoroute(pos)
nsurround = pxm..pxp..pym..pyp..pzm..pzp
if is_tube(nctr.name) then
- minetest.env:add_node(pos, { name = string.sub(nctr.name,1,-7)..nsurround })
+ local meta=minetest.env:get_meta(pos)
+ local meta0=meta:to_table()
+ nctr.name=string.sub(nctr.name,1,-7)..nsurround
+ minetest.env:add_node(pos, nctr)
+ local meta=minetest.env:get_meta(pos)
+ meta:from_table(meta0)
end
end
diff --git a/init.lua b/init.lua
index 142eb97..5b0187c 100644
--- a/init.lua
+++ b/init.lua
@@ -328,5 +328,5 @@ dofile(minetest.get_modpath("pipeworks").."/crafts.lua")
dofile(minetest.get_modpath("pipeworks").."/flowing_logic.lua")
dofile(minetest.get_modpath("pipeworks").."/compat.lua")
dofile(minetest.get_modpath("pipeworks").."/item_transport.lua")
-
+dofile(minetest.get_modpath("pipeworks").."/autocrafter.lua")
print("Pipeworks loaded!")
diff --git a/textures/pipeworks_autocrafter.png b/textures/pipeworks_autocrafter.png
new file mode 100644
index 0000000..ae5f8d9
--- /dev/null
+++ b/textures/pipeworks_autocrafter.png
Binary files differ