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,
})
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