Advertisement
Guest User

Quarry

a guest
Nov 25th, 2014
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.12 KB | None | 0 0
  1. -- cd disk
  2. -- edit quarry
  3. -- Episode 17
  4.  
  5. xCoord = -1668  // Starting x Coord
  6. zCoord = -484   // Starting z Coord
  7. yCoord = 127    // Starting y Coord
  8.  
  9. orientation = 4 -- Starting orientation
  10. orientations = {"North","East","South","West"}  -- Strings of the orientations
  11.  
  12. zDiff = {-1, 0, +1, 0}
  13. xDiff = {0, +1, 0, -1}
  14.  
  15. Length = 9
  16. Width = 10
  17. yMin = yCoord
  18.  
  19. xQuarry = 999
  20. zQuarry = 999
  21. yQuarry = 150
  22.  
  23. xProgress = 999
  24. zProgress = 999
  25. yProgress = 150
  26. oProgress = 1
  27.  
  28. xHome = xCoord
  29. zHome = zCoord
  30. yHome = yCoord  
  31.  
  32. yTravel = 85
  33.  
  34. function inventoryFull()
  35.     turtle.select(9)
  36.     full = turtle.getItemCount(9) > 0
  37.     turtle.select(1)
  38.     return full
  39. end
  40.  
  41. function left()
  42.     orientation = orientation -1
  43.     orientation = (orientation -1) % 4
  44.     orientation = orientation +1
  45.    
  46.     turtle.turnLeft()
  47. end
  48.  
  49. function right()
  50.     orientation = orientation -1
  51.     orientation = (orientation +1) % 4
  52.     orientation = orientation +1
  53.    
  54.     turtle.turnRight()
  55. end
  56.  
  57. function moveForward()
  58.     xCoord = xCoord + xDiff[orientation]
  59.     zCoord = zCoord + zDiff[orientation]
  60.     turtle.dig()
  61.     moved = false
  62.     while not(moved) do
  63.         moved = turtle.forward()
  64.     end
  65. end
  66.  
  67. function moveUp()
  68.     yCoord = yCoord +1
  69.    
  70.     turtle.digUp()
  71.    
  72.     moved = false
  73.     while not(moved) do
  74.         moved = turtle.up()
  75.     end
  76. end
  77.  
  78. function moveDown()
  79.     yCoord = yCoord -1
  80.    
  81.     turtle.digDown()
  82.    
  83.     moved = false
  84.     while not(moved) do
  85.         moved = turtle.down()
  86.     end
  87.    
  88.     if yMin > yCoord then
  89.         yMin = yCoord
  90.     end
  91. end
  92.  
  93. function look(direction)
  94.     while direction ~= orientations[orientation] do
  95.         right()
  96.     end
  97. end
  98.  
  99. function goto(xTarget,zTarget,yTarget)
  100.     while yTarget < yCoord do
  101.         moveDown()
  102.     end
  103.     while yTarget > yCoord do
  104.         moveUp()
  105.     end
  106.    
  107.     if xTarget < xCoord then
  108.         look("West")
  109.         while xTarget < xCoord do
  110.             moveForward()
  111.         end
  112.     end
  113.     if xTarget > xCoord then
  114.         look("East")
  115.         while xTarget > xCoord do
  116.             moveForward()
  117.         end
  118.     end
  119.    
  120.     if zTarget < zCoord then
  121.         look("North")
  122.         while zTarget < zCoord do
  123.             moveForward()
  124.         end
  125.     end
  126.     if zTarget > zCoord then
  127.         look("South")
  128.         while zTarget > zCoord do
  129.             moveForward()
  130.         end
  131.     end
  132. end
  133.  
  134. function returnItems()
  135.     xProgress = xCoord
  136.     zProgress = zCoord
  137.     yProgress = yCoord
  138.     oProgress = orientation
  139.    
  140.     goto(xHome, zHome, yTravel)
  141.     goto(xHome, zHome, yHome)
  142.     for i = 1,9 do
  143.         turtle.select(i)
  144.         turtle.drop()
  145.     end
  146.     turtle.select(1)
  147.    
  148.     goto(xProgress, zProgress, yTravel)
  149.     goto(xProgress, zProgress, yProgress)
  150.     look(orientations[oProgress])
  151. end
  152.  
  153. function digLine()
  154.     for i = 1,Length do
  155.         if inventoryFull() then
  156.             returnItems()
  157.         end
  158.         moveForward()
  159.     end
  160. end
  161.  
  162. function digLayer()
  163.     for i = 1,Width do
  164.         digLine()
  165.         if (i%2) == 1 and i < Width then
  166.             left()
  167.             moveForward()
  168.             left()
  169.         elseif i < Width then
  170.             right()
  171.             moveForward()
  172.             right()
  173.         end
  174.     end
  175.     goto(xQuarry, zQuarry, yCoord)
  176.     look("North")
  177.     moveDown()
  178. end
  179.  
  180. function digQuarry(xTarget, zTarget, yTarget)
  181.     xQuarry = xTarget
  182.     zQuarry = zTarget
  183.     yQuarry = yTarget
  184.    
  185.     goto(xQuarry,zQuarry,yTravel)
  186.     goto(xQuarry,zQuarry,yQuarry)
  187.     while yMin > 5 do
  188.         digLayer()
  189.     end
  190.     goto(xQuarry, zQuarry, yQuarry)
  191.     yMin = 999
  192. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement