mirror of
https://github.com/mt-mods/pipeworks.git
synced 2024-11-13 22:10:32 +01:00
make valves and flow sensors work with new flow logic
This commit is contained in:
parent
e8c249f8d2
commit
7f94ed4c1a
12
devices.lua
12
devices.lua
|
@ -107,15 +107,15 @@ for s in ipairs(states) do
|
|||
drop = "pipeworks:valve_off_empty",
|
||||
mesecons = {effector = {
|
||||
action_on = function (pos, node)
|
||||
minetest.add_node(pos,{name="pipeworks:valve_on_empty", param2 = node.param2})
|
||||
minetest.swap_node(pos,{name="pipeworks:valve_on_empty", param2 = node.param2})
|
||||
end,
|
||||
action_off = function (pos, node)
|
||||
minetest.add_node(pos,{name="pipeworks:valve_off_empty", param2 = node.param2})
|
||||
minetest.swap_node(pos,{name="pipeworks:valve_off_empty", param2 = node.param2})
|
||||
end
|
||||
}},
|
||||
on_punch = function(pos, node, puncher)
|
||||
local fdir = minetest.get_node(pos).param2
|
||||
minetest.add_node(pos, { name = "pipeworks:valve_"..states[3-s].."_empty", param2 = fdir })
|
||||
minetest.swap_node(pos, { name = "pipeworks:valve_"..states[3-s].."_empty", param2 = fdir })
|
||||
end
|
||||
})
|
||||
end
|
||||
|
@ -148,15 +148,15 @@ minetest.register_node("pipeworks:valve_on_loaded", {
|
|||
drop = "pipeworks:valve_off_empty",
|
||||
mesecons = {effector = {
|
||||
action_on = function (pos, node)
|
||||
minetest.add_node(pos,{name="pipeworks:valve_on_empty", param2 = node.param2})
|
||||
minetest.swap_node(pos,{name="pipeworks:valve_on_empty", param2 = node.param2})
|
||||
end,
|
||||
action_off = function (pos, node)
|
||||
minetest.add_node(pos,{name="pipeworks:valve_off_empty", param2 = node.param2})
|
||||
minetest.swap_node(pos,{name="pipeworks:valve_off_empty", param2 = node.param2})
|
||||
end
|
||||
}},
|
||||
on_punch = function(pos, node, puncher)
|
||||
local fdir = minetest.get_node(pos).param2
|
||||
minetest.add_node(pos, { name = "pipeworks:valve_off_empty", param2 = fdir })
|
||||
minetest.swap_node(pos, { name = "pipeworks:valve_off_empty", param2 = fdir })
|
||||
end
|
||||
})
|
||||
|
||||
|
|
|
@ -178,13 +178,108 @@ minetest.register_abm({
|
|||
end
|
||||
})
|
||||
|
||||
--[[
|
||||
other nodes that need processed separately:
|
||||
table.insert(pipeworks.pipe_nodenames,"pipeworks:valve_on_empty")
|
||||
table.insert(pipeworks.pipe_nodenames,"pipeworks:valve_off_empty")
|
||||
table.insert(pipeworks.pipe_nodenames,"pipeworks:entry_panel_empty")
|
||||
table.insert(pipeworks.pipe_nodenames,"pipeworks:flow_sensor_empty")
|
||||
table.insert(pipeworks.pipe_nodenames,"pipeworks:valve_on_loaded")
|
||||
table.insert(pipeworks.pipe_nodenames,"pipeworks:entry_panel_loaded")
|
||||
table.insert(pipeworks.pipe_nodenames,"pipeworks:flow_sensor_loaded")
|
||||
]]--
|
||||
pipeworks.device_nodenames = {}
|
||||
|
||||
table.insert(pipeworks.device_nodenames,"pipeworks:valve_on_empty")
|
||||
table.insert(pipeworks.device_nodenames,"pipeworks:valve_off_empty")
|
||||
table.insert(pipeworks.device_nodenames,"pipeworks:valve_on_loaded")
|
||||
table.insert(pipeworks.device_nodenames,"pipeworks:flow_sensor_empty")
|
||||
table.insert(pipeworks.device_nodenames,"pipeworks:flow_sensor_loaded")
|
||||
|
||||
print(dump(pipeworks.device_nodenames))
|
||||
|
||||
minetest.register_abm({
|
||||
nodenames = pipeworks.device_nodenames,
|
||||
interval = 2,
|
||||
chance = 1,
|
||||
action = function(pos, node, active_object_count, active_object_count_wider)
|
||||
local fdir = node.param2
|
||||
local fdir_mod4 = fdir % 4
|
||||
local fdir_mod4_p2 = (fdir+2) % 4
|
||||
|
||||
local fdir_to_pos = {
|
||||
{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 },
|
||||
{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]
|
||||
|
||||
local adjacent_node1 = minetest.get_node(pos_adjacent1)
|
||||
local adjacent_node2 = minetest.get_node(pos_adjacent2)
|
||||
|
||||
if not adjacent_node1 or not adjacent_node2 then return end
|
||||
print("---------------")
|
||||
print(dump(pos_adjacent1))
|
||||
print(dump(adjacent_node1.name))
|
||||
print(dump(pos_adjacent2))
|
||||
print(dump(adjacent_node2.name))
|
||||
|
||||
local my_level = (minetest.get_meta(pos):get_float("liquid_level")) or 0
|
||||
local adjacent_node_level1 = (minetest.get_meta(pos_adjacent1):get_float("liquid_level")) or 0
|
||||
local adjacent_node_level2 = (minetest.get_meta(pos_adjacent2):get_float("liquid_level")) or 0
|
||||
|
||||
if not string.match(node.name, "pipeworks:valve_off") then
|
||||
|
||||
local num_connections = 1
|
||||
local set1
|
||||
local set2
|
||||
local total_level = my_level
|
||||
|
||||
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
|
||||
num_connections = num_connections + 1
|
||||
total_level = total_level + adjacent_node_level1
|
||||
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
|
||||
num_connections = num_connections + 1
|
||||
total_level = total_level + adjacent_node_level2
|
||||
set2 = true
|
||||
end
|
||||
|
||||
local average_level = total_level / num_connections
|
||||
|
||||
minetest.get_meta(pos):set_float("liquid_level", average_level)
|
||||
|
||||
if set1 then
|
||||
minetest.get_meta(pos_adjacent1):set_float("liquid_level", average_level)
|
||||
end
|
||||
|
||||
if set2 then
|
||||
minetest.get_meta(pos_adjacent2):set_float("liquid_level", average_level)
|
||||
end
|
||||
|
||||
if node.name == "pipeworks:flow_sensor_empty" or
|
||||
node.name == "pipeworks:flow_sensor_loaded" then
|
||||
print("I'm a flow sensor!")
|
||||
|
||||
local sensor = string.match(node.name, "pipeworks:flow_sensor_")
|
||||
local newnode = nil
|
||||
if my_level > 1 then
|
||||
newnode = sensor.."loaded"
|
||||
else
|
||||
newnode = sensor.."empty"
|
||||
end
|
||||
if newnode then
|
||||
minetest.swap_node(pos, {name = newnode, param2 = node.param2})
|
||||
end
|
||||
end
|
||||
else
|
||||
print("I'm a valve and I'm off!")
|
||||
end
|
||||
|
||||
print("my_level="..dump(my_level))
|
||||
print("adjacent_node_level1="..dump(adjacent_node_level1))
|
||||
print("adjacent_node_level2="..dump(adjacent_node_level2))
|
||||
|
||||
end
|
||||
})
|
||||
|
||||
-- table.insert(pipeworks.device_nodenames,"pipeworks:entry_panel")
|
||||
|
|
16
init.lua
16
init.lua
|
@ -84,6 +84,18 @@ function pipeworks.replace_name(tbl,tr,name)
|
|||
return ntbl
|
||||
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
|
||||
|
||||
|
@ -93,7 +105,10 @@ dofile(pipeworks.modpath.."/autoplace_pipes.lua")
|
|||
dofile(pipeworks.modpath.."/autoplace_tubes.lua")
|
||||
dofile(pipeworks.modpath.."/luaentity.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.."/crafts.lua")
|
||||
dofile(pipeworks.modpath.."/tube_registration.lua")
|
||||
dofile(pipeworks.modpath.."/routing_tubes.lua")
|
||||
|
@ -105,7 +120,6 @@ dofile(pipeworks.modpath.."/filter-injector.lua")
|
|||
dofile(pipeworks.modpath.."/trashcan.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_pipe_devices then dofile(pipeworks.modpath.."/devices.lua") end
|
||||
if pipeworks.enable_redefines then dofile(pipeworks.modpath.."/compat.lua") end
|
||||
|
|
Loading…
Reference in New Issue
Block a user