mirror of
https://github.com/sys4-fr/server-nalc.git
synced 2024-11-11 04:50:17 +01:00
Updated pipeworks (rollback)
This commit is contained in:
parent
4a96a86be3
commit
91e44ae813
|
@ -107,15 +107,15 @@ for s in ipairs(states) do
|
||||||
drop = "pipeworks:valve_off_empty",
|
drop = "pipeworks:valve_off_empty",
|
||||||
mesecons = {effector = {
|
mesecons = {effector = {
|
||||||
action_on = function (pos, node)
|
action_on = function (pos, node)
|
||||||
minetest.swap_node(pos,{name="pipeworks:valve_on_empty", param2 = node.param2})
|
minetest.add_node(pos,{name="pipeworks:valve_on_empty", param2 = node.param2})
|
||||||
end,
|
end,
|
||||||
action_off = function (pos, node)
|
action_off = function (pos, node)
|
||||||
minetest.swap_node(pos,{name="pipeworks:valve_off_empty", param2 = node.param2})
|
minetest.add_node(pos,{name="pipeworks:valve_off_empty", param2 = node.param2})
|
||||||
end
|
end
|
||||||
}},
|
}},
|
||||||
on_punch = function(pos, node, puncher)
|
on_punch = function(pos, node, puncher)
|
||||||
local fdir = minetest.get_node(pos).param2
|
local fdir = minetest.get_node(pos).param2
|
||||||
minetest.swap_node(pos, { name = "pipeworks:valve_"..states[3-s].."_empty", param2 = fdir })
|
minetest.add_node(pos, { name = "pipeworks:valve_"..states[3-s].."_empty", param2 = fdir })
|
||||||
end
|
end
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
@ -148,15 +148,15 @@ minetest.register_node("pipeworks:valve_on_loaded", {
|
||||||
drop = "pipeworks:valve_off_empty",
|
drop = "pipeworks:valve_off_empty",
|
||||||
mesecons = {effector = {
|
mesecons = {effector = {
|
||||||
action_on = function (pos, node)
|
action_on = function (pos, node)
|
||||||
minetest.swap_node(pos,{name="pipeworks:valve_on_empty", param2 = node.param2})
|
minetest.add_node(pos,{name="pipeworks:valve_on_empty", param2 = node.param2})
|
||||||
end,
|
end,
|
||||||
action_off = function (pos, node)
|
action_off = function (pos, node)
|
||||||
minetest.swap_node(pos,{name="pipeworks:valve_off_empty", param2 = node.param2})
|
minetest.add_node(pos,{name="pipeworks:valve_off_empty", param2 = node.param2})
|
||||||
end
|
end
|
||||||
}},
|
}},
|
||||||
on_punch = function(pos, node, puncher)
|
on_punch = function(pos, node, puncher)
|
||||||
local fdir = minetest.get_node(pos).param2
|
local fdir = minetest.get_node(pos).param2
|
||||||
minetest.swap_node(pos, { name = "pipeworks:valve_off_empty", param2 = fdir })
|
minetest.add_node(pos, { name = "pipeworks:valve_off_empty", param2 = fdir })
|
||||||
end
|
end
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -241,11 +241,6 @@ minetest.register_node("pipeworks:spigot_pouring", {
|
||||||
end,
|
end,
|
||||||
after_dig_node = function(pos)
|
after_dig_node = function(pos)
|
||||||
pipeworks.scan_for_pipe_objects(pos)
|
pipeworks.scan_for_pipe_objects(pos)
|
||||||
local pos_below = {x = pos.x, y = pos.y-1, z = pos.z}
|
|
||||||
local below_node = minetest.get_node(pos_below)
|
|
||||||
if below_node.name == "default:water_source" then
|
|
||||||
minetest.set_node(pos_below, { name = "air" })
|
|
||||||
end
|
|
||||||
end,
|
end,
|
||||||
selection_box = {
|
selection_box = {
|
||||||
type = "fixed",
|
type = "fixed",
|
||||||
|
@ -269,7 +264,7 @@ local panel_cbox = {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
minetest.register_node("pipeworks:entry_panel", {
|
minetest.register_node("pipeworks:entry_panel_empty", {
|
||||||
description = "Airtight Pipe entry/exit",
|
description = "Airtight Pipe entry/exit",
|
||||||
drawtype = "mesh",
|
drawtype = "mesh",
|
||||||
mesh = "pipeworks_entry_panel.obj",
|
mesh = "pipeworks_entry_panel.obj",
|
||||||
|
@ -325,7 +320,7 @@ minetest.register_node("pipeworks:entry_panel", {
|
||||||
|
|
||||||
if not minetest.registered_nodes[minetest.get_node(pos1).name]["buildable_to"] then return end
|
if not minetest.registered_nodes[minetest.get_node(pos1).name]["buildable_to"] then return end
|
||||||
|
|
||||||
minetest.add_node(pos1, {name = "pipeworks:entry_panel", param2 = fdir })
|
minetest.add_node(pos1, {name = "pipeworks:entry_panel_empty", param2 = fdir })
|
||||||
pipeworks.scan_for_pipe_objects(pos1)
|
pipeworks.scan_for_pipe_objects(pos1)
|
||||||
|
|
||||||
if not pipeworks.expect_infinite_stacks then
|
if not pipeworks.expect_infinite_stacks then
|
||||||
|
@ -340,10 +335,26 @@ minetest.register_node("pipeworks:entry_panel", {
|
||||||
end
|
end
|
||||||
})
|
})
|
||||||
|
|
||||||
local sensorboxes = {}
|
minetest.register_node("pipeworks:entry_panel_loaded", {
|
||||||
pipeworks.add_node_box(sensorboxes, pipeworks.pipe_leftstub)
|
description = "Airtight Pipe entry/exit",
|
||||||
pipeworks.add_node_box(sensorboxes, pipeworks.pipe_sensorbody)
|
drawtype = "mesh",
|
||||||
pipeworks.add_node_box(sensorboxes, pipeworks.pipe_rightstub)
|
mesh = "pipeworks_entry_panel.obj",
|
||||||
|
tiles = { "pipeworks_entry_panel.png" },
|
||||||
|
paramtype = "light",
|
||||||
|
paramtype2 = "facedir",
|
||||||
|
groups = {snappy=3, pipe=1, not_in_creative_inventory=1},
|
||||||
|
sounds = default.node_sound_wood_defaults(),
|
||||||
|
walkable = true,
|
||||||
|
after_place_node = function(pos)
|
||||||
|
pipeworks.scan_for_pipe_objects(pos)
|
||||||
|
end,
|
||||||
|
after_dig_node = function(pos)
|
||||||
|
pipeworks.scan_for_pipe_objects(pos)
|
||||||
|
end,
|
||||||
|
selection_box = panel_cbox,
|
||||||
|
collision_box = panel_cbox,
|
||||||
|
drop = "pipeworks:entry_panel_empty"
|
||||||
|
})
|
||||||
|
|
||||||
minetest.register_node("pipeworks:flow_sensor_empty", {
|
minetest.register_node("pipeworks:flow_sensor_empty", {
|
||||||
description = "Flow Sensor",
|
description = "Flow Sensor",
|
||||||
|
@ -507,11 +518,6 @@ minetest.register_node("pipeworks:fountainhead", {
|
||||||
end,
|
end,
|
||||||
after_dig_node = function(pos)
|
after_dig_node = function(pos)
|
||||||
pipeworks.scan_for_pipe_objects(pos)
|
pipeworks.scan_for_pipe_objects(pos)
|
||||||
local pos_above = {x = pos.x, y = pos.y+1, z = pos.z}
|
|
||||||
local node_above = minetest.get_node(pos_above)
|
|
||||||
if node_above.name == "default:water_source" then
|
|
||||||
minetest.set_node(pos_above, { name = "air" })
|
|
||||||
end
|
|
||||||
end,
|
end,
|
||||||
on_construct = function(pos)
|
on_construct = function(pos)
|
||||||
if mesecon then
|
if mesecon then
|
||||||
|
@ -528,10 +534,37 @@ minetest.register_node("pipeworks:fountainhead", {
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
-- compatibility
|
minetest.register_node("pipeworks:fountainhead_pouring", {
|
||||||
|
description = "Fountainhead",
|
||||||
|
drawtype = "mesh",
|
||||||
|
mesh = "pipeworks_fountainhead.obj",
|
||||||
|
tiles = { "pipeworks_fountainhead.png" },
|
||||||
|
sunlight_propagates = true,
|
||||||
|
paramtype = "light",
|
||||||
|
groups = {snappy=3, pipe=1, not_in_creative_inventory=1},
|
||||||
|
sounds = default.node_sound_wood_defaults(),
|
||||||
|
walkable = true,
|
||||||
|
after_place_node = function(pos)
|
||||||
|
pipeworks.scan_for_pipe_objects(pos)
|
||||||
|
end,
|
||||||
|
after_dig_node = function(pos)
|
||||||
|
pipeworks.scan_for_pipe_objects(pos)
|
||||||
|
end,
|
||||||
|
on_construct = function(pos)
|
||||||
|
if mesecon then
|
||||||
|
mesecon.receptor_on(pos, rules)
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
selection_box = {
|
||||||
|
type = "fixed",
|
||||||
|
fixed = { -2/16, -8/16, -2/16, 2/16, 8/16, 2/16 }
|
||||||
|
},
|
||||||
|
collision_box = {
|
||||||
|
type = "fixed",
|
||||||
|
fixed = { -2/16, -8/16, -2/16, 2/16, 8/16, 2/16 }
|
||||||
|
},
|
||||||
|
drop = "pipeworks:fountainhead"
|
||||||
|
})
|
||||||
|
|
||||||
minetest.register_alias("pipeworks:valve_off_loaded", "pipeworks:valve_off_empty")
|
minetest.register_alias("pipeworks:valve_off_loaded", "pipeworks:valve_off_empty")
|
||||||
minetest.register_alias("pipeworks:fountainhead_pouring", "pipeworks:fountainhead")
|
|
||||||
|
|
||||||
minetest.register_alias("pipeworks:entry_panel_empty", "pipeworks:entry_panel")
|
|
||||||
minetest.register_alias("pipeworks:entry_panel_loaded", "pipeworks:entry_panel")
|
|
||||||
|
|
|
@ -1,344 +1,121 @@
|
||||||
-- This file provides the actual flow logic that makes liquids
|
-- This file provides the actual flow and pathfinding logic that makes water
|
||||||
-- move through the pipes.
|
-- move through the pipes.
|
||||||
|
--
|
||||||
|
-- Contributed by mauvebic, 2013-01-03, rewritten a bit by Vanessa Ezekowitz
|
||||||
|
--
|
||||||
|
|
||||||
local finite_liquids = minetest.setting_getbool("liquid_finite")
|
local finitewater = minetest.setting_getbool("liquid_finite")
|
||||||
local pipe_liquid_shows_loaded = 1
|
|
||||||
local max_pressure = 4
|
|
||||||
|
|
||||||
if mesecon then
|
pipeworks.check_for_liquids = function(pos)
|
||||||
pipereceptor_on = {
|
local coords = {
|
||||||
receptor = {
|
{x=pos.x,y=pos.y-1,z=pos.z},
|
||||||
state = mesecon.state.on,
|
{x=pos.x,y=pos.y+1,z=pos.z},
|
||||||
rules = pipeworks.mesecons_rules
|
{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}, }
|
||||||
pipereceptor_off = {
|
for i =1,6 do
|
||||||
receptor = {
|
local name = minetest.get_node(coords[i]).name
|
||||||
state = mesecon.state.off,
|
if name and string.find(name,"water") then
|
||||||
rules = pipeworks.mesecons_rules
|
if finitewater then minetest.remove_node(coords[i]) end
|
||||||
}
|
return true
|
||||||
}
|
end
|
||||||
|
end
|
||||||
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
-- check if a valve, sensor, or other X-oriented device
|
pipeworks.check_for_inflows = function(pos,node)
|
||||||
-- has something connected at each end.
|
local coords = {
|
||||||
|
{x=pos.x,y=pos.y-1,z=pos.z},
|
||||||
function pipeworks.is_device_connected(pos, node, axisdir, fdir_mod4, rotation)
|
{x=pos.x,y=pos.y+1,z=pos.z},
|
||||||
local fdir = node.param2
|
{x=pos.x-1,y=pos.y,z=pos.z},
|
||||||
local fdir_mod4_p2 = (fdir+2) % 4
|
{x=pos.x+1,y=pos.y,z=pos.z},
|
||||||
|
{x=pos.x,y=pos.y,z=pos.z-1},
|
||||||
if rotation == "z" then
|
{x=pos.x,y=pos.y,z=pos.z+1}, }
|
||||||
fdir_mod4 = (fdir+1) % 4
|
local newnode = false
|
||||||
fdir_mod4_p2 = (fdir+3) % 4
|
local source = false
|
||||||
|
for i =1,6 do
|
||||||
|
if newnode then break end
|
||||||
|
local name = minetest.get_node(coords[i]).name
|
||||||
|
if name and (name == "pipeworks:pump_on" and pipeworks.check_for_liquids(coords[i])) or string.find(name,"_loaded") then
|
||||||
|
if string.find(name,"_loaded") then
|
||||||
|
source = minetest.get_meta(coords[i]):get_string("source")
|
||||||
|
if source == minetest.pos_to_string(pos) then break end
|
||||||
|
end
|
||||||
|
newnode = string.gsub(node.name,"empty","loaded")
|
||||||
|
source = {x=coords[i].x,y=coords[i].y,z=coords[i].z}
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
if newnode then
|
||||||
local fdir_to_pos = {
|
minetest.add_node(pos,{name=newnode, param2 = node.param2})
|
||||||
{x = pos.x+1, y = pos.y, z = pos.z },
|
minetest.get_meta(pos):set_string("source",minetest.pos_to_string(source))
|
||||||
{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},
|
|
||||||
}
|
|
||||||
|
|
||||||
local pos_adjacent1 = fdir_to_pos[fdir_mod4 + 1]
|
|
||||||
local pos_adjacent2 = fdir_to_pos[fdir_mod4_p2 + 1]
|
|
||||||
|
|
||||||
if rotation == "y" then
|
|
||||||
pos_adjacent1 = { x=pos.x, y=pos.y+1, z=pos.z }
|
|
||||||
pos_adjacent2 = { x=pos.x, y=pos.y-1, z=pos.z }
|
|
||||||
end
|
end
|
||||||
|
|
||||||
local adjacent_node1 = minetest.get_node(pos_adjacent1)
|
|
||||||
local adjacent_node2 = minetest.get_node(pos_adjacent2)
|
|
||||||
|
|
||||||
local set1
|
|
||||||
local set2
|
|
||||||
|
|
||||||
if string.find(dump(pipeworks.pipe_nodenames), adjacent_node1.name) or
|
|
||||||
(string.find(dump(pipeworks.device_nodenames), adjacent_node1.name) and
|
|
||||||
(adjacent_node1.param2 == fdir_mod4 or adjacent_node1.param2 == fdir_mod4_p2)) then
|
|
||||||
set1 = true
|
|
||||||
end
|
|
||||||
|
|
||||||
if string.find(dump(pipeworks.pipe_nodenames), adjacent_node2.name) or
|
|
||||||
(string.find(dump(pipeworks.device_nodenames), adjacent_node2.name) and
|
|
||||||
(adjacent_node2.param2 == fdir_mod4 or adjacent_node2.param2 == fdir_mod4_p2)) then
|
|
||||||
set2 = true
|
|
||||||
end
|
|
||||||
return {set1=set1, set2=set2, pos_adjacent1=pos_adjacent1, pos_adjacent2=pos_adjacent2}
|
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Evaluate and balance liquid in all pipes
|
pipeworks.check_sources = function(pos,node)
|
||||||
|
local sourcepos = minetest.string_to_pos(minetest.get_meta(pos):get_string("source"))
|
||||||
|
if not sourcepos then return end
|
||||||
|
local source = minetest.get_node(sourcepos).name
|
||||||
|
local newnode = false
|
||||||
|
if source and not ((source == "pipeworks:pump_on" and pipeworks.check_for_liquids(sourcepos)) or string.find(source,"_loaded") or source == "ignore" ) then
|
||||||
|
newnode = string.gsub(node.name,"loaded","empty")
|
||||||
|
end
|
||||||
|
|
||||||
minetest.register_abm({
|
if newnode then
|
||||||
label = "Liquid balancing",
|
minetest.add_node(pos,{name=newnode, param2 = node.param2})
|
||||||
nodenames = pipeworks.pipe_nodenames,
|
minetest.get_meta(pos):set_string("source","")
|
||||||
interval = 1,
|
end
|
||||||
chance = 1,
|
end
|
||||||
action = function(pos, node, active_object_count, active_object_count_wider)
|
|
||||||
local coords = {
|
pipeworks.spigot_check = function(pos, node)
|
||||||
{x = pos.x, y = pos.y, z = pos.z},
|
local belowname = minetest.get_node({x=pos.x,y=pos.y-1,z=pos.z}).name
|
||||||
{x = pos.x, y = pos.y-1, z = pos.z},
|
if belowname and (belowname == "air" or belowname == "default:water_flowing" or belowname == "default:water_source") then
|
||||||
{x = pos.x, y = pos.y+1, z = pos.z},
|
local spigotname = minetest.get_node(pos).name
|
||||||
{x = pos.x-1, y = pos.y, z = pos.z},
|
local fdir=node.param2
|
||||||
{x = pos.x+1, y = pos.y, z = pos.z},
|
local check = {
|
||||||
{x = pos.x, y = pos.y, z = pos.z-1},
|
{x=pos.x,y=pos.y,z=pos.z+1},
|
||||||
{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 near_node = minetest.get_node(check[fdir+1])
|
||||||
local num_connections = 0
|
if near_node and string.find(near_node.name, "_loaded") then
|
||||||
local connection_list = {}
|
if spigotname and spigotname == "pipeworks:spigot" then
|
||||||
local total_level = 0
|
minetest.add_node(pos,{name = "pipeworks:spigot_pouring", param2 = fdir})
|
||||||
|
if finitewater or belowname ~= "default:water_source" then
|
||||||
for _,adjacentpos in ipairs(coords) do
|
minetest.add_node({x=pos.x,y=pos.y-1,z=pos.z},{name = "default:water_source"})
|
||||||
local adjacent_node = minetest.get_node(adjacentpos)
|
|
||||||
if adjacent_node and string.find(dump(pipeworks.pipe_nodenames), adjacent_node.name) then
|
|
||||||
|
|
||||||
local node_level = (minetest.get_meta(adjacentpos):get_float("liquid_level")) or 0
|
|
||||||
if node_level < 0 then node_level = 0 end
|
|
||||||
|
|
||||||
total_level = total_level + node_level
|
|
||||||
num_connections = num_connections + 1
|
|
||||||
table.insert(connection_list, adjacentpos)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
local average_level = total_level / num_connections
|
|
||||||
|
|
||||||
for _, connected_pipe_pos in ipairs(connection_list) do
|
|
||||||
|
|
||||||
local newnode
|
|
||||||
local connected_pipe = minetest.get_node(connected_pipe_pos)
|
|
||||||
local pipe_name = string.match(connected_pipe.name, "pipeworks:pipe_%d.*_")
|
|
||||||
|
|
||||||
if connected_pipe and pipe_name then
|
|
||||||
minetest.get_meta(connected_pipe_pos):set_float("liquid_level", average_level)
|
|
||||||
|
|
||||||
if average_level > pipe_liquid_shows_loaded then
|
|
||||||
newnode = pipe_name.."loaded"
|
|
||||||
else
|
|
||||||
newnode = pipe_name.."empty"
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if newnode and connected_pipe.name ~= newnode then
|
|
||||||
minetest.swap_node(connected_pipe_pos, {name = newnode, param2 = connected_pipe.param2})
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
})
|
|
||||||
|
|
||||||
-- Process all pumps in the area
|
|
||||||
|
|
||||||
minetest.register_abm({
|
|
||||||
label = "Pump processing",
|
|
||||||
nodenames = {"pipeworks:pump_on", "pipeworks:pump_off"},
|
|
||||||
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}
|
|
||||||
local maxp = {x = pos.x+1, y = pos.y, z = pos.z+1}
|
|
||||||
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 meta = minetest.get_meta(pos_above)
|
|
||||||
local node_level_above = meta:get_float("liquid_level")
|
|
||||||
if node_level_above == nil then node_level_above = 0 end
|
|
||||||
local pipe_name = string.match(node_above.name, "pipeworks:pipe_%d.*_")
|
|
||||||
|
|
||||||
if pipe_name then
|
|
||||||
if node.name == "pipeworks:pump_on" then
|
|
||||||
local water_nodes = minetest.find_nodes_in_area(minp, maxp,
|
|
||||||
{"default:water_source", "default:water_flowing"})
|
|
||||||
|
|
||||||
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
|
|
||||||
if node_level_above > 0 then
|
|
||||||
meta:set_float("liquid_level", node_level_above - 0.5 ) -- leak the pipe down
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
})
|
|
||||||
|
|
||||||
-- Process all spigots and fountainheads in the area
|
|
||||||
|
|
||||||
minetest.register_abm({
|
|
||||||
label = "Spigot/Fountainhead processing",
|
|
||||||
nodenames = {"pipeworks:spigot", "pipeworks:spigot_pouring", "pipeworks:fountainhead"},
|
|
||||||
interval = 2,
|
|
||||||
chance = 1,
|
|
||||||
action = function(pos, node, active_object_count, active_object_count_wider)
|
|
||||||
|
|
||||||
local fdir = node.param2 % 4
|
|
||||||
if fdir ~= node.param2 then
|
|
||||||
minetest.set_node(pos,{name = node.name, param2 = fdir})
|
|
||||||
end
|
|
||||||
|
|
||||||
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.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
|
|
||||||
|
|
||||||
local node_level_below = (minetest.get_meta(pos_below):get_float("liquid_level")) or 0
|
|
||||||
|
|
||||||
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 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
|
else
|
||||||
if below_node.name == "air" or below_node.name == "default:water_flowing"
|
if spigotname == "pipeworks:spigot_pouring" then
|
||||||
or below_node.name == "default:water_source" 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
|
||||||
local fdir_to_pos = {
|
minetest.remove_node({x=pos.x,y=pos.y-1,z=pos.z})
|
||||||
{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.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
|
|
||||||
|
|
||||||
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
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
})
|
end
|
||||||
|
|
||||||
pipeworks.device_nodenames = {}
|
pipeworks.fountainhead_check = function(pos, node)
|
||||||
|
local abovename = minetest.get_node({x=pos.x,y=pos.y+1,z=pos.z}).name
|
||||||
table.insert(pipeworks.device_nodenames,"pipeworks:valve_on_empty")
|
if abovename and (abovename == "air" or abovename == "default:water_flowing" or abovename == "default:water_source") then
|
||||||
table.insert(pipeworks.device_nodenames,"pipeworks:valve_off_empty")
|
local fountainhead_name = minetest.get_node(pos).name
|
||||||
table.insert(pipeworks.device_nodenames,"pipeworks:valve_on_loaded")
|
local near_node = minetest.get_node({x=pos.x,y=pos.y-1,z=pos.z})
|
||||||
table.insert(pipeworks.device_nodenames,"pipeworks:flow_sensor_empty")
|
if near_node and string.find(near_node.name, "_loaded") then
|
||||||
table.insert(pipeworks.device_nodenames,"pipeworks:flow_sensor_loaded")
|
if fountainhead_name and fountainhead_name == "pipeworks:fountainhead" then
|
||||||
table.insert(pipeworks.device_nodenames,"pipeworks:entry_panel")
|
minetest.add_node(pos,{name = "pipeworks:fountainhead_pouring"})
|
||||||
|
if finitewater or abovename ~= "default:water_source" then
|
||||||
minetest.register_abm({
|
minetest.add_node({x=pos.x,y=pos.y+1,z=pos.z},{name = "default:water_source"})
|
||||||
label = "Waterdevices processing",
|
|
||||||
nodenames = pipeworks.device_nodenames,
|
|
||||||
interval = 2,
|
|
||||||
chance = 1,
|
|
||||||
action = function(pos, node, active_object_count, active_object_count_wider)
|
|
||||||
|
|
||||||
local fdir = node.param2
|
|
||||||
local axisdir = math.floor(fdir/4)
|
|
||||||
local fdir_mod4 = fdir % 4
|
|
||||||
local rotation
|
|
||||||
|
|
||||||
if not string.match(node.name, "pipeworks:valve_off") then
|
|
||||||
|
|
||||||
if node.name == "pipeworks:entry_panel" then
|
|
||||||
rotation = "z"
|
|
||||||
fdir_mod4 = (fdir+1) % 4
|
|
||||||
|
|
||||||
-- reset the panel's facedir to predictable values, if needed
|
|
||||||
|
|
||||||
if axisdir == 5 then
|
|
||||||
minetest.swap_node(pos, {name = node.name, param2 = fdir_mod4 })
|
|
||||||
return
|
|
||||||
elseif axisdir ~= 0 and axisdir ~= 3 then
|
|
||||||
minetest.swap_node(pos, {name = node.name, param2 = 13 })
|
|
||||||
return
|
|
||||||
end
|
end
|
||||||
|
|
||||||
if node.param2 == 13 then
|
|
||||||
rotation = "y"
|
|
||||||
end
|
|
||||||
elseif axisdir ~= 0 and axisdir ~= 5 then -- if the device isn't horizontal, force it.
|
|
||||||
minetest.swap_node(pos, {name = node.name, param2 = fdir_mod4})
|
|
||||||
return
|
|
||||||
end
|
end
|
||||||
|
else
|
||||||
local connections = pipeworks.is_device_connected(pos, node, axisdir, fdir_mod4, rotation)
|
if fountainhead_name == "pipeworks:fountainhead_pouring" then
|
||||||
|
minetest.add_node({x=pos.x,y=pos.y,z=pos.z},{name = "pipeworks:fountainhead"})
|
||||||
local num_connections = 1
|
if abovename == "default:water_source" and not finitewater then
|
||||||
local my_level = (minetest.get_meta(pos):get_float("liquid_level")) or 0
|
minetest.remove_node({x=pos.x,y=pos.y+1,z=pos.z})
|
||||||
local total_level = my_level
|
|
||||||
|
|
||||||
if not connections.set1 and not connections.set2 then return end
|
|
||||||
|
|
||||||
if connections.set1 then
|
|
||||||
num_connections = num_connections + 1
|
|
||||||
total_level = total_level + (minetest.get_meta(connections.pos_adjacent1):get_float("liquid_level")) or 0
|
|
||||||
end
|
|
||||||
|
|
||||||
if connections.set2 then
|
|
||||||
num_connections = num_connections + 1
|
|
||||||
total_level = total_level + (minetest.get_meta(connections.pos_adjacent2):get_float("liquid_level")) or 0
|
|
||||||
end
|
|
||||||
|
|
||||||
local average_level = total_level / num_connections
|
|
||||||
|
|
||||||
minetest.get_meta(pos):set_float("liquid_level", average_level)
|
|
||||||
|
|
||||||
if connections.set1 then
|
|
||||||
minetest.get_meta(connections.pos_adjacent1):set_float("liquid_level", average_level)
|
|
||||||
end
|
|
||||||
|
|
||||||
if connections.set2 then
|
|
||||||
minetest.get_meta(connections.pos_adjacent2):set_float("liquid_level", average_level)
|
|
||||||
end
|
|
||||||
|
|
||||||
if node.name == "pipeworks:flow_sensor_empty" or
|
|
||||||
node.name == "pipeworks:flow_sensor_loaded" then
|
|
||||||
local sensor = string.match(node.name, "pipeworks:flow_sensor_")
|
|
||||||
local newnode = nil
|
|
||||||
|
|
||||||
if my_level > 1 and (connections.set1 or connections.set2) then
|
|
||||||
newnode = sensor.."loaded"
|
|
||||||
else
|
|
||||||
newnode = sensor.."empty"
|
|
||||||
end
|
|
||||||
|
|
||||||
if newnode ~= node.name then
|
|
||||||
minetest.swap_node(pos, {name = newnode, param2 = node.param2})
|
|
||||||
if mesecon then
|
|
||||||
if newnode == "pipeworks:flow_sensor_empty" then
|
|
||||||
mesecon.receptor_off(pos, rules)
|
|
||||||
else
|
|
||||||
mesecon.receptor_on(pos, rules)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
})
|
end
|
||||||
|
|
||||||
|
|
|
@ -39,8 +39,6 @@ pipeworks.mesecons_rules={{x=0,y=0,z=1},{x=0,y=0,z=-1},{x=1,y=0,z=0},{x=-1,y=0,z
|
||||||
|
|
||||||
pipeworks.liquid_texture = "default_water.png"
|
pipeworks.liquid_texture = "default_water.png"
|
||||||
|
|
||||||
pipeworks.pipe_nodenames = {}
|
|
||||||
|
|
||||||
-- Helper functions
|
-- Helper functions
|
||||||
|
|
||||||
function pipeworks.fix_image_names(table, replacement)
|
function pipeworks.fix_image_names(table, replacement)
|
||||||
|
@ -106,18 +104,6 @@ function pipeworks.replace_name(tbl,tr,name)
|
||||||
return ntbl
|
return ntbl
|
||||||
end
|
end
|
||||||
|
|
||||||
function pipeworks.table_copy(t)
|
|
||||||
local nt = { };
|
|
||||||
for k, v in pairs(t) do
|
|
||||||
if type(v) == "table" then
|
|
||||||
nt[k] = pipeworks.table_copy(v)
|
|
||||||
else
|
|
||||||
nt[k] = v
|
|
||||||
end
|
|
||||||
end
|
|
||||||
return nt
|
|
||||||
end
|
|
||||||
|
|
||||||
-------------------------------------------
|
-------------------------------------------
|
||||||
-- Load the various other parts of the mod
|
-- Load the various other parts of the mod
|
||||||
|
|
||||||
|
@ -127,10 +113,7 @@ dofile(pipeworks.modpath.."/autoplace_pipes.lua")
|
||||||
dofile(pipeworks.modpath.."/autoplace_tubes.lua")
|
dofile(pipeworks.modpath.."/autoplace_tubes.lua")
|
||||||
dofile(pipeworks.modpath.."/luaentity.lua")
|
dofile(pipeworks.modpath.."/luaentity.lua")
|
||||||
dofile(pipeworks.modpath.."/item_transport.lua")
|
dofile(pipeworks.modpath.."/item_transport.lua")
|
||||||
|
|
||||||
if pipeworks.enable_pipes then dofile(pipeworks.modpath.."/pipes.lua") end
|
|
||||||
dofile(pipeworks.modpath.."/flowing_logic.lua")
|
dofile(pipeworks.modpath.."/flowing_logic.lua")
|
||||||
|
|
||||||
dofile(pipeworks.modpath.."/crafts.lua")
|
dofile(pipeworks.modpath.."/crafts.lua")
|
||||||
dofile(pipeworks.modpath.."/tube_registration.lua")
|
dofile(pipeworks.modpath.."/tube_registration.lua")
|
||||||
dofile(pipeworks.modpath.."/routing_tubes.lua")
|
dofile(pipeworks.modpath.."/routing_tubes.lua")
|
||||||
|
@ -142,6 +125,7 @@ dofile(pipeworks.modpath.."/filter-injector.lua")
|
||||||
dofile(pipeworks.modpath.."/trashcan.lua")
|
dofile(pipeworks.modpath.."/trashcan.lua")
|
||||||
dofile(pipeworks.modpath.."/wielder.lua")
|
dofile(pipeworks.modpath.."/wielder.lua")
|
||||||
|
|
||||||
|
if pipeworks.enable_pipes then dofile(pipeworks.modpath.."/pipes.lua") end
|
||||||
if pipeworks.enable_teleport_tube then dofile(pipeworks.modpath.."/teleport_tube.lua") end
|
if pipeworks.enable_teleport_tube then dofile(pipeworks.modpath.."/teleport_tube.lua") end
|
||||||
if pipeworks.enable_pipe_devices then dofile(pipeworks.modpath.."/devices.lua") end
|
if pipeworks.enable_pipe_devices then dofile(pipeworks.modpath.."/devices.lua") end
|
||||||
if pipeworks.enable_redefines then dofile(pipeworks.modpath.."/compat.lua") end
|
if pipeworks.enable_redefines then dofile(pipeworks.modpath.."/compat.lua") end
|
||||||
|
|
|
@ -2,6 +2,9 @@
|
||||||
|
|
||||||
local REGISTER_COMPATIBILITY = true
|
local REGISTER_COMPATIBILITY = true
|
||||||
|
|
||||||
|
local pipes_empty_nodenames = {}
|
||||||
|
local pipes_full_nodenames = {}
|
||||||
|
|
||||||
local vti = {4, 3, 2, 1, 6, 5}
|
local vti = {4, 3, 2, 1, 6, 5}
|
||||||
local cconnects = {{}, {1}, {1, 2}, {1, 3}, {1, 3, 5}, {1, 2, 3}, {1, 2, 3, 5}, {1, 2, 3, 4}, {1, 2, 3, 4, 5}, {1, 2, 3, 4, 5, 6}}
|
local cconnects = {{}, {1}, {1, 2}, {1, 3}, {1, 3, 5}, {1, 2, 3}, {1, 2, 3, 5}, {1, 2, 3, 4}, {1, 2, 3, 4, 5}, {1, 2, 3, 4, 5, 6}}
|
||||||
for index, connects in ipairs(cconnects) do
|
for index, connects in ipairs(cconnects) do
|
||||||
|
@ -110,10 +113,12 @@ for index, connects in ipairs(cconnects) do
|
||||||
end
|
end
|
||||||
})
|
})
|
||||||
|
|
||||||
table.insert(pipeworks.pipe_nodenames, "pipeworks:pipe_"..index.."_empty")
|
table.insert(pipes_empty_nodenames, "pipeworks:pipe_"..index.."_empty")
|
||||||
table.insert(pipeworks.pipe_nodenames, "pipeworks:pipe_"..index.."_loaded")
|
table.insert(pipes_full_nodenames, "pipeworks:pipe_"..index.."_loaded")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if REGISTER_COMPATIBILITY then
|
if REGISTER_COMPATIBILITY then
|
||||||
local cempty = "pipeworks:pipe_compatibility_empty"
|
local cempty = "pipeworks:pipe_compatibility_empty"
|
||||||
local cloaded = "pipeworks:pipe_compatibility_loaded"
|
local cloaded = "pipeworks:pipe_compatibility_loaded"
|
||||||
|
@ -170,3 +175,48 @@ if REGISTER_COMPATIBILITY then
|
||||||
})
|
})
|
||||||
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:entry_panel_empty")
|
||||||
|
table.insert(pipes_empty_nodenames,"pipeworks:flow_sensor_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,
|
||||||
|
chance = 1,
|
||||||
|
action = function(pos, node, active_object_count, active_object_count_wider)
|
||||||
|
pipeworks.check_for_inflows(pos,node)
|
||||||
|
end
|
||||||
|
})
|
||||||
|
|
||||||
|
minetest.register_abm({
|
||||||
|
nodenames = pipes_full_nodenames,
|
||||||
|
interval = 1,
|
||||||
|
chance = 1,
|
||||||
|
action = function(pos, node, active_object_count, active_object_count_wider)
|
||||||
|
pipeworks.check_sources(pos,node)
|
||||||
|
end
|
||||||
|
})
|
||||||
|
|
||||||
|
minetest.register_abm({
|
||||||
|
nodenames = {"pipeworks:spigot","pipeworks:spigot_pouring"},
|
||||||
|
interval = 1,
|
||||||
|
chance = 1,
|
||||||
|
action = function(pos, node, active_object_count, active_object_count_wider)
|
||||||
|
pipeworks.spigot_check(pos,node)
|
||||||
|
end
|
||||||
|
})
|
||||||
|
|
||||||
|
minetest.register_abm({
|
||||||
|
nodenames = {"pipeworks:fountainhead","pipeworks:fountainhead_pouring"},
|
||||||
|
interval = 1,
|
||||||
|
chance = 1,
|
||||||
|
action = function(pos, node, active_object_count, active_object_count_wider)
|
||||||
|
pipeworks.fountainhead_check(pos,node)
|
||||||
|
end
|
||||||
|
})
|
||||||
|
|
||||||
|
|
|
@ -107,9 +107,9 @@ local function vacuum(pos, radius)
|
||||||
end
|
end
|
||||||
|
|
||||||
minetest.register_abm({nodenames = {"group:vacuum_tube"},
|
minetest.register_abm({nodenames = {"group:vacuum_tube"},
|
||||||
label = "Vacuum tubes",
|
|
||||||
interval = 1,
|
interval = 1,
|
||||||
chance = 1,
|
chance = 1,
|
||||||
|
label = "Vacuum tubes",
|
||||||
action = function(pos, node, active_object_count, active_object_count_wider)
|
action = function(pos, node, active_object_count, active_object_count_wider)
|
||||||
if node.name == "pipeworks:sand_tube" then
|
if node.name == "pipeworks:sand_tube" then
|
||||||
vacuum(pos, 2)
|
vacuum(pos, 2)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user