Advertisement
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.")
- -- 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
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement