Advertisement
hdgamer14

Miner-alpha 0.2(great for diamonds)

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