1
0
mirror of https://github.com/mt-mods/pipeworks.git synced 2024-12-27 11:20:26 +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,19 +111,23 @@ 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)
local taken = 0 return function(pos, node, currentpressure)
local below = {x=pos.x, y=pos.y-1, z=pos.z} local taken = 0
local name = minetest.get_node(below).name for _, offset in pairs(neighbours) do
if (name == "air") or (name == "default:water_flowing") then local npos = vector.add(pos, offset)
minetest.set_node(below, {name="default:water_source"}) local name = minetest.get_node(npos).name
taken = taken + 1 if (name == "air") or (name == "default:water_flowing") then
minetest.swap_node(npos, {name="default:water_source"})
taken = taken + 1
end
end
return taken
end end
return taken
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