Not a member of Pastebin yet?
                        Sign Up,
                        it unlocks many cool features!                    
                - local laser = peripheral.find("warpdriveLaser")
 - local mininglasers = {}
 - local sides = peripheral.getNames()
 - 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.")
 - local zeroBlockCount = 0
 - -- 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
 - -- Monitor the total blocks and stop if necessary
 - while true do
 - local total = 0
 - for _, mininglaser in pairs(mininglasers) do
 - local _, _, _, _, _, laserTotal = mininglaser.state()
 - total = total + laserTotal
 - end
 - if total == 0 then
 - zeroBlockCount = zeroBlockCount + 1
 - if zeroBlockCount >= 3 then
 - print("3 consecutive layers with 0 total blocks detected. Stopping mining.")
 - shell.run("stop") -- Call the stop script to stop mining
 - break -- Exit the loop
 - end
 - else
 - zeroBlockCount = 0
 - end
 - os.sleep(1) -- Delay to give mining lasers time to process
 - end
 - end
 - end
 
Advertisement
 
                    Add Comment                
                
                        Please, Sign In to add comment