Advertisement
hdgamer14

Miner-alpha 0.4(fix issue going home)

Dec 2nd, 2012
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.72 KB | None | 0 0
  1. --[[
  2. Made by HDGamer14
  3.  
  4. Alpha 0.4
  5.  
  6. To Do:
  7. - feature to leave the diamonds for you to break with fourtan pick
  8. - squash more bugs
  9. --]]
  10.  
  11.  
  12. local dist,dist1,row,row1,torchs,debug,auto_refuel,direction,home_dist,home_distRow,home,miner,torchRow,torchDist
  13.  
  14. debug = false
  15. auto_refuel = false
  16.  
  17.  
  18. function mine()
  19.   turtle.digUp()
  20.   turtle.dig()
  21.   turtle.digDown()  
  22. end
  23.  
  24. function unload()
  25.   turtle.turnRight()
  26.   print ("Unloading items...")
  27.   for n=1,15 do
  28.     turtle.select(n)
  29.     turtle.drop()
  30.   end
  31.   turtle.select(1)
  32.   turtle.turnLeft()
  33. end
  34.  
  35. function go_back()
  36.   print("Resuming mining . . .")
  37.   if home_distRow == 0 then
  38.     turtle.turnLeft()
  39.   else
  40.     for i=1,home_distRow do
  41.       turtle.back()
  42.     end
  43.     turtle.turnLeft()
  44.   end  
  45.   for i=1,home_dist do
  46.    turtle.forward()
  47.   end
  48.   if direction == true then
  49.    else  
  50.     turtle.turnLeft()
  51.     turtle.forward()
  52.     turtle.turnLeft()
  53.   end
  54.   turtle.suck()
  55.   turtle.suckDown()
  56. end
  57.  
  58. function fuel()
  59.   if turtle.getFuelLevel() < home then
  60.     print ("Out of fuel!")
  61.       if auto_refuel == true then
  62.         turtle.select(1)
  63.         for f=1,14 do
  64.           turtle.select(f)
  65.           turtle.refuel(2)          
  66.         end
  67.         turtle.select(1)
  68.         if turtle.getFuelLevel() < home then
  69.         go_home()
  70.         fuel_me()
  71.         go_back()
  72.         end
  73.       else
  74.         go_home()
  75.         fuel_me()
  76.         go_back()
  77.       end
  78.   else
  79.   end
  80. end
  81.  
  82. function fuel_me()
  83.   print ("Waiting for fuel . . .")
  84.   turtle.select(1)
  85.   repeat
  86.     turtle.refuel(2)
  87.     sleep(1)
  88.   until turtle.getFuelLevel() > 180
  89. end
  90.  
  91. function go_home()
  92.   if debug == true then
  93.     print("Go_home")
  94.   else
  95.  
  96.   end
  97.   home_distRow = row - row1
  98.   if direction == true then
  99.     home_dist = dist - dist1
  100.   else
  101.     turtle.turnLeft()
  102.     turtle.forward()
  103.     turtle.turnLeft()
  104.     home_dist = dist1 - 1
  105.   end
  106.   for i=1,home_dist do
  107.    turtle.back()
  108.   end
  109.   turtle.turnRight()
  110.   if home_distRow == 0 then
  111.     unload()
  112.   else
  113.     for j=1,home_distRow do
  114.       turtle.forward()
  115.     end
  116.     unload()
  117.   end
  118. end
  119.  
  120. function new_row()
  121.   print("Row = "..row1)
  122.   if row1 == 1 then
  123.     turtle.digUp()
  124.     turtle.digDown()
  125.     print("Finised mineing")
  126.   else
  127.     if debug == true then
  128.         print("New_row")
  129.         print("Row = "..row1)
  130.     end
  131.     if direction == true then
  132.       turtle.turnLeft()
  133.       mine()
  134.       turtle.forward()
  135.       turtle.turnLeft()
  136.       direction = false
  137.     else
  138.       turtle.turnRight()
  139.       mine()
  140.       turtle.forward()
  141.       turtle.turnRight()
  142.       direction = true
  143.     end
  144.     dist1 = dist
  145.     row1 = row1 - 1
  146.     home = home + 1
  147.     if torchs == true then
  148.       torchDist = 0
  149.       torchRow = torchRow + 1
  150.       if torchRow == 4 then
  151.         torchRow = 0
  152.       end
  153.     end
  154.   end  
  155. end
  156.  
  157. function cycle()
  158.  
  159.   if debug == true then
  160.     print ("Cycle")
  161.     sleep(1)
  162.   end
  163.   if dist1 == 0 then
  164.     new_row()
  165.   else
  166.   mine()
  167.   if torchs == true then    
  168.     if torchRow == 0 then
  169.       torchDist = torchDist + 1
  170.       if torchDist == 5 then
  171.         turtle.select(16)
  172.         turtle.placeDown()
  173.         turtle.select(1)
  174.         torchDist = 0
  175.       end  
  176.     end
  177.   end
  178.     dist1 = dist1 - 1
  179.   if direction == true then
  180.     home = home + 1
  181.   else
  182.     home = home - 1
  183.   end  
  184.   if turtle.forward() == false then
  185.     for i=1,5 do
  186.     turtle.attack()
  187.     mine()
  188.     sleep(1)
  189.     end
  190.     turtle.forward()
  191.   end
  192.   fuel()
  193.   if turtle.getItemCount(14) > 0
  194.    then
  195.    go_home()
  196.    go_back()
  197.    end
  198.   end
  199.     if debug == true then
  200.       print("TorchRow "..torchRow)
  201.       print("TorchDist "..torchDist)
  202.       print("Dist after "..dist1)
  203.       print("")
  204.   end
  205. end
  206.  
  207. --Get info
  208.  
  209.   shell.run("clear")
  210.   print("How far you you like me to go?")
  211.     dist=read()
  212.   print("How many rows would you like me to mine?")
  213.     row=read(number)
  214.   print("Would you like me to use torches? (yes/no)")
  215.     torchs=read()
  216.   if torchs == "yes" then
  217.     print("Place torhes in slot 16")
  218.     repeat
  219.       sleep(1)
  220.     until turtle.getItemCount(16) > 0
  221.  
  222.  torchs = true
  223.    else
  224.  torchs = false  
  225.   end
  226.    
  227.   if debug == true then
  228.       print("")
  229.       print ("I'm mineing "..dist.." blocks deep!")
  230.       print ("I'm mineing "..row.." Row(s) over!")
  231.   if torchs == true then
  232.       print ("I will use torches!")
  233.     else
  234.       print ("I will not use torches!")
  235.   end
  236.     end
  237.  
  238. dist1 = dist
  239. row1 = row
  240. home = 5
  241. direction = true
  242. miner = dist * row
  243. miner = miner + row
  244. torchRow = 0
  245. torchDist = 0
  246.  
  247. -- Start Program
  248. repeat
  249.   cycle()
  250.   miner = miner - 1
  251. until miner == 0
  252. go_home()
  253. turtle.turnRight()
  254. turtle.select(16)
  255. turtle.drop()
  256. turtle.select(1)
  257. print("All Done :D")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement