Advertisement
hdgamer14

Miner-alpha 0.3.2(sand/gravel fix)

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