forked from mtcontrib/pipeworks
pressure logic: rewrite callbacks for horizontal rotation flowables to support singular and double-ended devices
This commit is contained in:
parent
9df0ec7edb
commit
b2b29a1737
12
devices.lua
12
devices.lua
@ -215,7 +215,7 @@ for s in ipairs(states) do
|
|||||||
-- only register flow logic for the "on" ABM.
|
-- only register flow logic for the "on" ABM.
|
||||||
-- this means that the off state automatically blocks flow by not participating in the balancing operation.
|
-- this means that the off state automatically blocks flow by not participating in the balancing operation.
|
||||||
if states[s] ~= "off" then
|
if states[s] ~= "off" then
|
||||||
new_flow_logic_register.directional_horizonal_rotate(nodename_valve_empty)
|
new_flow_logic_register.directional_horizonal_rotate(nodename_valve_empty, true)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -263,7 +263,7 @@ minetest.register_node(nodename_valve_loaded, {
|
|||||||
-- right-clicking a "loaded" valve (becoming an off valve) then turning it on again will yield a on-but-empty valve,
|
-- right-clicking a "loaded" valve (becoming an off valve) then turning it on again will yield a on-but-empty valve,
|
||||||
-- but the flow logic will still function.
|
-- but the flow logic will still function.
|
||||||
-- thus under new_flow_logic this serves as a kind of migration.
|
-- thus under new_flow_logic this serves as a kind of migration.
|
||||||
new_flow_logic_register.directional_horizonal_rotate(nodename_valve_loaded)
|
new_flow_logic_register.directional_horizonal_rotate(nodename_valve_loaded, true)
|
||||||
|
|
||||||
-- grating
|
-- grating
|
||||||
|
|
||||||
@ -438,8 +438,8 @@ minetest.register_node(nodename_panel_loaded, {
|
|||||||
on_rotate = pipeworks.fix_after_rotation
|
on_rotate = pipeworks.fix_after_rotation
|
||||||
})
|
})
|
||||||
-- TODO: AFAIK the two panels have no visual difference, so are redundant under new flow logic - alias?
|
-- TODO: AFAIK the two panels have no visual difference, so are redundant under new flow logic - alias?
|
||||||
new_flow_logic_register.directional_horizonal_rotate(nodename_panel_empty)
|
new_flow_logic_register.directional_horizonal_rotate(nodename_panel_empty, true)
|
||||||
new_flow_logic_register.directional_horizonal_rotate(nodename_panel_loaded)
|
new_flow_logic_register.directional_horizonal_rotate(nodename_panel_loaded, true)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -521,8 +521,8 @@ minetest.register_node(nodename_sensor_loaded, {
|
|||||||
mesecons = pipereceptor_on,
|
mesecons = pipereceptor_on,
|
||||||
on_rotate = pipeworks.fix_after_rotation
|
on_rotate = pipeworks.fix_after_rotation
|
||||||
})
|
})
|
||||||
new_flow_logic_register.directional_horizonal_rotate(nodename_sensor_empty)
|
new_flow_logic_register.directional_horizonal_rotate(nodename_sensor_empty, true)
|
||||||
new_flow_logic_register.directional_horizonal_rotate(nodename_sensor_loaded)
|
new_flow_logic_register.directional_horizonal_rotate(nodename_sensor_loaded, true)
|
||||||
-- activate flow sensor at roughly half the pressure pumps drive pipes
|
-- activate flow sensor at roughly half the pressure pumps drive pipes
|
||||||
local sensor_pressure_set = { { nodename_sensor_empty, 0.0 }, { nodename_sensor_loaded, 1.0 } }
|
local sensor_pressure_set = { { nodename_sensor_empty, 0.0 }, { nodename_sensor_loaded, 1.0 } }
|
||||||
new_flow_logic_register.transition_simple_set(sensor_pressure_set, { mesecons=pipeworks.mesecons_rules })
|
new_flow_logic_register.transition_simple_set(sensor_pressure_set, { mesecons=pipeworks.mesecons_rules })
|
||||||
|
@ -69,34 +69,39 @@ end
|
|||||||
-- register a node as a directional flowable whose accepting sides depends upon param2 rotation.
|
-- register a node as a directional flowable whose accepting sides depends upon param2 rotation.
|
||||||
-- used for entry panels, valves, flow sensors and spigots,
|
-- used for entry panels, valves, flow sensors and spigots,
|
||||||
-- whose facing axis is always upwards and can only rotate horizontally.
|
-- whose facing axis is always upwards and can only rotate horizontally.
|
||||||
local iseastwest = function(node)
|
register.directional_horizonal_rotate = function(nodename, doubleended)
|
||||||
local data = node.param2
|
local rotations = {
|
||||||
local rotation = data % 4
|
{x= 0,y= 0,z= 1},
|
||||||
-- rotation 0 and 2 is the same axis, as is 1 and 3.
|
{x= 1,y= 0,z= 0},
|
||||||
-- 0-3 starts at north and proceeds clockwise.
|
{x= 0,y= 0,z=-1},
|
||||||
local axis = rotation % 2
|
{x=-1,y= 0,z= 0},
|
||||||
--pipeworks.logger("iseastwest() rotation="..tostring(rotation).." axis="..tostring(axis))
|
}
|
||||||
return (axis == 1)
|
local getends = function(node)
|
||||||
end
|
--local dname = "horizontal rotate getends() "
|
||||||
register.directional_horizonal_rotate = function(nodename)
|
local param2 = node.param2
|
||||||
local north = {x= 0,y= 0,z= 1}
|
-- the sole end of the spigot points in the direction the rotation bits suggest
|
||||||
local south = {x= 0,y= 0,z=-1}
|
-- also note to self: lua arrays start at one...
|
||||||
local east = {x= 1,y= 0,z= 0}
|
local mainend = (param2 % 4) + 1
|
||||||
local west = {x=-1,y= 0,z= 0}
|
-- use modulus wrap-around to find other end for straight-run devices like the valve
|
||||||
local neighbourfn = function(node)
|
local otherend = ((param2 + 2) % 4) + 1
|
||||||
if iseastwest(node) then
|
local mainrot = rotations[mainend]
|
||||||
return { east, west }
|
--pipeworks.logger(dname.."mainrot: "..dump(mainrot))
|
||||||
|
local result
|
||||||
|
if doubleended then
|
||||||
|
result = { mainrot, rotations[otherend] }
|
||||||
else
|
else
|
||||||
return { north, south }
|
result = { mainrot }
|
||||||
end
|
end
|
||||||
|
--pipeworks.logger(dname.."result: "..dump(result))
|
||||||
|
return result
|
||||||
|
end
|
||||||
|
local neighbourfn = function(node)
|
||||||
|
return getends(node)
|
||||||
end
|
end
|
||||||
local directionfn = function(node, direction)
|
local directionfn = function(node, direction)
|
||||||
local result = false
|
local result = false
|
||||||
if iseastwest(node) then
|
for index, endvec in ipairs(getends(node)) do
|
||||||
--pipeworks.logger("horizontal rotate directionfn() eastwest=true")
|
if vector.equals(direction, endvec) then result = true end
|
||||||
result = vector.equals(direction, east) or vector.equals(direction, west)
|
|
||||||
else
|
|
||||||
result = vector.equals(direction, north) or vector.equals(direction, south)
|
|
||||||
end
|
end
|
||||||
return result
|
return result
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user