Fix bug with pump limit via commands

This commit is contained in:
Joachim Stolberg 2023-05-17 19:07:23 +02:00
parent 11944f7aba
commit 3cc2a01779

View File

@ -57,6 +57,17 @@ local State4 = techage.NodeStates:new({
standby_ticks = STANDBY_TICKS, 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 -- Function returns the number of pumped units
local function pump(pos, mem, nvm, state, outdir, 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) 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 elseif node.name == "techage:t4_pump" then
local mem = techage.get_mem(pos) local mem = techage.get_mem(pos)
mem.dbg_cycles = 5 mem.dbg_cycles = 5
local val = M(pos):get_int("limit") handle_pump_limit(pos, nvm)
if val and val > 0 then
nvm.limit = val
nvm.num_items = 0
else
nvm.limit = nil
nvm.num_items = nil
end
State4:start(pos, nvm) State4:start(pos, nvm)
elseif node.name == "techage:t4_pump_on" then elseif node.name == "techage:t4_pump_on" then
State4:stop(pos, nvm) State4:stop(pos, nvm)
@ -340,6 +344,10 @@ techage.register_node({"techage:t4_pump", "techage:t4_pump_on"}, {
local nvm = techage.get_nvm(pos) local nvm = techage.get_nvm(pos)
return nvm.flowrate or 0 return nvm.flowrate or 0
else 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) return State4:on_receive_message(pos, topic, payload)
end end
end, end,
@ -358,9 +366,9 @@ techage.register_node({"techage:t4_pump", "techage:t4_pump_on"}, {
end end
return 0 return 0
else else
local nvm = techage.get_nvm(pos) if topic == 1 then
if nvm.limit then local nvm = techage.get_nvm(pos)
nvm.num_items = 0 handle_pump_limit(pos, nvm)
end end
return State4:on_beduino_receive_cmnd(pos, topic, payload) return State4:on_beduino_receive_cmnd(pos, topic, payload)
end end