summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--autocrafter.lua75
-rw-r--r--autoplace.lua7
-rw-r--r--crafts.lua20
-rw-r--r--init.lua2
-rw-r--r--item_transport.lua54
-rw-r--r--teleport_tube.lua82
-rw-r--r--textures/pipeworks_autocrafter.pngbin0 -> 167 bytes
-rw-r--r--tubes.lua10
8 files changed, 229 insertions, 21 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/crafts.lua b/crafts.lua
index 03890c5..9d33b4f 100644
--- a/crafts.lua
+++ b/crafts.lua
@@ -115,7 +115,25 @@ if io.open(minetest.get_modpath("pipeworks").."/../technic/init.lua", "r") == ni
output = "pipeworks:detector_tube_off_000000 2",
recipe = {
{ "homedecor:plastic_sheeting", "homedecor:plastic_sheeting", "homedecor:plastic_sheeting" },
- { "default:mese_crystal_fragment", "default:mese_crystal_fragment", "default:mese_crystal_fragment" },
+ { "mesecons:mesecon", "mesecons:mesecon", "mesecons:mesecon" },
+ { "homedecor:plastic_sheeting", "homedecor:plastic_sheeting", "homedecor:plastic_sheeting" }
+ },
+ })
+
+ minetest.register_craft( {
+ output = "pipeworks:accelerator_tube_000000 2",
+ recipe = {
+ { "homedecor:plastic_sheeting", "homedecor:plastic_sheeting", "homedecor:plastic_sheeting" },
+ { "default:mese_crystal_fragment", "default:steel_ingot", "default:mese_crystal_fragment" },
+ { "homedecor:plastic_sheeting", "homedecor:plastic_sheeting", "homedecor:plastic_sheeting" }
+ },
+ })
+
+ minetest.register_craft( {
+ output = "pipeworks:teleport_tube_000000 2",
+ recipe = {
+ { "homedecor:plastic_sheeting", "homedecor:plastic_sheeting", "homedecor:plastic_sheeting" },
+ { "default:desert_stone", "default:mese_block", "default:desert_stone" },
{ "homedecor:plastic_sheeting", "homedecor:plastic_sheeting", "homedecor:plastic_sheeting" }
},
})
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/item_transport.lua b/item_transport.lua
index db057aa..bed8f31 100644
--- a/item_transport.lua
+++ b/item_transport.lua
@@ -153,10 +153,13 @@ minetest.register_entity("pipeworks:tubed_item", {
end,
get_staticdata = function(self)
-
+ if self.start_pos==nil then return end
+ local velocity=self.object:getvelocity()
+ --self.object:setvelocity({x=0,y=0,z=0})
+ self.object:setpos(self.start_pos)
return minetest.serialize({
itemstring=self.itemstring,
- velocity=self.object:getvelocity(),
+ velocity=velocity,
start_pos=self.start_pos
})
end,
@@ -196,31 +199,35 @@ minetest.register_entity("pipeworks:tubed_item", {
local velocitycopy={x=velocity.x,y=velocity.y,z=velocity.z}
local moved=false
+ local speed=math.abs(velocity.x+velocity.y+velocity.z)
+ local vel={x=velocity.x/speed,y=velocity.y/speed,z=velocity.z/speed}
- if math.abs(velocity.x)==1 then
+ if math.abs(vel.x)==1 then
local next_node=math.abs(pos.x-self.start_pos.x)
if next_node >= 1 then
- self.start_pos.x=self.start_pos.x+velocity.x
+ self.start_pos.x=self.start_pos.x+vel.x
moved=true
end
- elseif math.abs(velocity.y)==1 then
+ elseif math.abs(vel.y)==1 then
local next_node=math.abs(pos.y-self.start_pos.y)
if next_node >= 1 then
- self.start_pos.y=self.start_pos.y+velocity.y
+ self.start_pos.y=self.start_pos.y+vel.y
moved=true
end
- elseif math.abs(velocity.z)==1 then
+ elseif math.abs(vel.z)==1 then
local next_node=math.abs(pos.z-self.start_pos.z)
if next_node >= 1 then
- self.start_pos.z=self.start_pos.z+velocity.z
+ self.start_pos.z=self.start_pos.z+vel.z
moved=true
end
end
+ local sposcopy={x=self.start_pos.x,y=self.start_pos.y,z=self.start_pos.z}
+
node = minetest.env:get_node(self.start_pos)
if moved and minetest.get_item_group(node.name,"tubedevice_receiver")==1 then
if minetest.registered_nodes[node.name].tube and minetest.registered_nodes[node.name].tube.insert_object then
- leftover = minetest.registered_nodes[node.name].tube.insert_object(self.start_pos,node,stack,velocity)
+ leftover = minetest.registered_nodes[node.name].tube.insert_object(self.start_pos,node,stack,vel)
else
leftover = stack
end
@@ -249,7 +256,8 @@ minetest.register_entity("pipeworks:tubed_item", {
end
end
- if velocity.x~=velocitycopy.x or velocity.y~=velocitycopy.y or velocity.z~=velocitycopy.z then
+ if velocity.x~=velocitycopy.x or velocity.y~=velocitycopy.y or velocity.z~=velocitycopy.z or
+ self.start_pos.x~=sposcopy.x or self.start_pos.y~=sposcopy.y or self.start_pos.z~=sposcopy.z then
self.object:setpos(self.start_pos)
self.object:setvelocity(velocity)
end
@@ -278,13 +286,23 @@ function go_next(pos,velocity,stack)
local len=1
local n
local can_go
+ local speed=math.abs(velocity.x+velocity.y+velocity.z)
+ local vel={x=velocity.x/speed,y=velocity.y/speed,z=velocity.z/speed,speed=speed}
+ if speed>=4.1 then
+ speed=4
+ elseif speed>=1.1 then
+ speed=speed-0.1
+ else
+ speed=1
+ end
+ vel.speed=speed
if minetest.registered_nodes[cnode.name].tube and minetest.registered_nodes[cnode.name].tube.can_go then
- can_go=minetest.registered_nodes[cnode.name].tube.can_go(pos,node,velocity,stack)
+ can_go=minetest.registered_nodes[cnode.name].tube.can_go(pos,node,vel,stack)
else
can_go=adjlist
end
for _,vect in ipairs(can_go) do
- if vect.x~=-velocity.x or vect.y~=-velocity.y or vect.z~=-velocity.z then
+ if vect.x~=-vel.x or vect.y~=-vel.y or vect.z~=-vel.z then
npos=addVect(pos,vect)
node=minetest.env:get_node(npos)
tube_receiver=minetest.get_item_group(node.name,"tubedevice_receiver")
@@ -334,9 +352,9 @@ function go_next(pos,velocity,stack)
end
until false
meta:set_int("tubedir",n)
- velocity.x=tubes[n].vect.x
- velocity.y=tubes[n].vect.y
- velocity.z=tubes[n].vect.z
+ velocity.x=tubes[n].vect.x*vel.speed
+ velocity.y=tubes[n].vect.y*vel.speed
+ velocity.z=tubes[n].vect.z*vel.speed
end
else
local i=1
@@ -352,9 +370,9 @@ function go_next(pos,velocity,stack)
break
end
until false
- velocity.x=chests[n].vect.x
- velocity.y=chests[n].vect.y
- velocity.z=chests[n].vect.z
+ velocity.x=chests[n].vect.x*speed
+ velocity.y=chests[n].vect.y*speed
+ velocity.z=chests[n].vect.z*speed
end
return 1
end \ No newline at end of file
diff --git a/teleport_tube.lua b/teleport_tube.lua
new file mode 100644
index 0000000..eda3912
--- /dev/null
+++ b/teleport_tube.lua
@@ -0,0 +1,82 @@
+
+filename=minetest.get_worldpath() .. "/teleport_tubes"
+
+function read_file()
+ local f = io.open(filename, "r")
+ if f==nil then return {} end
+ local t = f:read("*all")
+ f:close()
+ if t=="" or t==nil then return {} end
+ return minetest.deserialize(t)
+end
+
+function write_file(tbl)
+ local f = io.open(filename, "w")
+ f:write(minetest.serialize(tbl))
+ f:close()
+end
+
+function add_tube_in_file(pos,channel)
+ tbl=read_file()
+ for _,val in ipairs(tbl) do
+ if val.x==pos.x and val.y==pos.y and val.z==pos.z then
+ return
+ end
+ end
+ table.insert(tbl,{x=pos.x,y=pos.y,z=pos.z,channel=channel})
+ write_file(tbl)
+end
+
+function remove_tube_in_file(pos)
+ tbl=read_file()
+ newtbl={}
+ for _,val in ipairs(tbl) do
+ if val.x~=pos.x or val.y~=pos.y or val.z~=pos.z then
+ table.insert(newtbl,val)
+ end
+ end
+ write_file(newtbl)
+end
+
+function get_tubes_in_file(pos,channel)
+ tbl=read_file()
+ newtbl={}
+ for _,val in ipairs(tbl) do
+ if val.channel==channel and (val.x~=pos.x or val.y~=pos.y or val.z~=pos.z) then
+ table.insert(newtbl,val)
+ end
+ end
+ return newtbl
+end
+
+
+register_tube("pipeworks:teleport_tube","Teleporter pneumatic tube segment",plain_textures,noctr_textures,end_textures,
+ short_texture,inv_texture,
+ {tube={can_go=function(pos,node,velocity,stack)
+ velocity.x=0
+ velocity.y=0
+ velocity.z=0
+ local meta = minetest.env:get_meta(pos)
+ channel=meta:get_string("channel")
+ goto=get_tubes_in_file(pos,channel)
+ if goto[1]==nil then return {} end
+ pos.x=goto[1].x
+ pos.y=goto[1].y
+ pos.z=goto[1].z
+ return meseadjlist
+ end},
+ on_construct = function(pos)
+ local meta = minetest.env:get_meta(pos)
+ meta:set_string("channel","0")
+ meta:set_string("formspec","size[9,1;]field[0,0.5;9,1;channel;Channel:;${channel}]")
+ add_tube_in_file(pos,"0")
+ end,
+ on_receive_fields = function(pos,formname,fields,sender)
+ local meta = minetest.env:get_meta(pos)
+ meta:set_string("channel",fields.channel)
+ remove_tube_in_file(pos)
+ add_tube_in_file(pos,fields.channel)
+ end,
+ after_dig_node = function(pos)
+ remove_tube_in_file(pos)
+ end})
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
diff --git a/tubes.lua b/tubes.lua
index 9789143..90e6ecf 100644
--- a/tubes.lua
+++ b/tubes.lua
@@ -371,3 +371,13 @@ register_tube("pipeworks:detector_tube_off","Detector tube segment",detector_pla
groups={mesecon=2},
mesecons={receptor={state="off",
rules=mesecons_rules}}})
+
+register_tube("pipeworks:accelerator_tube","Accelerator pneumatic tube segment",plain_textures,noctr_textures,end_textures,
+ short_texture,inv_texture,
+ {tube={can_go=function(pos,node,velocity,stack)
+ velocity.speed=velocity.speed+1
+ return meseadjlist
+ end}})
+
+modpath=minetest.get_modpath("pipeworks")
+dofile(modpath.."/teleport_tube.lua") \ No newline at end of file