1
0
mirror of https://github.com/mt-mods/pipeworks.git synced 2024-12-28 03:40:25 +01:00

new flow logic: abms.lua: generalise spigot output code to support arbitary neighbour lists

This commit is contained in:
thetaepsilon-gamedev 2017-10-01 21:04:07 +01:00
parent dc13ec619f
commit 667eeb7d09
2 changed files with 19 additions and 30 deletions

View File

@ -377,8 +377,9 @@ minetest.register_node(nodename_spigot_loaded, {
new_flow_logic_register.simple(nodename_spigot_empty) new_flow_logic_register.simple(nodename_spigot_empty)
new_flow_logic_register.simple(nodename_spigot_loaded) new_flow_logic_register.simple(nodename_spigot_loaded)
local spigot_min = 1 local spigot_min = 1
new_flow_logic_register.output(nodename_spigot_empty, spigot_min, pipeworks.flowlogic.helpers.output_spigot) local outputfn = pipeworks.flowlogic.helpers.make_neighbour_output({{x=0, y=-1, z=0}})
new_flow_logic_register.output(nodename_spigot_loaded, spigot_min, pipeworks.flowlogic.helpers.output_spigot) new_flow_logic_register.output(nodename_spigot_empty, spigot_min, outputfn)
new_flow_logic_register.output(nodename_spigot_loaded, spigot_min, outputfn)

View File

@ -111,20 +111,24 @@ end
-- flowlogic output helper for spigots -- flowlogic output helper implementation:
-- tries to place a water block in the world beneath the spigot. -- outputs water by trying to place water nodes nearby in the world.
-- threshold checking is assumed to be handled by the node registration; -- neighbours is a list of node offsets to try placing water in.
-- see register_local_pipes.lua for the pipeworks default spigot. -- this is a constructor function, returning another function which satisfies the output helper requirements.
flowlogic.helpers.output_spigot = function(pos, node, currentpressure) flowlogic.helpers.make_neighbour_output = function(neighbours)
return function(pos, node, currentpressure)
local taken = 0 local taken = 0
local below = {x=pos.x, y=pos.y-1, z=pos.z} for _, offset in pairs(neighbours) do
local name = minetest.get_node(below).name local npos = vector.add(pos, offset)
local name = minetest.get_node(npos).name
if (name == "air") or (name == "default:water_flowing") then if (name == "air") or (name == "default:water_flowing") then
minetest.set_node(below, {name="default:water_source"}) minetest.swap_node(npos, {name="default:water_source"})
taken = taken + 1 taken = taken + 1
end end
end
return taken return taken
end end
end
@ -145,19 +149,3 @@ flowlogic.run_output = function(pos, node, threshold, outputfn)
meta:set_float(label_pressure, newpressure) meta:set_float(label_pressure, newpressure)
end end
end end
flowlogic.run_spigot_output = function(pos, node)
-- try to output a water source node if there's enough pressure and space below.
local meta = minetest.get_meta(pos)
local currentpressure = meta:get_float(label_pressure)
if currentpressure > 1 then
local below = {x=pos.x, y=pos.y-1, z=pos.z}
local name = minetest.get_node(below).name
if (name == "air") or (name == "default:water_flowing") then
minetest.set_node(below, {name="default:water_source"})
meta:set_float(label_pressure, currentpressure - 1)
end
end
end