Advertisement
hdgamer14

Miner-alpha 0.3(more bug fixes)

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