Advertisement
tomte55

OC Miner 2.0

Dec 6th, 2016
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.15 KB | None | 0 0
  1. local debug = false
  2.  
  3. local tArgs ={...}
  4. local debugArg =tArgs[1]
  5.  
  6. if debugArg == "debug" then
  7.     debug = true
  8. end
  9.  
  10. local component = require("component")
  11. local robot     = require("robot")
  12. local term      = require("term")
  13. local computer  = require("computer")
  14.  
  15.  
  16. local shafts = 0
  17. local shaftsQ = 0
  18. local lenght = 0
  19. local lenghtQ = 0
  20. local shaftSpacing = 0
  21. local shaftSpacingQ = 0
  22. local startEnter = 0
  23.  
  24. function start()
  25.     print("Put Wooden Crate in slot 1")
  26.     print("Put Ender Chest in slot 2")
  27.     print("Torches in slot 3")
  28.     print("When done press ENTER")
  29.     startEnter = tonumber(term.read())
  30.     term.clear()
  31.     print("Lenght of each shaft?")
  32.     lenghtQ = tonumber(term.read())
  33.     if lenghtQ >= 51 then
  34.         print("Shafts can't be longer than 50")
  35.         lenghtQ = tonumber(term.read())
  36.     end
  37.     term.clear()
  38.     print("Number of shafts?")
  39.     print("Only put 2,4,6,8,10 etc")
  40.     shaftsQ = tonumber(term.read())
  41.     term.clear()
  42.     print("Spacing between shafts?")
  43.     print("0 Will make a room")
  44.     shaftSpacingQ = tonumber(term.read())
  45.     shaftSpacingQ = shaftSpacingQ + 1
  46.     term.clear()
  47.     mine()
  48. end
  49.  
  50. function invDrop()
  51.     if debug == true then
  52.         print("invDrop()")
  53.     end
  54.     robot.turnAround()
  55.     robot.select(2)
  56.     robot.place()
  57.     for i=4,16 do
  58.         robot.select(i)
  59.         robot.drop()
  60.     end
  61.     robot.select(2)
  62.     robot.swing()
  63.     robot.turnAround()
  64.     newShaft()
  65. end
  66.  
  67. function recharge()
  68.     if debug == true then
  69.         print("recharge()")
  70.     end
  71.     if computer.energy() <= 17750 then
  72.         if debug == true then
  73.             print("recharging...")
  74.         end
  75.         robot.turnAround()
  76.         robot.select(1)
  77.         robot.place()
  78.         -- Check advanced inventory API to get battery and charger and put it here <<<------
  79.  
  80.         robot.select(4)
  81.         robot.back()
  82.         robot.place()
  83.         robot.select(5)
  84.         robot.back()
  85.         robot.place()
  86.         while computer.energy ~= 30000 do
  87.             os.sleep(1)
  88.         end
  89.         if computer.energy() == 30000 then
  90.             robot.select(5)
  91.             robot.swing()
  92.             robot.forward()
  93.             robot.sleect(4)
  94.             robot.swing()
  95.             robot.forward()
  96.         end
  97.         robot.select(1)
  98.         robot.swing()
  99.     end
  100.     invDrop()
  101. end
  102.  
  103. function newShaft()
  104.     if debug == true then
  105.         print("newShaft()")
  106.     end
  107.     shaftSpacing = 0
  108.     if shafts%2==0 then
  109.         robot.turnRight()
  110.         while shaftSpacing ~= shaftSpacingQ do
  111.             robot.swing()
  112.             robot.forward()
  113.             shaftSpacing = shaftSpacing + 1
  114.             robot.swingUp()
  115.             robot.swingDown()
  116.             if shaftSpacing == shaftSpacingQ then
  117.                 robot.turnRight()
  118.                 mine()
  119.             end
  120.         end
  121.     else
  122.         robot.turnLeft()
  123.         while shaftSpacing ~= shaftSpacingQ do
  124.             robot.swing()
  125.             robot.forward()
  126.             shaftSpacing = shaftSpacing + 1
  127.             robot.swingUp()
  128.             robot.swingDown()
  129.             if shaftSpacing == shaftSpacingQ then
  130.                 robot.turnLeft()
  131.                 mine()
  132.             end
  133.         end
  134.     end
  135.     if shafts == shaftsQ then  
  136.         os.shutdown()
  137.     end
  138. end
  139.  
  140. function mine()
  141.     if debug == true then
  142.         print("mine()")
  143.     end
  144.     shafts = shafts + 1
  145.     while lenght ~= lenghtQ do
  146.         robot.swing()
  147.         robot.forward()
  148.         lenght = lenght + 1
  149.         robot.swingUp()
  150.         robot.swingDown()
  151.         if lenght%5==0 then
  152.             robot.select(3)
  153.             robot.placeDown()
  154.         end
  155.     end
  156.     if lenght == lenghtQ then
  157.         recharge()
  158.     end
  159. end
  160.  
  161.  
  162. -- (Main Stuff) --
  163. if robot.detectDown == true then
  164.     robot.up()
  165. end
  166. start()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement