2013-01-04 06:15:23 +01:00
|
|
|
-- This file provides the actual flow and pathfinding logic that makes water
|
|
|
|
-- move through the pipes.
|
|
|
|
--
|
2013-07-14 04:39:25 +02:00
|
|
|
-- Contributed by mauvebic, 2013-01-03, rewritten a bit by Vanessa Ezekowitz
|
2013-01-04 06:15:23 +01:00
|
|
|
--
|
|
|
|
|
2013-07-04 06:01:08 +02:00
|
|
|
local finitewater = minetest.setting_getbool("liquid_finite")
|
|
|
|
|
2013-12-15 08:53:10 +01:00
|
|
|
pipeworks.check_for_liquids = function(pos)
|
2013-01-04 06:15:23 +01: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 05:55:07 +02:00
|
|
|
local name = minetest.get_node(coords[i]).name
|
2013-08-08 04:16:47 +02:00
|
|
|
if name and string.find(name,"water") then
|
2013-07-04 06:01:08 +02:00
|
|
|
if finitewater then minetest.remove_node(coords[i]) end
|
2013-05-10 21:59:56 +02:00
|
|
|
return true
|
|
|
|
end
|
2013-01-04 06:15:23 +01:00
|
|
|
end
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
|
2013-12-15 08:53:10 +01:00
|
|
|
pipeworks.check_for_inflows = function(pos,node)
|
2013-01-04 06:15:23 +01: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 05:55:07 +02:00
|
|
|
local name = minetest.get_node(coords[i]).name
|
2013-12-15 08:53:10 +01:00
|
|
|
if name and (name == "pipeworks:pump_on" and pipeworks.check_for_liquids(coords[i])) or string.find(name,"_loaded") then
|
2013-07-04 06:01:08 +02:00
|
|
|
if string.find(name,"_loaded") then
|
2013-12-21 11:11:36 +01:00
|
|
|
source = minetest.get_meta(coords[i]):get_string("source")
|
2013-01-04 06:15:23 +01:00
|
|
|
if source == minetest.pos_to_string(pos) then break end
|
|
|
|
end
|
2013-07-04 06:01:08 +02:00
|
|
|
newnode = string.gsub(node.name,"empty","loaded")
|
2013-01-04 06:15:23 +01:00
|
|
|
source = {x=coords[i].x,y=coords[i].y,z=coords[i].z}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
if newnode then
|
2013-07-01 05:55:07 +02:00
|
|
|
minetest.add_node(pos,{name=newnode, param2 = node.param2})
|
2013-07-04 06:01:08 +02:00
|
|
|
minetest.get_meta(pos):set_string("source",minetest.pos_to_string(source))
|
2013-01-04 06:15:23 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-12-15 08:53:10 +01:00
|
|
|
pipeworks.check_sources = function(pos,node)
|
2013-07-04 06:01:08 +02:00
|
|
|
local sourcepos = minetest.string_to_pos(minetest.get_meta(pos):get_string("source"))
|
2013-05-10 23:28:11 +02:00
|
|
|
if not sourcepos then return end
|
2013-07-01 05:55:07 +02:00
|
|
|
local source = minetest.get_node(sourcepos).name
|
2013-01-04 06:15:23 +01:00
|
|
|
local newnode = false
|
2013-12-15 08:53:10 +01: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 06:01:08 +02:00
|
|
|
newnode = string.gsub(node.name,"loaded","empty")
|
2013-01-04 06:15:23 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
if newnode then
|
2013-07-01 05:55:07 +02:00
|
|
|
minetest.add_node(pos,{name=newnode, param2 = node.param2})
|
2013-07-04 06:01:08 +02:00
|
|
|
minetest.get_meta(pos):set_string("source","")
|
2013-01-04 06:15:23 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-12-15 08:53:10 +01:00
|
|
|
pipeworks.spigot_check = function(pos, node)
|
2013-07-04 06:01:08 +02:00
|
|
|
local belowname = minetest.get_node({x=pos.x,y=pos.y-1,z=pos.z}).name
|
2013-08-08 04:16:47 +02:00
|
|
|
if belowname and (belowname == "air" or belowname == "default:water_flowing" or belowname == "default:water_source") then
|
2013-07-04 06:01:08 +02: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 04:16:47 +02: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 06:01:08 +02: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-10 22:17:47 +02:00
|
|
|
end
|
2013-04-28 23:45:25 +02:00
|
|
|
end
|
2013-01-04 06:15:23 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-12-15 08:53:10 +01:00
|
|
|
pipeworks.fountainhead_check = function(pos, node)
|
2013-10-28 03:38:19 +01:00
|
|
|
local abovename = minetest.get_node({x=pos.x,y=pos.y+1,z=pos.z}).name
|
|
|
|
if abovename and (abovename == "air" or abovename == "default:water_flowing" or abovename == "default:water_source") then
|
|
|
|
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"})
|
|
|
|
if finitewater or abovename ~= "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 fountainhead_name == "pipeworks:fountainhead_pouring" then
|
|
|
|
minetest.add_node({x=pos.x,y=pos.y,z=pos.z},{name = "pipeworks:fountainhead"})
|
|
|
|
if abovename == "default:water_source" and not finitewater then
|
|
|
|
minetest.remove_node({x=pos.x,y=pos.y+1,z=pos.z})
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|