diff options
author | VanessaE <vanessaezekowitz@gmail.com> | 2013-06-05 07:38:47 -0700 |
---|---|---|
committer | VanessaE <vanessaezekowitz@gmail.com> | 2013-06-05 07:38:47 -0700 |
commit | 8c034ff6ef3a9f71d9777667197c255bde7e7055 (patch) | |
tree | 5dc2d9a7015b628e1c3441156128c561801d0eab | |
parent | 3796ddd3d8916ed47996846b2b30ad0ae460f9cc (diff) | |
parent | c9a8224bb5f27bb308d2fb9e3480e82f39f80943 (diff) | |
download | pipeworks-8c034ff6ef3a9f71d9777667197c255bde7e7055.tar pipeworks-8c034ff6ef3a9f71d9777667197c255bde7e7055.tar.gz pipeworks-8c034ff6ef3a9f71d9777667197c255bde7e7055.tar.bz2 pipeworks-8c034ff6ef3a9f71d9777667197c255bde7e7055.tar.xz pipeworks-8c034ff6ef3a9f71d9777667197c255bde7e7055.zip |
Merge pull request #37 from Novatux/teleport
Add an no-receive option to teleport tubes.
-rw-r--r-- | teleport_tube.lua | 35 |
1 files changed, 27 insertions, 8 deletions
diff --git a/teleport_tube.lua b/teleport_tube.lua index 76370c2..10541f0 100644 --- a/teleport_tube.lua +++ b/teleport_tube.lua @@ -16,14 +16,14 @@ function write_file(tbl) f:close() end -function add_tube_in_file(pos,channel) +function add_tube_in_file(pos,channel, cr) 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}) + table.insert(tbl,{x=pos.x,y=pos.y,z=pos.z,channel=channel,cr=cr}) write_file(tbl) end @@ -45,11 +45,12 @@ function get_tubes_in_file(pos,channel) for _,val in ipairs(tbl) do local node = minetest.env:get_node(val) local meta = minetest.env:get_meta(val) - if node.name~="ignore" and val.channel~=meta:get_string("channel") then + if node.name~="ignore" and (val.channel~=meta:get_string("channel") or val.cr~=meta:get_int("can_receive")) then val.channel=meta:get_string("channel") + val.cr=meta:get_int("can_receive") changed=true end - if val.channel==channel and (val.x~=pos.x or val.y~=pos.y or val.z~=pos.z) then + if val.cr==1 and 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 @@ -84,15 +85,33 @@ register_tube("pipeworks:teleport_tube","Teleporter pneumatic tube segment",tele 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") + meta:set_string("channel","") + meta:set_int("can_receive",1) + meta:set_string("formspec","size[9,1;]".. + "field[0,0.5;7,1;channel;Channel:;${channel}]".. + "button[8,0;1,1;bt;On]") + add_tube_in_file(pos,"") end, on_receive_fields = function(pos,formname,fields,sender) local meta = minetest.env:get_meta(pos) + if fields.channel==nil then fields.channel=meta:get_string("channel") end meta:set_string("channel",fields.channel) remove_tube_in_file(pos) - add_tube_in_file(pos,fields.channel) + local cr = meta:get_int("can_receive") + if fields["bt"] then + cr=1-cr + meta:set_int("can_receive",cr) + if cr==1 then + meta:set_string("formspec","size[9,1;]".. + "field[0,0.5;7,1;channel;Channel:;${channel}]".. + "button[8,0;1,1;bt;On]") + else + meta:set_string("formspec","size[9,1;]".. + "field[0,0.5;7,1;channel;Channel:;${channel}]".. + "button[8,0;1,1;bt;Off]") + end + end + add_tube_in_file(pos,fields.channel, cr) end, on_destruct = function(pos) remove_tube_in_file(pos) |