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
|
|
|
--
|
|
|
|
|
2013-07-04 08:01:08 +04:00
|
|
|
local finitewater = minetest.setting_getbool("liquid_finite")
|
|
|
|
|
2013-07-14 06:39:25 +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-07-14 06:39:25 +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},
|
|
|
|
{x=pos.x,y=pos.y,z=pos.z+1}, }
|
|
|
|
local newnode = false
|
|
|
|
local source = false
|
|
|
|
for i =1,6 do
|
|
|
|
if newnode then break end
|
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 (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
|
|
|
|
local 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
|
2013-07-04 08:01:08 +04:00
|
|
|
newnode = string.gsub(node.name,"empty","loaded")
|
2013-01-04 09:15:23 +04:00
|
|
|
source = {x=coords[i].x,y=coords[i].y,z=coords[i].z}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
if newnode then
|
2013-07-01 07:55:07 +04:00
|
|
|
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-07-14 06:39:25 +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-08-08 06:16:47 +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
|
|
|
|
|
|
|
|
if newnode then
|
2013-07-01 07:55:07 +04:00
|
|
|
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-07-14 06:39:25 +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
|
2013-08-08 06:16:47 +04:00
|
|
|
if belowname and (belowname == "air" or belowname == "default:water_flowing" or belowname == "default:water_source") then
|
2013-07-04 08:01:08 +04:00
|
|
|
local spigotname = minetest.get_node(pos).name
|
|
|
|
local fdir=node.param2
|
|
|
|
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})
|
|
|
|
if finitewater or belowname ~= "default:water_source" then
|
|
|
|
minetest.add_node({x=pos.x,y=pos.y-1,z=pos.z},{name = "default:water_source"})
|
|
|
|
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})
|
|
|
|
if belowname == "default:water_source" and not finitewater then
|
|
|
|
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
|
|
|
|
|