Aarondmorgan

GPSmine v.03

Jun 30th, 2013
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 7.11 KB | None | 0 0
  1. --AaronDMorgan's GPS Mining Turtle Program
  2. --Manually entered "end coordinates" will be changed to changeable Args in the future.
  3. --CURRENTLY MINES ONE TUNNEL FOR DEBUGGING PURPOSES!
  4.  
  5. --function for leaving the ground
  6. function ymoveup()
  7. updist = 1
  8.         repeat
  9.                 turtle.up()
  10.                 updist = updist - 1
  11.         until updist == 0
  12.         updist = 1
  13. end
  14.  
  15. --function responsible for z-plane movement to chest
  16. function zmove()
  17.         if z > 1033 then            --Enter end z coordinate here
  18.                 zdist = z - 1033
  19.                 repeat
  20.                         turtle.forward()
  21.                         zdist = zdist - 1
  22.                 until zdist == 0
  23.         end
  24.         if z < 1033 then
  25.                 zdist = z - 1033
  26.                 zdist = zdist * -1
  27.                 turtle.turnRight()
  28.                 turtle.turnRight()
  29.                 repeat
  30.                         turtle.forward()
  31.                         zdist = zdist - 1
  32.                 until zdist == 0
  33.                 turtle.turnRight()
  34.                 turtle.turnRight()
  35.         end
  36.         turtle.turnLeft()
  37. end
  38.  
  39. --function responsible for x-plane movement to chest
  40. function xmove()
  41.         if x > 233 then             -- enter end x coordinate here
  42.                 xdist = x - 233
  43.                 repeat
  44.                         turtle.forward()
  45.                         xdist = xdist - 1
  46.                 until xdist == 0
  47.         end
  48.         if x < 233 then
  49.                 xdist = x - 233
  50.                 xdist = xdist * -1
  51.                 turtle.turnRight()
  52.                 turtle.turnRight()
  53.                 repeat
  54.                         turtle.forward()
  55.                         xdist = xdist - 1
  56.                 until xdist == 0
  57.                 turtle.turnRight()
  58.                 turtle.turnRight()
  59.         end
  60. end
  61.  
  62. --function responsible for landing
  63. function ymovedown()
  64.         y = y + updist
  65.         ydist = y - 11              --enter end y coordinate here
  66.         repeat
  67.                 turtle.down()
  68.                 ydist = ydist - 1
  69.         until ydist == 0
  70.         turtle.turnRight()
  71. end
  72.  
  73. --function responsible for z-plane movement back to mining
  74. function zmoveback()
  75.         if z > zstart then         
  76.                 zdist = z - zstart
  77.                 repeat
  78.                         turtle.forward()
  79.                         zdist = zdist - 1
  80.                 until zdist == 0
  81.         end
  82.         if z < zstart then
  83.                 zdist = z - zstart
  84.                 zdist = zdist * -1
  85.                 turtle.turnRight()
  86.                 turtle.turnRight()
  87.                 repeat
  88.                         turtle.forward()
  89.                         zdist = zdist - 1
  90.                 until zdist == 0
  91.                 turtle.turnRight()
  92.                 turtle.turnRight()
  93.         end
  94.         turtle.turnLeft()
  95. end
  96.  
  97. --function responsible for x-plane movement back to mining
  98. function xmoveback()
  99.         if x > xstart then             
  100.                 xdist = x - xstart
  101.                 repeat
  102.                         turtle.forward()
  103.                         xdist = xdist - 1
  104.                 until xdist == 0
  105.         end
  106.         if x < xstart then
  107.                 xdist = x - xstart
  108.                 xdist = xdist * -1
  109.                 turtle.turnRight()
  110.                 turtle.turnRight()
  111.                 repeat
  112.                         turtle.forward()
  113.                         xdist = xdist - 1
  114.                 until xdist == 0
  115.                 turtle.turnRight()
  116.                 turtle.turnRight()
  117.         end
  118. end
  119.  
  120. --[[Computer slot 1, Filter slot 2, Timer slot 3, Chest slot 4, Fuel slot 15, torches slot 16.]]
  121. -- Create the function for refueling
  122. function checkFuel()
  123.   if turtle.getFuelLevel() <= 20 then
  124.         if turtle.getItemCount(15) == 0 then
  125.     print("Out of fuel.")
  126.     exit()
  127.   else
  128.    turtle.select(15)
  129.           turtle.refuel(1)
  130.           turtle.select(1)
  131. end --if
  132. end --if
  133. end --checkFuel()
  134.  
  135. -- Create the turnAround function
  136. function turnAround()
  137.   turtle.turnRight()
  138.   turtle.turnRight()
  139. end --turnAround()
  140.  
  141. -- Digs the tunnel for the given length
  142. function tunnel(length)
  143.   local torchDistance = 0
  144.   d = 0
  145.   while d <= 75 do              --change to increase tunnel distance
  146.     if turtle.detect() then
  147.         repeat
  148.             turtle.dig()
  149.             sleep(0.50)
  150.         until turtle.detect() == false
  151. end --if
  152.     turtle.forward()
  153.     if turtle.detectUp() then
  154.         repeat
  155.             turtle.digUp()
  156.             sleep(0.50)
  157.         until turtle.detectUp() == false
  158. end --if
  159.     turtle.turnLeft()
  160.     if turtle.detect() then
  161.         repeat
  162.             turtle.dig()
  163.             sleep(0.50)
  164.         until turtle.detect() == false
  165. end --if
  166.     turtle.up()
  167.     if turtle.detect() then
  168.         repeat
  169.             turtle.dig()
  170.             sleep(0.50)
  171.         until turtle.detect() == false
  172. end--if
  173.     turtle.turnRight()
  174.     turtle.turnRight()
  175.     if turtle.detect() then
  176.         repeat
  177.             turtle.dig()
  178.             sleep(0.50)
  179.         until turtle.detect() == false
  180. end
  181.     turtle.down()
  182.     if turtle.detect() then
  183.         repeat
  184.             turtle.dig()
  185.             sleep(0.50)
  186.         until turtle.detect() == false
  187. end
  188.     turtle.turnLeft()
  189.     d = d + 1
  190. torchDistance = torchDistance + 1
  191. -- attempts to place a block below
  192.         turtle.select(1)
  193.         turtle.placeDown()
  194. -- Places a torch every 9 blocks
  195.         if torchDistance == 9 then
  196.           print("Placing torch...")
  197.    turtle.select(16)
  198.           turnAround()
  199.           turtle.place()
  200.           turnAround()
  201.           torchDistance = 0
  202.           checkFuel()
  203.         end --if
  204.   end --for
  205. -- Sends the turtle back to the start
  206.         turtle.up()
  207. turnAround()
  208.         for index = 1, d do
  209.           checkFuel()
  210.    if not turtle.detect() then
  211.   turtle.forward()
  212.           else
  213.          repeat
  214.         turtle.dig()
  215.            turtle.sleep(0.25)
  216.   until turtle.detect() == false
  217.   turtle.forward()
  218.           end --if
  219.         end --for
  220.         turtle.down()
  221. turnAround()
  222. end --tunnel()
  223.  
  224. --function responsible for emptying inventory into chest
  225. function itemdump()
  226.     turtle.select(1)
  227.         turtle.drop()
  228.         turtle.select(2)
  229.         turtle.drop()
  230.         turtle.select(3)
  231.         turtle.drop()
  232.         turtle.select(4)
  233.         turtle.drop()
  234.         turtle.select(5)
  235.         turtle.drop()
  236.         turtle.select(6)
  237.         turtle.drop()
  238.         turtle.select(7)
  239.         turtle.drop()
  240.         turtle.select(8)
  241.         turtle.drop()
  242.         turtle.select(9)
  243.         turtle.drop()
  244.         turtle.select(10)
  245.         turtle.drop()
  246.         turtle.select(11)
  247.         turtle.drop()
  248.         turtle.select(12)
  249.         turtle.drop()
  250.         turtle.select(13)
  251.     turtle.drop()
  252.         turtle.select(14)
  253.         turtle.drop()
  254.         turtle.select(15)
  255.         turtle.drop()
  256. end --itemdump()
  257.  
  258. -- Main script
  259. rednet.open("right")
  260. x, y, z = gps.locate()
  261. xstart, ystart, zstart = gps.locate()
  262. tunnel()
  263. ymoveup()
  264. zmove()
  265. xmove()
  266. ymovedown()
  267. itemdump()
  268. x, y, z = gps.locate()
  269. ymoveup()
  270. zmoveback()
  271. xmoveback()
  272. turtle.forward()
  273. turtle.forward()
  274. turtle.forward()
  275. ymovedown()
Advertisement
Add Comment
Please, Sign In to add comment