Detector check function

master
Wuzzy 2021-12-21 23:18:11 +01:00
parent 630739eb80
commit 4b6f03f258
1 changed files with 16 additions and 3 deletions

View File

@ -44,10 +44,9 @@ function lzr_laser.add_laser(pos, dir)
-- Activate node
minetest.set_node(pos, {name="lzr_laser:detector_on", param2 = node.param2})
pos = vector.add(pos, dir)
return pos, dir
else
return false
end
-- Laser ends here
return false
-- Anything else: fail
else
return false
@ -123,6 +122,20 @@ function lzr_laser.emit_lasers_in_area(pos1, pos2)
end
end
-- Return true if all detectors in area are on (including if no detector)
function lzr_laser.check_detectors_in_area(pos1, pos2)
local detectors = minetest.find_nodes_in_area(pos1, pos2, {"group:detector"})
for d=1, #detectors do
local dpos = detectors[d]
local detector = minetest.get_node(dpos)
local is_active = minetest.get_item_group(detector.name, "detector") == 2
if not is_active then
return false
end
end
return true
end
-- Completely recalculate all lasers
function lzr_laser.full_laser_update(pos1, pos2)
lzr_laser.clear_lasers_in_area(pos1, pos2)