mirror of
https://github.com/mt-mods/pipeworks.git
synced 2024-12-25 02:10:23 +01:00
abms.lua: refactor and generalise run_pump_intake() to allow passing custom intake functions
This commit is contained in:
parent
aee23d7642
commit
3486ee319e
@ -24,13 +24,13 @@ register.balance = register_abm_balance
|
|||||||
|
|
||||||
-- register a node for the pump ABM.
|
-- register a node for the pump ABM.
|
||||||
-- maxpressure is the maximum pressure that this pump can drive.
|
-- maxpressure is the maximum pressure that this pump can drive.
|
||||||
local register_abm_input = function(nodename, maxpressure)
|
local register_abm_input = function(nodename, maxpressure, intakefn)
|
||||||
minetest.register_abm({
|
minetest.register_abm({
|
||||||
nodenames = { nodename },
|
nodenames = { nodename },
|
||||||
interval = 1,
|
interval = 1,
|
||||||
chance = 1,
|
chance = 1,
|
||||||
action = function(pos, node, active_object_count, active_object_count_wider)
|
action = function(pos, node, active_object_count, active_object_count_wider)
|
||||||
pipeworks.flowlogic.run_pump_intake(pos, node, maxpressure)
|
pipeworks.flowlogic.run_input(pos, node, maxpressure, intakefn)
|
||||||
end
|
end
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
@ -31,12 +31,7 @@ end
|
|||||||
-- new version of liquid check
|
-- new version of liquid check
|
||||||
-- accepts a limit parameter to only delete water blocks that the receptacle can accept,
|
-- accepts a limit parameter to only delete water blocks that the receptacle can accept,
|
||||||
-- and returns it so that the receptacle can update it's pressure values.
|
-- and returns it so that the receptacle can update it's pressure values.
|
||||||
-- this should ensure that water blocks aren't vanished from existance.
|
|
||||||
-- will take care of zero or negative-valued limits.
|
|
||||||
local check_for_liquids_v2 = function(pos, limit)
|
local check_for_liquids_v2 = function(pos, limit)
|
||||||
if not limit then
|
|
||||||
limit = 6
|
|
||||||
end
|
|
||||||
local coords = make_coords_offsets(pos, false)
|
local coords = make_coords_offsets(pos, false)
|
||||||
local total = 0
|
local total = 0
|
||||||
for index, tpos in ipairs(coords) do
|
for index, tpos in ipairs(coords) do
|
||||||
@ -89,15 +84,20 @@ end
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
flowlogic.run_pump_intake = function(pos, node, maxpressure)
|
flowlogic.run_input = function(pos, node, maxpressure, intakefn)
|
||||||
-- try to absorb nearby water nodes, but only up to limit.
|
-- intakefn allows a given input node to define it's own intake logic.
|
||||||
-- NB: check_for_liquids_v2 handles zero or negative from the following subtraction
|
-- this function will calculate the maximum amount of water that can be taken in;
|
||||||
|
-- the intakefn will be given this and is expected to return the actual absorption amount.
|
||||||
|
|
||||||
local meta = minetest.get_meta(pos)
|
local meta = minetest.get_meta(pos)
|
||||||
local currentpressure = meta:get_float(label_pressure)
|
local currentpressure = meta:get_float(label_pressure)
|
||||||
|
|
||||||
local intake_limit = maxpressure - currentpressure
|
local intake_limit = maxpressure - currentpressure
|
||||||
local actual_intake = check_for_liquids_v2(pos, intake_limit)
|
if intake_limit <= 0 then return end
|
||||||
|
|
||||||
|
local actual_intake = intakefn(pos, intake_limit)
|
||||||
|
if actual_intake <= 0 then return end
|
||||||
|
if actual_intake >= intake_limit then actual_intake = intake_limit end
|
||||||
|
|
||||||
local newpressure = actual_intake + currentpressure
|
local newpressure = actual_intake + currentpressure
|
||||||
-- debuglog("oldpressure "..currentpressure.." intake_limit "..intake_limit.." actual_intake "..actual_intake.." newpressure "..newpressure)
|
-- debuglog("oldpressure "..currentpressure.." intake_limit "..intake_limit.." actual_intake "..actual_intake.." newpressure "..newpressure)
|
||||||
meta:set_float(label_pressure, newpressure)
|
meta:set_float(label_pressure, newpressure)
|
||||||
|
@ -51,7 +51,6 @@ local checkbase = function(nodename)
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- Register a node as a simple intake.
|
-- Register a node as a simple intake.
|
||||||
-- See new_flow_logic for the details of this.
|
|
||||||
-- Expects node to be registered as a flowable (is present in flowables.list.all),
|
-- Expects node to be registered as a flowable (is present in flowables.list.all),
|
||||||
-- so that water can move out of it.
|
-- so that water can move out of it.
|
||||||
-- maxpressure is the maximum pipeline pressure that this node can drive.
|
-- maxpressure is the maximum pipeline pressure that this node can drive.
|
||||||
@ -61,6 +60,6 @@ register.intake_simple = function(nodename, maxpressure)
|
|||||||
pipeworks.flowables.inputs.list[nodename] = { maxpressure=maxpressure }
|
pipeworks.flowables.inputs.list[nodename] = { maxpressure=maxpressure }
|
||||||
table.insert(pipeworks.flowables.inputs.nodenames, nodename)
|
table.insert(pipeworks.flowables.inputs.nodenames, nodename)
|
||||||
if pipeworks.enable_new_flow_logic then
|
if pipeworks.enable_new_flow_logic then
|
||||||
abmregister.input(nodename, maxpressure)
|
abmregister.input(nodename, maxpressure, pipeworks.flowlogic.check_for_liquids_v2)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user