Advertisement
Mercyrocket

Turtle Os 1.5 Mining Program

Feb 2nd, 2014 (edited)
329
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.21 KB | None | 0 0
  1. --ComputerCraft mining turtle program (CraftOS 1.5)
  2. --For placing in a mining "corridor" and sending the turles off on strip mine branches.
  3.  
  4. --Functions
  5. function dig()
  6.  
  7.  while turtle.detect() == true do
  8.   turtle.dig()
  9.   sleep (0.7)
  10.  end
  11.  
  12.   turtle.forward()
  13.   turtle.digUp()
  14.   turtle.up()
  15.   turtle.digUp()
  16.   turtle.down()
  17. end
  18.  
  19. function torch()
  20.  
  21.  turtle.turnLeft()
  22.  turtle.dig()
  23.  turtle.select(16)
  24.  turtle.place()
  25.  turtle.turnRight()
  26. end
  27.  
  28. function returning()
  29.  
  30.  while turtle.detect() == true do
  31.   turtle.dig()
  32.   sleep (0.7)
  33.  end
  34.  
  35.   turtle.forward()
  36. end
  37.  
  38.  
  39.  
  40. function round(r,d)
  41.  
  42. local d = d or 1
  43.  return math.floor((r + d / 2) / d * d)
  44. end
  45.  
  46. -- Main Body --
  47.  
  48. term.write("How far would you like to mine? ")
  49.  input = read()
  50.  
  51.  fuelreq = input * 4
  52.  
  53.  
  54.   sleep (1)
  55.  print ("Fuel Required: "..fuelreq)
  56.  
  57.   sleep (1)
  58.  print ("Current Fuel Level: "..turtle.getFuelLevel())
  59.  
  60. local fuelshort = fuelreq - turtle.getFuelLevel()
  61.  if turtle.getFuelLevel() - fuelreq < 0 then
  62.    
  63.  print ("Not enough fuel, please add " ..fuelshort.. " fuel into slot 1-15...")
  64.  
  65.   while turtle.getFuelLevel() < fuelreq do
  66.    for x = 1,15 do  
  67.      turtle.select(x)
  68.      turtle.refuel(64)
  69.     x = x + 1
  70.   end
  71.  end
  72. end
  73.  
  74.  sleep (1)  
  75.   print ("Enough fuel for this trip")
  76.  
  77.  sleep (1)
  78. term.write ("Checking torch quantities")
  79. sleep (0.6)
  80.  term.write (".")
  81. sleep (0.5)
  82.  term.write (".")
  83. sleep (0.5)
  84.  print (".")
  85. sleep (0.5)
  86.  
  87. local  torchneed = input / 10
  88. local  torchreq = round(torchneed, 1)
  89.  
  90. turtle.select(16)
  91.  
  92.  if turtle.getItemCount(16) < torchneed then
  93.   print ("Not enough torches, please place "..torchreq - turtle.getItemCount(16).." more into slot 16..")
  94.  
  95.   while turtle.getItemCount(16) < torchreq do
  96.    sleep (1)
  97.   end
  98.  end
  99.  
  100.  sleep (0.3)
  101.   print ("Enough torches")
  102.  
  103.  sleep (0.8)
  104.   print ("Proceeding to mine...")
  105.  
  106. local tally = 0
  107.  for tally = 1,input do
  108.    dig()
  109.  
  110.   if tally % 10 == 0 then
  111.    torch()
  112.    
  113.   end
  114.  end
  115.  
  116. print ("Returning Back...")
  117.  
  118.  turtle.turnRight()
  119.  turtle.turnRight()
  120.  
  121. local q = 0
  122.  for q = 1,input do
  123.   returning()
  124.  end
  125.  
  126. local e = 0
  127.  for e = 1,16 do
  128.    turtle.select(e)
  129.    turtle.drop(64)
  130.   e = e + 1
  131.  end
  132.  
  133. print ("Finished Mining!")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement