Advertisement
liq3

Mine

Dec 2nd, 2016
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.59 KB | None | 0 0
  1. local robot = require("robot")
  2. local computer = require("computer")
  3. local component = require("component")
  4. local sides = require("sides")
  5.  
  6. function moveForward()
  7.     if robot.detect() then robot.swing() end
  8.     if not robot.forward() then computer.shutdown() end
  9. end
  10.  
  11. function moveUp()
  12.     if robot.detectUp() then robot.swingUp() end
  13.     if not robot.up() then computer.shotdown() end
  14. end
  15.  
  16. function moveDown()
  17.     if robot.detectDown() then robot.swingDown() end
  18.     if not robot.down() then computer.shutdown() end
  19. end
  20.  
  21. function shouldMine(side)
  22.     local info = component.geolyzer.analyze(side)
  23.     return info and info.name and (info.name:match(".*[oO]re.*") or info.name:match(".*Obsidian.*"))
  24. end
  25.  
  26. function scanDig()
  27.     if robot.detectUp() and shouldMine(sides.top) then
  28.         moveUp()
  29.         scanDig()
  30.         moveDown()
  31.     end
  32.     if robot.detectDown() and shouldMine(sides.bottom) then
  33.         moveDown()
  34.         scanDig()
  35.         moveUp()
  36.     end
  37.     for i=2,5,1 do
  38.         if robot.detect() and shouldMine(i) then
  39.             if i == sides.right then robot.turnRight()
  40.             elseif i == sides.left then robot.turnLeft()
  41.             elseif i == sides.back then robot.turnAround()
  42.             end
  43.            
  44.             moveForward()
  45.             scanDig()
  46.             robot.back()
  47.            
  48.             if i == sides.right then robot.turnLeft()
  49.             elseif i == sides.left then robot.turnRight()
  50.             elseif i == sides.back then robot.turnAround()
  51.             end
  52.         end
  53.     end
  54. end
  55.  
  56. local distance = 10
  57. for ix=1,distance/2,1 do
  58.     scanDig()
  59.     moveUp()
  60.     scanDig()
  61.     moveForward()
  62.     scanDig()
  63.     moveDown()
  64.     scanDig()
  65.     moveForward()  
  66. end
  67.  
  68. robot.turnAround()
  69. for i=1,distance,1 do
  70.     moveForward()
  71. end
  72. computer.shutdown()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement