diff options
Diffstat (limited to 'flowing_logic.lua')
-rw-r--r-- | flowing_logic.lua | 42 |
1 files changed, 30 insertions, 12 deletions
diff --git a/flowing_logic.lua b/flowing_logic.lua index e943488..a375aeb 100644 --- a/flowing_logic.lua +++ b/flowing_logic.lua @@ -14,7 +14,10 @@ local check4liquids = function(pos) {x=pos.x,y=pos.y,z=pos.z+1}, } for i =1,6 do local name = minetest.env:get_node(coords[i]).name - if string.find(name,'water') then return true end + if string.find(name,'water') then + minetest.env:remove_node(coords[i]) + return true + end end return false end @@ -44,13 +47,14 @@ local check4inflows = function(pos,node) end if newnode then dbg(newnode..' to replace '..node.name) - minetest.env:add_node(pos,{name=newnode}) + minetest.env:add_node(pos,{name=newnode, param2 = node.param2}) minetest.env:get_meta(pos):set_string('source',minetest.pos_to_string(source)) end end local checksources = function(pos,node) local sourcepos = minetest.string_to_pos(minetest.env:get_meta(pos):get_string('source')) + if not sourcepos then return end local source = minetest.env:get_node(sourcepos).name local newnode = false if not ((source == 'pipeworks:pump_on' and check4liquids(sourcepos)) or string.find(source,'_loaded') or source == 'ignore' ) then @@ -59,7 +63,7 @@ local checksources = function(pos,node) if newnode then dbg(newnode..' to replace '..node.name) end if newnode then - minetest.env:add_node(pos,{name=newnode}) + minetest.env:add_node(pos,{name=newnode, param2 = node.param2}) minetest.env:get_meta(pos):set_string('source','') end end @@ -67,7 +71,8 @@ end local update_outlet = function(pos) local top = minetest.env:get_node({x=pos.x,y=pos.y+1,z=pos.z}).name if string.find(top,'_loaded') then - if minetest.env:get_node({x=pos.x,y=pos.y-1,z=pos.z}).name == 'air' then + local name = minetest.env:get_node({x=pos.x,y=pos.y-1,z=pos.z}).name + if name == 'air' or name == "default:water_source" or name == "default:water_flowing" then minetest.env:add_node({x=pos.x,y=pos.y-1,z=pos.z},{name='default:water_source'}) end elseif minetest.env:get_node({x=pos.x,y=pos.y-1,z=pos.z}).name == 'default:water_source' then @@ -81,19 +86,32 @@ local spigot_check = function(pos,node) dbg(fdir..' checking '..minetest.pos_to_string(check[fdir+1])..' for spigot at '..minetest.pos_to_string(pos)) local top = minetest.env:get_node(check[fdir+1]).name dbg('found '..top) - if string.find(top,'_loaded') then - minetest.env:add_node({x=pos.x,y=pos.y,z=pos.z},{name='pipeworks:spigot_pouring', param2 = fdir}) - if minetest.env:get_node({x=pos.x,y=pos.y-1,z=pos.z}).name == 'air' then - minetest.env:add_node({x=pos.x,y=pos.y-1,z=pos.z},{name='default:water_source'}) - end + local name = minetest.env:get_node({x=pos.x,y=pos.y-1,z=pos.z}).name + if string.find(top,'_loaded') and (name == 'air' or name == "default:water_source" or name == "default:water_flowing") then + minetest.env:add_node({x=pos.x,y=pos.y-1,z=pos.z},{name='default:water_source'}) + minetest.env:add_node(pos,{name='pipeworks:spigot_pouring', param2 = fdir}) else - minetest.env:add_node({x=pos.x,y=pos.y,z=pos.z},{name='pipeworks:spigot', param2 = fdir}) - if minetest.env:get_node({x=pos.x,y=pos.y-1,z=pos.z}).name == 'default:water_source' then - minetest.env:remove_node({x=pos.x,y=pos.y-1,z=pos.z}) + if minetest.env:get_node(pos).name == 'pipeworks:spigot_pouring' then + minetest.env:add_node({x=pos.x,y=pos.y,z=pos.z},{name='pipeworks:spigot', param2 = fdir}) + if name == 'air' or name == "default:water_source" or name == "default:water_flowing" then + minetest.env:remove_node({x=pos.x,y=pos.y-1,z=pos.z}) + end end end end +table.insert(pipes_empty_nodenames,"pipeworks:valve_on_empty") +table.insert(pipes_empty_nodenames,"pipeworks:valve_off_empty") +table.insert(pipes_empty_nodenames,"pipeworks:valve_on_loaded") +table.insert(pipes_empty_nodenames,"pipeworks:entry_panel_empty") +table.insert(pipes_empty_nodenames,"pipeworks:flow_sensor_empty") + +table.insert(pipes_full_nodenames,"pipeworks:valve_on_empty") +table.insert(pipes_full_nodenames,"pipeworks:valve_off_empty") +table.insert(pipes_full_nodenames,"pipeworks:valve_on_loaded") +table.insert(pipes_full_nodenames,"pipeworks:entry_panel_loaded") +table.insert(pipes_full_nodenames,"pipeworks:flow_sensor_loaded") + minetest.register_abm({ nodenames = pipes_empty_nodenames, interval = 1, |