Advertisement
hdgamer14

Miner-alpha 4.1(Love Squashing Bugs)

Dec 8th, 2012 (edited)
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.29 KB | None | 0 0
  1. --[[
  2. Made by HDGamer14
  3.  
  4. Alpha
  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,newRow
  13.  
  14. debug = true
  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_dist == 0 then
  38.     turtle.turnLeft()
  39.   else
  40.     for i=1,home_dist do
  41.       turtle.back()
  42.     end
  43.     turtle.turnLeft()
  44.   end  
  45.   for i=1,home_distRow 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(16)
  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.     print("dist: ", dist , " dist1: " , dist1)
  95.     print("row: " , row , " row1: " , row1)
  96.   else
  97.  
  98.   end
  99.  
  100.   home_dist = dist - dist1
  101.   if direction == true then
  102.     home_distRow = row - row1
  103.   else
  104.     turtle.turnLeft()
  105.     turtle.forward()
  106.     turtle.turnLeft()
  107.     home_distRow = row - row1 + 1
  108.   end
  109.   for i=1,home_dist do
  110.    turtle.back()
  111.   end
  112.   turtle.turnRight()
  113.   if home_distRow == 0 then
  114.     unload()
  115.   else
  116.     for j=1,home_distRow do
  117.       turtle.forward()
  118.     end
  119.     unload()
  120.   end
  121. end
  122.  
  123. function new_row()
  124.   print("Row = "..row1)
  125.   if row1 == 1 then
  126.     turtle.digUp()
  127.     turtle.digDown()
  128.     print("Finised mineing")
  129.   else
  130.     if debug == true then
  131.         print("New_row")
  132.         print("Row = "..row1)
  133.     end
  134.     if direction == true then
  135.       turtle.turnLeft()
  136.       if turtle.forward() == false then
  137.         repeat
  138.           turtle.attack()
  139.           mine()
  140.           sleep(0.3)
  141.         until turtle.forward() == true
  142.       end
  143.       turtle.turnLeft()
  144.       direction = false
  145.     else
  146.       turtle.turnRight()
  147.       if turtle.forward() == false then
  148.         repeat
  149.           turtle.attack()
  150.           mine()
  151.           sleep(0.3)
  152.         until turtle.forward() == true
  153.       end
  154.       turtle.turnRight()
  155.       direction = true
  156.     end
  157.     dist1 = dist
  158.     row1 = row1 - 1
  159.     home = home + 1
  160.     if torchs == true then
  161.       torchDist = 0
  162.       torchRow = torchRow + 1
  163.       if torchRow == 8 then
  164.         torchRow = 0
  165.       end
  166.     end
  167.   end  
  168. end
  169.  
  170. function cycle()
  171.  
  172.   if debug == true then
  173.     print ("Cycle")
  174.     sleep(1)
  175.   end
  176.   if dist1 == 0 then
  177.     if newRow == true then
  178.     new_row()
  179.     else
  180.       turtle.digUp()
  181.       turtle.digDown()
  182.       print("Finised mineing")      
  183.     end
  184.   else
  185.   mine()
  186.   if torchs == true then    
  187.     if torchRow == 0 then
  188.       torchDist = torchDist + 1
  189.       if torchDist == 5 then
  190.         turtle.select(16)
  191.         turtle.placeDown()
  192.         turtle.select(1)
  193.         torchDist = 0
  194.       end  
  195.     end
  196.   end
  197.     dist1 = dist1 - 1
  198.   if direction == true then
  199.     home = home + 1
  200.   else
  201.     home = home - 1
  202.   end
  203.  
  204.   if turtle.forward() == false then
  205.     repeat
  206.       turtle.attack()
  207.       mine()
  208.       sleep(0.3)
  209.     until turtle.forward() == true
  210.   end
  211.   fuel()
  212.   if turtle.getItemCount(14) > 0
  213.    then
  214.    go_home()
  215.    go_back()
  216.    end
  217.   end
  218.     if debug == true then
  219.       print("TorchRow "..torchRow)
  220.       print("TorchDist "..torchDist)
  221.       print("Dist after "..dist1)
  222.       print("")
  223.   end
  224. end
  225.  
  226. newRow = true
  227.  
  228. --Get info
  229.  
  230.   shell.run("clear")
  231.   print("How far you you like me to go?")
  232.     dist=read()
  233.   print("How many rows would you like me to mine?")
  234.     row=read(number)
  235.     if row == 1 then
  236.       newRow = false
  237.     end  
  238.   print("Would you like me to use torches? (yes/no)")
  239.     torchs=read()
  240.   if torchs == "yes" then
  241.     print("Place torhes in slot 16")
  242.     repeat
  243.       sleep(1)
  244.     until turtle.getItemCount(16) > 0
  245.  
  246.  torchs = true
  247.    else
  248.  torchs = false  
  249.   end
  250.    
  251.   if debug == true then
  252.       print("")
  253.       print ("I'm mineing "..dist.." blocks deep!")
  254.       print ("I'm mineing "..row.." Row(s) over!")
  255.   if torchs == true then
  256.       print ("I will use torches!")
  257.     else
  258.       print ("I will not use torches!")
  259.   end
  260.     end
  261.  
  262. dist1 = dist
  263. row1 = row
  264. home = 5
  265. direction = true
  266. miner = dist * row
  267. miner = miner + row
  268. torchRow = 0
  269. torchDist = 0
  270. -- Start Program
  271. repeat
  272.   cycle()
  273.   miner = miner - 1
  274. until miner == 0
  275. go_home()
  276. turtle.turnRight()
  277. turtle.select(16)
  278. turtle.drop()
  279. turtle.select(1)
  280. print("All Done :D")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement