diff --git a/basic_machines/concentrator.lua b/basic_machines/concentrator.lua index 2d5217c..eed6f43 100644 --- a/basic_machines/concentrator.lua +++ b/basic_machines/concentrator.lua @@ -62,7 +62,7 @@ local names = networks.register_junction("techage:concentrator", 2/8, Boxes, Tub techage.register_node(names, { on_push_item = function(pos, in_dir, stack) local push_dir = M(pos):get_int("push_dir") - return techage.push_items(pos, push_dir, stack) + return techage.safe_push_items(pos, push_dir, stack) end, is_pusher = true, -- is a pulling/pushing node }) @@ -101,7 +101,7 @@ names = networks.register_junction("techage:ta4_concentrator", 2/8, Boxes, Tube, techage.register_node(names, { on_push_item = function(pos, in_dir, stack) local push_dir = M(pos):get_int("push_dir") - return techage.push_items(pos, push_dir, stack) + return techage.safe_push_items(pos, push_dir, stack) end, is_pusher = true, -- is a pulling/pushing node }) diff --git a/basis/command.lua b/basis/command.lua index 435818b..301cf3b 100644 --- a/basis/command.lua +++ b/basis/command.lua @@ -405,6 +405,31 @@ function techage.push_items(pos, out_dir, stack, idx) return false end +-- Check for recursion and too long distances +local start_pos +function techage.safe_push_items(pos, out_dir, stack, idx) + local mem = techage.get_mem(pos) + if not mem.pushing then + if not start_pos then + start_pos = pos + mem.pushing = true + local res = techage.push_items(pos, out_dir, stack, idx) + mem.pushing = nil + start_pos = nil + return res + else + local npos, in_dir, name = get_dest_node(pos, out_dir) + if vector.distance(start_pos, npos) < (Tube.max_tube_length or 100) then + mem.pushing = true + local res = techage.push_items(pos, out_dir, stack, idx) + mem.pushing = nil + return res + end + end + end + return false +end + function techage.unpull_items(pos, out_dir, stack) local npos, in_dir, name = get_dest_node(pos, out_dir) if npos and NodeDef[name] and NodeDef[name].on_unpull_item then diff --git a/logic/node_detector.lua b/logic/node_detector.lua index deb1d26..eed6d7f 100644 --- a/logic/node_detector.lua +++ b/logic/node_detector.lua @@ -60,20 +60,21 @@ local function any_node_changed(pos) nvm.num = #minetest.find_nodes_in_area(nvm.pos1, nvm.pos2, {"air"}) return false end - local num = #minetest.find_nodes_in_area(nvm.pos1, nvm.pos2, {"air"}) + local num1 = #minetest.find_nodes_in_area(nvm.pos1, nvm.pos2, {"air"}) + local num2 = #minetest.find_nodes_in_area(nvm.pos1, nvm.pos2, {"ignore"}) - if nvm.num ~= num then - if nvm.mode == 1 and num < nvm.num then - nvm.num = num + if num2 == 0 and nvm.num ~= num1 then + if nvm.mode == 1 and num1 < nvm.num then + nvm.num = num1 return true - elseif nvm.mode == 2 and num > nvm.num then - nvm.num = num + elseif nvm.mode == 2 and num1 > nvm.num then + nvm.num = num1 return true elseif nvm.mode == 3 then - nvm.num = num + nvm.num = num1 return true end - nvm.num = num + nvm.num = num1 end return false end