Advertisement
liq3

Mine 2.0

Dec 3rd, 2016
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.74 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. local os = require("os")
  6.  
  7. function moveGeneric(move, detect, swing)
  8.     if detect() then swing() end
  9.     if not move() then computer.shutdown() end
  10. end
  11.  
  12. function moveForward()
  13.     moveGeneric(robot.forward, robot.detect, robot.swing)
  14. end
  15.  
  16. function moveUp()
  17.     moveGeneric(robot.up, robot.detectUp, robot.swingUp)
  18. end
  19.  
  20. function moveDown()
  21.     moveGeneric(robot.down, robot.detectDown, robot.swingDown)
  22. end
  23.  
  24. function shouldMine(side)
  25.     local info = component.geolyzer.analyze(side)
  26.     return info and info.name and (info.name:match(".*[oO]re.*") or info.name:match("blockMisc") or info.name:match("resource"))
  27. end
  28.  
  29. function faceDirection(side)
  30.     while side ~= component.navigation.getFacing() do
  31.         robot.turnLeft()
  32.     end
  33. end
  34.  
  35. function scanDig()
  36.     if robot.detectUp() and shouldMine(sides.top) then
  37.         moveUp()
  38.         scanDig()
  39.         moveDown()
  40.     end
  41.     if robot.detectDown() and shouldMine(sides.bottom) then
  42.         moveDown()
  43.         scanDig()
  44.         moveUp()
  45.     end
  46.     for i=2,5,1 do
  47.         if shouldMine(i) then
  48.             if i == sides.right then robot.turnRight()
  49.             elseif i == sides.left then robot.turnLeft()
  50.             elseif i == sides.back then robot.turnAround()
  51.             end
  52.            
  53.             moveForward()
  54.             scanDig()
  55.             robot.back()
  56.            
  57.             if i == sides.right then robot.turnLeft()
  58.             elseif i == sides.left then robot.turnRight()
  59.             elseif i == sides.back then robot.turnAround()
  60.             end
  61.         end
  62.     end
  63. end
  64.  
  65. function placeCobble()
  66.     if not robot.detectDown() then
  67.         robot.select(2)
  68.         robot.placeDown()
  69.     end
  70. end
  71.  
  72. function mineTunnel()
  73.     local distance = 120
  74.     for ix=1,distance/2,1 do
  75.         scanDig()
  76.         placeCobble()
  77.         moveUp()
  78.         scanDig()
  79.         moveForward()
  80.         scanDig()
  81.         moveDown()
  82.         scanDig()
  83.         if ix % 4 == 0 then
  84.             robot.select(1)
  85.             if not robot.placeUp(sides.right) then
  86.                 robot.placeUp(sides.left)
  87.             end
  88.         end
  89.         placeCobble()
  90.         moveForward()  
  91.     end
  92.    
  93.     robot.turnAround()
  94.     for i=1,distance,1 do
  95.         moveForward()
  96.     end
  97. end
  98.  
  99. local branchDistance = 36
  100.  
  101. function mineBranch()
  102.     print("Mining Branch")
  103.     print(branchDistance)
  104.     faceDirection(sides.south)
  105.     for i=1,branchDistance,1 do
  106.         moveForward()
  107.     end
  108.     faceDirection(sides.east)
  109.     mineTunnel()
  110.     faceDirection(sides.north)
  111.     for i=1,branchDistance,1 do
  112.         moveForward()
  113.     end
  114.     if component.geolyzer.analyze(sides.front).name:match("Chest") then
  115.         for i=3,robot.inventorySize(),1 do
  116.             robot.select(i)
  117.             robot.drop()
  118.         end
  119.     else
  120.         print("No chest to drop items.")
  121.     end
  122. end
  123.  
  124. mineBranch()
  125.  
  126. while (computer.energy() + 500 < computer.maxEnergy()) do
  127.     os.sleep(500)
  128. end
  129.  
  130. branchDistance = 42
  131. mineBranch()
  132.    
  133.  
  134. local x = 657
  135. local y = 11
  136. local z = -992
  137.  
  138. computer.shutdown()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement