Guest User

Untitled

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