2013-01-04 09:15:23 +04:00
|
|
|
-- This file provides the actual flow and pathfinding logic that makes water
|
|
|
|
-- move through the pipes.
|
|
|
|
--
|
2013-07-14 06:39:25 +04:00
|
|
|
-- Contributed by mauvebic, 2013-01-03, rewritten a bit by Vanessa Ezekowitz
|
2013-01-04 09:15:23 +04:00
|
|
|
--
|
|
|
|
|
2017-05-18 12:33:56 +03:00
|
|
|
local finitewater = minetest.settings:get_bool("liquid_finite")
|
2013-07-04 08:01:08 +04:00
|
|
|
|
2013-12-15 11:53:10 +04:00
|
|
|
pipeworks.check_for_liquids = function(pos)
|
2013-01-04 09:15:23 +04:00
|
|
|
local coords = {
|
|
|
|
{x=pos.x,y=pos.y-1,z=pos.z},
|
|
|
|
{x=pos.x,y=pos.y+1,z=pos.z},
|
|
|
|
{x=pos.x-1,y=pos.y,z=pos.z},
|
|
|
|
{x=pos.x+1,y=pos.y,z=pos.z},
|
|
|
|
{x=pos.x,y=pos.y,z=pos.z-1},
|
|
|
|
{x=pos.x,y=pos.y,z=pos.z+1}, }
|
|
|
|
for i =1,6 do
|
2013-07-01 07:55:07 +04:00
|
|
|
local name = minetest.get_node(coords[i]).name
|
2013-08-08 06:16:47 +04:00
|
|
|
if name and string.find(name,"water") then
|
2013-07-04 08:01:08 +04:00
|
|
|
if finitewater then minetest.remove_node(coords[i]) end
|
2013-05-10 23:59:56 +04:00
|
|
|
return true
|
|
|
|
end
|
2013-01-04 09:15:23 +04:00
|
|
|
end
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
|
2013-12-15 11:53:10 +04:00
|
|
|
pipeworks.check_for_inflows = function(pos,node)
|
2013-01-04 09:15:23 +04:00
|
|
|
local coords = {
|
|
|
|
{x=pos.x,y=pos.y-1,z=pos.z},
|
|
|
|
{x=pos.x,y=pos.y+1,z=pos.z},
|
|
|
|
{x=pos.x-1,y=pos.y,z=pos.z},
|
|
|
|
{x=pos.x+1,y=pos.y,z=pos.z},
|
|
|
|
{x=pos.x,y=pos.y,z=pos.z-1},
|
2017-03-17 16:02:34 +03:00
|
|
|
{x=pos.x,y=pos.y,z=pos.z+1},
|
|
|
|
}
|
2013-01-04 09:15:23 +04:00
|
|
|
local newnode = false
|
|
|
|
local source = false
|
2017-03-17 16:02:34 +03:00
|
|
|
for i = 1, 6 do
|
2013-01-04 09:15:23 +04:00
|
|
|
if newnode then break end
|
2017-03-17 16:02:34 +03:00
|
|
|
local testnode = minetest.get_node(coords[i])
|
|
|
|
local name = testnode.name
|
2013-12-15 11:53:10 +04:00
|
|
|
if name and (name == "pipeworks:pump_on" and pipeworks.check_for_liquids(coords[i])) or string.find(name,"_loaded") then
|
2013-07-04 08:01:08 +04:00
|
|
|
if string.find(name,"_loaded") then
|
2013-12-21 14:11:36 +04:00
|
|
|
source = minetest.get_meta(coords[i]):get_string("source")
|
2013-01-04 09:15:23 +04:00
|
|
|
if source == minetest.pos_to_string(pos) then break end
|
|
|
|
end
|
2017-11-04 05:09:25 +03:00
|
|
|
if string.find(name, "valve") or string.find(name, "sensor")
|
|
|
|
or string.find(name, "straight_pipe") or string.find(name, "panel") then
|
2017-03-17 16:02:34 +03:00
|
|
|
|
|
|
|
if ((i == 3 or i == 4) and minetest.facedir_to_dir(testnode.param2).x ~= 0)
|
|
|
|
or ((i == 5 or i == 6) and minetest.facedir_to_dir(testnode.param2).z ~= 0)
|
|
|
|
or ((i == 1 or i == 2) and minetest.facedir_to_dir(testnode.param2).y ~= 0) then
|
|
|
|
|
|
|
|
newnode = string.gsub(node.name,"empty","loaded")
|
|
|
|
source = {x=coords[i].x,y=coords[i].y,z=coords[i].z}
|
|
|
|
end
|
|
|
|
else
|
|
|
|
newnode = string.gsub(node.name,"empty","loaded")
|
|
|
|
source = {x=coords[i].x,y=coords[i].y,z=coords[i].z}
|
|
|
|
end
|
2013-01-04 09:15:23 +04:00
|
|
|
end
|
|
|
|
end
|
2021-02-05 19:17:50 +03:00
|
|
|
if newnode then
|
|
|
|
minetest.add_node(pos,{name=newnode, param2 = node.param2})
|
2013-07-04 08:01:08 +04:00
|
|
|
minetest.get_meta(pos):set_string("source",minetest.pos_to_string(source))
|
2013-01-04 09:15:23 +04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-12-15 11:53:10 +04:00
|
|
|
pipeworks.check_sources = function(pos,node)
|
2013-07-04 08:01:08 +04:00
|
|
|
local sourcepos = minetest.string_to_pos(minetest.get_meta(pos):get_string("source"))
|
2013-05-11 01:28:11 +04:00
|
|
|
if not sourcepos then return end
|
2013-07-01 07:55:07 +04:00
|
|
|
local source = minetest.get_node(sourcepos).name
|
2013-01-04 09:15:23 +04:00
|
|
|
local newnode = false
|
2013-12-15 11:53:10 +04:00
|
|
|
if source and not ((source == "pipeworks:pump_on" and pipeworks.check_for_liquids(sourcepos)) or string.find(source,"_loaded") or source == "ignore" ) then
|
2013-07-04 08:01:08 +04:00
|
|
|
newnode = string.gsub(node.name,"loaded","empty")
|
2013-01-04 09:15:23 +04:00
|
|
|
end
|
|
|
|
|
2021-02-05 19:17:50 +03:00
|
|
|
if newnode then
|
|
|
|
minetest.add_node(pos,{name=newnode, param2 = node.param2})
|
2013-07-04 08:01:08 +04:00
|
|
|
minetest.get_meta(pos):set_string("source","")
|
2013-01-04 09:15:23 +04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-12-15 11:53:10 +04:00
|
|
|
pipeworks.spigot_check = function(pos, node)
|
2013-07-04 08:01:08 +04:00
|
|
|
local belowname = minetest.get_node({x=pos.x,y=pos.y-1,z=pos.z}).name
|
2022-03-15 04:39:58 +03:00
|
|
|
if belowname and (belowname == "air" or belowname == pipeworks.liquids.water.flowing or belowname == pipeworks.liquids.water.source) then
|
2013-07-04 08:01:08 +04:00
|
|
|
local spigotname = minetest.get_node(pos).name
|
2016-06-12 03:09:07 +03:00
|
|
|
local fdir=node.param2 % 4
|
2013-07-04 08:01:08 +04:00
|
|
|
local check = {
|
|
|
|
{x=pos.x,y=pos.y,z=pos.z+1},
|
|
|
|
{x=pos.x+1,y=pos.y,z=pos.z},
|
|
|
|
{x=pos.x,y=pos.y,z=pos.z-1},
|
|
|
|
{x=pos.x-1,y=pos.y,z=pos.z}
|
|
|
|
}
|
2013-08-08 06:16:47 +04:00
|
|
|
local near_node = minetest.get_node(check[fdir+1])
|
|
|
|
if near_node and string.find(near_node.name, "_loaded") then
|
|
|
|
if spigotname and spigotname == "pipeworks:spigot" then
|
2013-07-04 08:01:08 +04:00
|
|
|
minetest.add_node(pos,{name = "pipeworks:spigot_pouring", param2 = fdir})
|
2022-03-15 04:39:58 +03:00
|
|
|
if finitewater or belowname ~= pipeworks.liquids.water.source then
|
|
|
|
minetest.add_node({x=pos.x,y=pos.y-1,z=pos.z},{name = pipeworks.liquids.water.source})
|
2013-07-04 08:01:08 +04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
else
|
|
|
|
if spigotname == "pipeworks:spigot_pouring" then
|
|
|
|
minetest.add_node({x=pos.x,y=pos.y,z=pos.z},{name = "pipeworks:spigot", param2 = fdir})
|
2022-03-15 04:39:58 +03:00
|
|
|
if belowname == pipeworks.liquids.water.source and not finitewater then
|
2013-07-04 08:01:08 +04:00
|
|
|
minetest.remove_node({x=pos.x,y=pos.y-1,z=pos.z})
|
|
|
|
end
|
2013-05-11 00:17:47 +04:00
|
|
|
end
|
2013-04-29 01:45:25 +04:00
|
|
|
end
|
2013-01-04 09:15:23 +04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-12-15 11:53:10 +04:00
|
|
|
pipeworks.fountainhead_check = function(pos, node)
|
2013-10-28 06:38:19 +04:00
|
|
|
local abovename = minetest.get_node({x=pos.x,y=pos.y+1,z=pos.z}).name
|
2022-03-15 04:39:58 +03:00
|
|
|
if abovename and (abovename == "air" or abovename == pipeworks.liquids.water.flowing or abovename == pipeworks.liquids.water.source) then
|
2013-10-28 06:38:19 +04:00
|
|
|
local fountainhead_name = minetest.get_node(pos).name
|
|
|
|
local near_node = minetest.get_node({x=pos.x,y=pos.y-1,z=pos.z})
|
|
|
|
if near_node and string.find(near_node.name, "_loaded") then
|
|
|
|
if fountainhead_name and fountainhead_name == "pipeworks:fountainhead" then
|
|
|
|
minetest.add_node(pos,{name = "pipeworks:fountainhead_pouring"})
|
2022-03-15 04:39:58 +03:00
|
|
|
if finitewater or abovename ~= pipeworks.liquids.water.source then
|
|
|
|
minetest.add_node({x=pos.x,y=pos.y+1,z=pos.z},{name = pipeworks.liquids.water.source})
|
2013-10-28 06:38:19 +04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
else
|
|
|
|
if fountainhead_name == "pipeworks:fountainhead_pouring" then
|
|
|
|
minetest.add_node({x=pos.x,y=pos.y,z=pos.z},{name = "pipeworks:fountainhead"})
|
2022-03-15 04:39:58 +03:00
|
|
|
if abovename == pipeworks.liquids.water.source and not finitewater then
|
2013-10-28 06:38:19 +04:00
|
|
|
minetest.remove_node({x=pos.x,y=pos.y+1,z=pos.z})
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|