Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function DetectPeripheral(name)
- local sides = {"top" , "bottom" , "front" , "left" , "right" , "back"}
- for i = 1, 6 do
- if peripheral.isPresent(sides[i]) and peripheral.getType(sides[i]) == name then
- return sides[i]
- end
- end
- return nil
- end
- offset = 0
- m = peripheral.wrap(DetectPeripheral("mininglaser"))
- if not m.isMining() then
- while not passed do
- term.setCursorPos(1, 1)
- passed = false
- term.clear()
- print("Press X to mine")
- print("or press O to offset")
- print("current offset is "..offset)
- event, scancode = os.pullEvent("key")
- if tonumber(scancode) == 45 then
- print("Mining")
- m.startMining()
- passed = true
- elseif tonumber(scancode) == 24 then
- term.clear()
- term.setCursorPos(1, 1)
- print("Enter the offset")
- offset = tonumber(read())
- if offset == nil then
- print("Wrong input")
- offset = 0
- else
- m.setStartLayerOffset(offset)
- end
- end
- end
- end
- function interrupt()
- event, scancode = os.pullEvent("key")
- if tonumber(scancode) == 31 then
- m.stop()
- print("stopped")
- os.reboot()
- return 0
- end
- end
- function monitor()
- if m.isMining() then
- state, energy, layer, valuablesMined, valuablesInLayer = m.getMinerState()
- term.clear()
- term.setCursorPos(1, 1)
- print ("State: " .. state)
- print ("Energy: " .. energy)
- print ("Mined: " .. valuablesMined .. "/" .. valuablesInLayer .. " at layer " .. layer)
- print ("press S to stop and reboot")
- sleep(2)
- else
- os.reboot()
- end
- end
- while true do
- parallel.waitForAny(monitor, interrupt)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement