local laser = peripheral.find("warpdriveLaser") local mininglasers = {} local sides = peripheral.getNames() local zeroBlockCount = 0 for _, side in pairs(sides) do if peripheral.getType(side) == "warpdriveMiningLaser" then table.insert(mininglasers, peripheral.wrap(side)) end end laser.beamFrequency(1420) if not laser then print("No warpdriveLaser detected") os.exit() end if #mininglasers == 0 then print("No warpdriveMiningLaser detected") os.exit() end print("Press the 'M' key to emit a laser scan and start the mining lasers with calculated layer offset.") -- Loop to wait for key events while true do -- Wait for a key event local event, key = os.pullEvent("key") -- Check if the "M" key was pressed (key code 50) if key == 50 then -- Get the laser's own position local _, laserY, _ = laser.getLocalPosition() -- Emit a laser scan in the Y- direction (0, -1, 0) laser.emitBeam(0, -1, 0) -- Get the scan result local _, _, targetY = laser.getScanResult() -- Calculate the layerOffset local mineTarget = laserY - targetY - 1 -- Print the target print("Target is: " .. mineTarget .. " blocks below") -- Configure the mining lasers to use the mineTarget as the layerOffset for _, mininglaser in pairs(mininglasers) do mininglaser.offset(mineTarget) mininglaser.enable(true) end repeat local areActive = false for _, mininglaser in pairs(mininglasers) do local _, isActive, _, _, _, total = mininglaser.state() if total == 0 then zeroBlockCount = zeroBlockCount + 1 else zeroBlockCount = 0 end if zeroBlockCount >= 3 then print("3 consecutive layers with 0 total blocks detected. Stopping mining.") for _, mininglaser in pairs(mininglasers) do shell.run("stop") end break end if isActive then areActive = true end end os.sleep(1) until not areActive or zeroBlockCount >= 3 -- Reset zeroBlockCount for the next mining session zeroBlockCount = 0 end end