summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--flowing_logic.lua120
1 files changed, 54 insertions, 66 deletions
diff --git a/flowing_logic.lua b/flowing_logic.lua
index f654078..ff36377 100644
--- a/flowing_logic.lua
+++ b/flowing_logic.lua
@@ -3,6 +3,7 @@
local finite_liquids = minetest.setting_getbool("liquid_finite")
local pipe_liquid_shows_loaded = 1
+local max_pressure = 4
if mesecon then
pipereceptor_on = {
@@ -130,7 +131,7 @@ minetest.register_abm({
minetest.register_abm({
nodenames = {"pipeworks:pump_on", "pipeworks:pump_off"},
- interval = 2,
+ interval = 1,
chance = 1,
action = function(pos, node, active_object_count, active_object_count_wider)
local minp = {x = pos.x-1, y = pos.y-1, z = pos.z-1}
@@ -149,7 +150,7 @@ minetest.register_abm({
local water_nodes = minetest.find_nodes_in_area(minp, maxp,
{"default:water_source", "default:water_flowing"})
- if (node_level_above < 2 ) and #water_nodes > 1 then
+ if (node_level_above < max_pressure ) and #water_nodes > 1 then
meta:set_float("liquid_level", node_level_above + 4) -- add water to the pipe
end
else
@@ -161,85 +162,72 @@ minetest.register_abm({
end
})
--- Process all fountainheads in the area
+-- Process all spigots and fountainheads in the area
minetest.register_abm({
- nodenames = {"pipeworks:fountainhead"},
+ nodenames = {"pipeworks:spigot", "pipeworks:spigot_pouring", "pipeworks:fountainhead"},
interval = 2,
chance = 1,
action = function(pos, node, active_object_count, active_object_count_wider)
- local pos_above = {x = pos.x, y = pos.y+1, z = pos.z}
- local node_above = minetest.get_node(pos_above)
- if not node_above then return end
local pos_below = {x = pos.x, y = pos.y-1, z = pos.z}
- local node_below = minetest.get_node(pos_below)
- if not node_below then return end
-
- local node_level_below = (minetest.get_meta(pos_below):get_float("liquid_level")) or 0
-
- if node_level_below > 0.9
- and (node_above.name == "air" or node_above.name == "default:water_flowing") then
- minetest.set_node(pos_above, {name = "default:water_source"})
- elseif node_level_below < 0.75 and node_above.name == "default:water_source" then
- minetest.set_node(pos_above, {name = "air"})
- end
+ local below_node = minetest.get_node(pos_below)
+ if not below_node then return end
- if node_level_below >= 1
- and (node_above.name == "air" or node_above.name == "default:water_source") then
- minetest.get_meta(pos_below):set_float("liquid_level", node_level_below - 1)
- end
- end
-})
+ if node.name == "pipeworks:fountainhead" then
+ local pos_above = {x = pos.x, y = pos.y+1, z = pos.z}
+ local node_above = minetest.get_node(pos_above)
+ if not node_above then return end
--- Process all spigots in the area
+ local node_level_below = (minetest.get_meta(pos_below):get_float("liquid_level")) or 0
-minetest.register_abm({
- nodenames = {"pipeworks:spigot","pipeworks:spigot_pouring"},
- interval = 2,
- chance = 1,
- action = function(pos, node, active_object_count, active_object_count_wider)
- local pos_below = {x = pos.x, y = pos.y-1, z = pos.z}
- local below_node = minetest.get_node(pos_below)
- if not below_node then return end
+ if node_level_below > 1
+ and (node_above.name == "air" or node_above.name == "default:water_flowing") then
+ minetest.set_node(pos_above, {name = "default:water_source"})
+ elseif node_level_below < 0.95 and node_above.name == "default:water_source" then
+ minetest.set_node(pos_above, {name = "air"})
+ end
- if below_node.name == "air" or below_node.name == "default:water_flowing"
- or below_node.name == "default:water_source" then
- local fdir = node.param2
- local fdir_to_pos = {
- {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 }
- }
-
- local pos_adjacent = fdir_to_pos[fdir+1]
- local adjacent_node = minetest.get_node(pos_adjacent)
- if not adjacent_node then return end
- local adjacent_node_level = (minetest.get_meta(pos_adjacent):get_float("liquid_level")) or 0
- local pipe_name = string.match(adjacent_node.name, "pipeworks:pipe_%d.*_")
- local device_name = string.match(adjacent_node.name, "pipeworks:valve_on.*")
- or string.match(adjacent_node.name, "pipeworks:flow_sensor.*")
- or string.match(adjacent_node.name, "pipeworks:entry_panel")
-
-
- if pipe_name and adjacent_node_level > 0.9
- and (below_node.name == "air" or below_node.name == "default:water_flowing") then
- minetest.set_node(pos, {name = "pipeworks:spigot_pouring", param2 = fdir})
- minetest.set_node(pos_below, {name = "default:water_source"})
+ if node_level_below >= 1
+ and (node_above.name == "air" or node_above.name == "default:water_source") then
+ minetest.get_meta(pos_below):set_float("liquid_level", node_level_below - 1)
end
+ else
+ if below_node.name == "air" or below_node.name == "default:water_flowing"
+ or below_node.name == "default:water_source" then
+ local fdir = node.param2
+ local fdir_to_pos = {
+ {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 }
+ }
+
+ local pos_adjacent = fdir_to_pos[fdir+1]
+ local adjacent_node = minetest.get_node(pos_adjacent)
+ if not adjacent_node then return end
+
+ local adjacent_node_level = (minetest.get_meta(pos_adjacent):get_float("liquid_level")) or 0
+ local pipe_name = string.match(adjacent_node.name, "pipeworks:pipe_%d.*_")
+
+ if pipe_name and adjacent_node_level > 1
+ and (below_node.name == "air" or below_node.name == "default:water_flowing") then
+ minetest.set_node(pos, {name = "pipeworks:spigot_pouring", param2 = fdir})
+ minetest.set_node(pos_below, {name = "default:water_source"})
+ end
- if (pipe_name and adjacent_node_level < 0.75)
- or (node.name ~= "pipeworks:spigot" and not pipe_name) then
- minetest.set_node(pos,{name = "pipeworks:spigot", param2 = fdir})
- if below_node.name == "default:water_source" then
- minetest.set_node(pos_below, {name = "air"})
+ if (pipe_name and adjacent_node_level < 0.95)
+ or (node.name ~= "pipeworks:spigot" and not pipe_name) then
+ minetest.set_node(pos,{name = "pipeworks:spigot", param2 = fdir})
+ if below_node.name == "default:water_source" then
+ minetest.set_node(pos_below, {name = "air"})
+ end
end
- end
- if adjacent_node_level >= 1
- and (below_node.name == "air" or below_node.name == "default:water_source") then
- minetest.get_meta(pos_adjacent):set_float("liquid_level", adjacent_node_level - 1)
+ if adjacent_node_level >= 1
+ and (below_node.name == "air" or below_node.name == "default:water_source") then
+ minetest.get_meta(pos_adjacent):set_float("liquid_level", adjacent_node_level - 1)
+ end
end
end
end