Advertisement
hdgamer14

Miner-alpha 0.3.1(derped on some code, sorry)

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