From 3aed046eb7c1a8fa2cad891aacd4b2c00d1f9fb7 Mon Sep 17 00:00:00 2001 From: Joachim Stolberg Date: Wed, 17 Feb 2021 20:15:22 +0100 Subject: [PATCH] Fix laser shutoff bug --- basis/laser_lib.lua | 11 +++++++---- power/laser.lua | 15 +++++++++++++-- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/basis/laser_lib.lua b/basis/laser_lib.lua index ea508d3..802b3c3 100644 --- a/basis/laser_lib.lua +++ b/basis/laser_lib.lua @@ -34,9 +34,12 @@ local function get_positions(pos, mem, dir) mem.peer_node_pos = pos3 local dist = vector.distance(pos1, pos3) if dist > GAP_MIN and dist <= GAP_MAX then - return pos1, pos3 + return true, pos1, pos3 -- new values + else + return false -- invalid values end end + return true -- no new values end -- return both both laser entities the pos and length @@ -119,15 +122,15 @@ function techage.renew_laser(pos, force) end mem.param2 = mem.param2 or minetest.get_node(pos).param2 local dir = minetest.facedir_to_dir(mem.param2) - local pos1, pos2 = get_positions(pos, mem, dir) + local res, pos1, pos2 = get_positions(pos, mem, dir) if pos1 then local size, pos3, pos4 = get_laser_length_and_pos(pos1, pos2, dir) if size then add_laser(pos, pos3, pos4, size, mem.param2) - return pos1, pos2 + return res, pos1, pos2 end end - + return res end -- techage.del_laser(pos) diff --git a/power/laser.lua b/power/laser.lua index 238bd96..7a0b359 100644 --- a/power/laser.lua +++ b/power/laser.lua @@ -39,7 +39,7 @@ minetest.register_node("techage:ta4_laser_emitter", { Cable:prepare_pairing(pos, tube_dir, "") Cable:after_place_node(pos, {tube_dir}) - local pos1, pos2 = techage.renew_laser(pos, true) + local res, pos1, pos2 = techage.renew_laser(pos, true) if pos1 then local node = techage.get_node_lvm(pos2) if node.name == "techage:ta4_laser_receiver" then @@ -57,13 +57,24 @@ minetest.register_node("techage:ta4_laser_emitter", { end, on_timer = function(pos, elapsed) - local pos1, pos2 = techage.renew_laser(pos) + local res, pos1, pos2 = techage.renew_laser(pos) if pos1 then local node = techage.get_node_lvm(pos2) if node.name == "techage:ta4_laser_receiver" then Cable:pairing(pos2, "laser") Cable:pairing(pos, "laser") + else + local metadata = M(pos):to_table() + Cable:stop_pairing(pos, metadata, "") + local tube_dir = tonumber(metadata.fields.tube_dir or 0) + Cable:after_dig_node(pos, {tube_dir}) end + elseif not res then + techage.del_laser(pos) + local metadata = M(pos):to_table() + Cable:stop_pairing(pos, metadata, "") + local tube_dir = tonumber(metadata.fields.tube_dir or 0) + Cable:after_dig_node(pos, {tube_dir}) end return true end,