summaryrefslogtreecommitdiff
path: root/teleport_tube.lua
diff options
context:
space:
mode:
authorNovatux <nathanael.courant@laposte.net>2013-01-19 13:14:41 +0100
committerNovatux <nathanael.courant@laposte.net>2013-01-19 13:14:41 +0100
commitaea0207b7fa5c6a1024efe306f4fe05c70a6085e (patch)
tree214a1def744581c433ec21532d5e91ac42b314fb /teleport_tube.lua
parent143aa0ee0404a05bc0f0a22bacd603df8c0df7f4 (diff)
downloadpipeworks-aea0207b7fa5c6a1024efe306f4fe05c70a6085e.tar
pipeworks-aea0207b7fa5c6a1024efe306f4fe05c70a6085e.tar.gz
pipeworks-aea0207b7fa5c6a1024efe306f4fe05c70a6085e.tar.bz2
pipeworks-aea0207b7fa5c6a1024efe306f4fe05c70a6085e.tar.xz
pipeworks-aea0207b7fa5c6a1024efe306f4fe05c70a6085e.zip
Added accelrator and teleport pipes
Diffstat (limited to 'teleport_tube.lua')
-rw-r--r--teleport_tube.lua75
1 files changed, 75 insertions, 0 deletions
diff --git a/teleport_tube.lua b/teleport_tube.lua
new file mode 100644
index 0000000..e4d759a
--- /dev/null
+++ b/teleport_tube.lua
@@ -0,0 +1,75 @@
+
+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_int("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_int("channel",0)
+ add_tube_in_file(pos,0)
+ end,
+ after_dig_node = function(pos)
+ remove_tube_in_file(pos)
+ end})