From 3cc2a0177972bc472268f3d4ce4b9143145f581c Mon Sep 17 00:00:00 2001 From: Joachim Stolberg Date: Wed, 17 May 2023 19:07:23 +0200 Subject: [PATCH] Fix bug with pump limit via commands --- liquids/pump.lua | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/liquids/pump.lua b/liquids/pump.lua index d9a842a..7404bff 100644 --- a/liquids/pump.lua +++ b/liquids/pump.lua @@ -57,6 +57,17 @@ local State4 = techage.NodeStates:new({ standby_ticks = STANDBY_TICKS, }) +local function handle_pump_limit(pos, nvm) + local val = M(pos):get_int("limit") + if val and val > 0 then + nvm.limit = val + nvm.num_items = 0 + else + nvm.limit = nil + nvm.num_items = nil + end +end + -- Function returns the number of pumped units local function pump(pos, mem, nvm, state, outdir, units) local taken, name = liquid.take(pos, Pipe, Flip[outdir], nil, units, mem.dbg_cycles > 0) @@ -152,14 +163,7 @@ local function on_rightclick(pos, node, clicker) elseif node.name == "techage:t4_pump" then local mem = techage.get_mem(pos) mem.dbg_cycles = 5 - local val = M(pos):get_int("limit") - if val and val > 0 then - nvm.limit = val - nvm.num_items = 0 - else - nvm.limit = nil - nvm.num_items = nil - end + handle_pump_limit(pos, nvm) State4:start(pos, nvm) elseif node.name == "techage:t4_pump_on" then State4:stop(pos, nvm) @@ -340,6 +344,10 @@ techage.register_node({"techage:t4_pump", "techage:t4_pump_on"}, { local nvm = techage.get_nvm(pos) return nvm.flowrate or 0 else + if topic == "on" then + local nvm = techage.get_nvm(pos) + handle_pump_limit(pos, nvm) + end return State4:on_receive_message(pos, topic, payload) end end, @@ -358,9 +366,9 @@ techage.register_node({"techage:t4_pump", "techage:t4_pump_on"}, { end return 0 else - local nvm = techage.get_nvm(pos) - if nvm.limit then - nvm.num_items = 0 + if topic == 1 then + local nvm = techage.get_nvm(pos) + handle_pump_limit(pos, nvm) end return State4:on_beduino_receive_cmnd(pos, topic, payload) end