Advertisement
Guest User

mine

a guest
Jan 21st, 2015
243
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.08 KB | None | 0 0
  1. os.loadAPI("version")
  2. sleep(2)
  3. print("AutoMiner by theTANCO "..version.versionnum)
  4. sleep(4)
  5. print("")
  6.  
  7. mine = true
  8. blocknum = 0
  9. j = 0
  10. i = 0
  11.  
  12. function continue()
  13.   cont = true
  14.   while cont == true do
  15.     print('Type "s" to shutdown, "r" to see fuel or refuel, or "c" to continue mining.')
  16.     key = read()
  17.     print("")
  18.     if key == "s" or key == "S" then
  19.       cont = false
  20.       mine = false
  21.       shell.run("shutdown")
  22.     elseif key == "r" or key == "R" then
  23.       turtle.select(16)
  24.       turtle.refuel()
  25.       print("Fuel level: "..turtle.getFuelLevel())
  26.       print("To refuel, put a fuel item such as coal in item slot 16.")
  27.       sleep(1)
  28.       print("")
  29.     elseif key == "c" or key == "C" then
  30.       cont = false
  31.       check()
  32.     else
  33.       print("Please type a specified letter.")
  34.       sleep(1)
  35.       print("")
  36.     end
  37.   end
  38. end
  39.  
  40. function torches()
  41.   if turtle.getItemCount(1) == 0 then
  42.     print("Not enough torches to continue.")
  43.     print("Please place more torches in item slot 1 to continue.")
  44.     print("")
  45.     sleep(1)
  46.     continue()
  47.   end
  48. end
  49.  
  50. function fuel()
  51.   if turtle.getFuelLevel() == 0 then
  52.     print("Not enough fuel to continue.")
  53.     print("Please place fuel items such as coal in item slot 16 to refuel.")
  54.     print("")
  55.     sleep(1)
  56.     continue()
  57.   end
  58. end
  59.  
  60. function inventory()
  61.   f = false
  62.   while true do
  63.     for q=1,16 do
  64.       if turtle.getItemCount(q) > 0 then
  65.         inv = {}
  66.         inv[q-1] = true
  67.       else
  68.         inv[q-1] = false
  69.         f = true
  70.         break
  71.       end
  72.     end
  73.     if f == false then
  74.       turtle.turnLeft()
  75.       turtle.turnLeft()
  76.       return = j*9+i+1
  77.       returning = return
  78.       while returning > 0 do
  79.         turtle.forward()
  80.         returning = returning - 1
  81.       end
  82.       for r=3,15 do
  83.         turtle.select(r)
  84.         turtle.drop(64)
  85.       end
  86.       turtle.turnLeft()
  87.       turtle.turnLeft()
  88.       while returning < return do
  89.         turtle.forward()
  90.         returning = returning + 1
  91.       end
  92.     else
  93.       break
  94.     end
  95.   end
  96. end
  97.  
  98. function check()
  99.   torches()
  100.   fuel()
  101. end
  102.  
  103. continue()
  104.  
  105. while mine == true do
  106.   turtle.select(1)
  107.   inputCheck1 = true
  108.   while inputCheck1 == true do
  109.     print("Mine for how many blocks?")
  110.     print("Your input will be rounded down to a multiple of 9.")
  111.     h=math.floor(read()/9)
  112.     blocknum = h*9
  113.     inputCheck2 = true
  114.     while inputCheck2 == true do
  115.       print("")
  116.       textutils.slowPrint("Mining for "..blocknum.." blocks ("..h.." torches).")
  117.       textutils.slowPrint('Type "go" to start or "stop" to retype your input.')
  118.       confirmInput = read()
  119.       print("")
  120.       if confirmInput == "go" then
  121.         inputCheck1 = false
  122.         inputCheck2 = false
  123.       elseif confirmInput == "stop" then
  124.         inputCheck2 = false
  125.       end
  126.     end
  127.   end
  128.   textutils.slowPrint("Mining...")
  129.   sleep(3)
  130.   for j=1,h do
  131.     check()
  132.     for i=1,9 do
  133.       inventory()
  134.       while turtle.detect() == true do
  135.         turtle.dig()
  136.         sleep(0.5)
  137.       end
  138.       check()
  139.       turtle.forward()
  140.       turtle.digDown()
  141.       turtle.turnLeft()
  142.       turtle.select(2)
  143.       turtle.placeUp()
  144.       turtle.place()
  145.       check()
  146.       turtle.down()
  147.       turtle.place()
  148.       turtle.placeDown()
  149.       turtle.turnRight()
  150.       turtle.turnRight()
  151.       turtle.place()
  152.       check()
  153.       turtle.up()
  154.       turtle.place()
  155.       turtle.turnLeft()
  156.     end
  157.     turtle.select(2)
  158.     turtle.place()
  159.     check()
  160.     turtle.down()
  161.     turtle.place()
  162.     check()
  163.     turtle.up()
  164.     turtle.select(1)
  165.     turtle.placeDown()
  166.     print("Placed "..j.."/"..h.." torches.")
  167.   end
  168.   print("Finished mining.")
  169.   turtle.turnLeft()
  170.   turtle.turnLeft()
  171.   for k=1,blocknum do
  172.     check()
  173.     turtle.forward()
  174.   end
  175.   turtle.select(2)
  176.   turtle.digDown()
  177.   turtle.placeDown()
  178.   check()
  179.   turtle.forward()
  180.   for l=3,15 do
  181.     turtle.select(l)
  182.     turtle.drop(64)
  183.   end
  184.   turtle.turnLeft()
  185.   turtle.turnLeft()
  186.   turtle.select(1)
  187.   turtle.place()
  188.   print("")
  189.   sleep(1)
  190.   continue()
  191. end
  192. shell.run("shutdown")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement