summaryrefslogtreecommitdiff
path: root/new_flow_logic
diff options
context:
space:
mode:
authorthetaepsilon-gamedev <thetaepsilon-gamedev@noreply.users.github.com>2017-10-01 12:25:43 +0100
committerthetaepsilon-gamedev <thetaepsilon-gamedev@noreply.users.github.com>2017-10-01 12:25:43 +0100
commit463e7a206af8e2b98617b549e3bc6dc5eb181ffc (patch)
treee8ba162f9b079cf56970e6085eef4963dd8a1a76 /new_flow_logic
parent4cf9c90bb9a2a1f3c1fc938b543198b4ebd885c3 (diff)
downloadpipeworks-463e7a206af8e2b98617b549e3bc6dc5eb181ffc.tar
pipeworks-463e7a206af8e2b98617b549e3bc6dc5eb181ffc.tar.gz
pipeworks-463e7a206af8e2b98617b549e3bc6dc5eb181ffc.tar.bz2
pipeworks-463e7a206af8e2b98617b549e3bc6dc5eb181ffc.tar.xz
pipeworks-463e7a206af8e2b98617b549e3bc6dc5eb181ffc.zip
new flow logic: abms.lua: start splitting apart spigot code into generalised output ABM
Diffstat (limited to 'new_flow_logic')
-rw-r--r--new_flow_logic/abms.lua38
1 files changed, 38 insertions, 0 deletions
diff --git a/new_flow_logic/abms.lua b/new_flow_logic/abms.lua
index 48dcb0b..640493a 100644
--- a/new_flow_logic/abms.lua
+++ b/new_flow_logic/abms.lua
@@ -4,6 +4,7 @@
local flowlogic = {}
+flowlogic.helpers = {}
pipeworks.flowlogic = flowlogic
@@ -105,6 +106,43 @@ end
+-- flowlogic output helper for spigots
+-- tries to place a water block in the world beneath the spigot.
+-- threshold checking is assumed to be handled by the node registration;
+-- see register_local_pipes.lua for the pipeworks default spigot.
+flowlogic.helpers.output_spigot = function(pos, node, currentpressure)
+ local taken = 0
+ 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"})
+ taken = taken + 1
+ end
+ return taken
+end
+
+
+
+flowlogic.run_output = function(pos, node, threshold, outputfn)
+ -- callback for output devices.
+ -- takes care of checking a minimum pressure value and updating the node metadata.
+ -- the outputfn is provided the current pressure and returns the pressure "taken".
+ -- as an example, using this with the above spigot function,
+ -- the spigot function tries to output a water source if it will fit in the world.
+ local meta = minetest.get_meta(pos)
+ -- sometimes I wonder if meta:get_* returning default values would ever be problematic.
+ -- though here it doesn't matter, an uninit'd node returns 0, which is fine for a new, empty node.
+ local currentpressure = meta:get_float(label_pressure)
+ if currentpressure > threshold then
+ local takenpressure = outputfn(pos, node, currentpressure)
+ local newpressure = currentpressure - takenpressure
+ if newpressure < 0 then currentpressure = 0 end
+ meta:set_float(label_pressure, newpressure)
+ 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)