Advertisement
Guest User

Quarry

a guest
Oct 24th, 2016
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.95 KB | None | 0 0
  1. xCoord = 405
  2. zCoord = 743
  3. yCoord = 64
  4.  
  5. xQuarry = 999
  6. zQuarry = 999
  7. yQuarry = 150
  8.  
  9. xProgress = 999
  10. zProgress = 999
  11. yProgress = 150
  12. oProgress = 1
  13.  
  14. xHome = xCoord
  15. zHome = zCoord
  16. yHome = yCoord
  17.  
  18. yTravel = 79
  19.  
  20. orientation = 4
  21. orientations = {"north","east","south","west"}
  22.  
  23. zDiff = {-1, 0, 1, 0}
  24. xDiff = {0, 1, 0, -1}
  25.  
  26. lineLength = 10
  27. lines = 9
  28. yMin = 999
  29.  
  30. jobAvailable = true
  31. manager = 43
  32.  
  33. function inventoryFull()
  34.   return turtle.getItemCount(16) > 0
  35. end
  36.  
  37. function left()
  38.   orientation = orientation - 1
  39.   orientation = (orientation -1) % 4
  40.   orientation = orientation + 1
  41.  
  42.   turtle.turnLeft()
  43. end
  44.  
  45.  
  46. function right()
  47.   orientation = orientation - 1
  48.   orientation = (orientation + 1) % 4
  49.   orientation = orientation + 1
  50.  
  51.   turtle.turnRight()
  52. end
  53.  
  54. function moveForward()
  55.   xCoord = xCoord + xDiff[orientation]
  56.   zCoord = zCoord + zDiff[orientation]
  57.  
  58.    turtle.dig()
  59.    moved = false
  60.    while not(moved) do
  61.      moved = turtle.forward()
  62.     end
  63.   end
  64.  
  65. function moveUP()
  66.   yCoord = yCoord + 1
  67.  
  68.   turtle.digUp()
  69.  
  70.   moved = false
  71.   while not(moved) do
  72.     moved = turtle.up()
  73.     end
  74.   end
  75.  
  76. function moveDown()
  77.   yCoord = yCoord - 1
  78.  
  79.   turtle.down()
  80.  
  81.   moved = false
  82.   while not(moved) do
  83.     moved = turtle.down()
  84.   end
  85.      
  86.     if yMin > yCoord then
  87.       yMin = yCoord
  88.     end
  89.   end
  90.  
  91. function look(direction)
  92.   while direction ~= orientations[orientation] do
  93.     right()
  94.   end  
  95. end
  96.  
  97. function goto(xTarget, zTarget, yTarget)
  98.    while yTarget < yCoord do
  99.       moveDown()
  100.     end
  101.    while yTarget > yCoord do
  102.      moveUP()
  103.    end
  104.  
  105.   if xTarget < xCoord then
  106.     look("west")
  107.     while xTarget < xCoord do
  108.       moveForward()
  109.     end
  110.   end
  111.   if xTarget > xCoord then
  112.     look("east")
  113.     while xTarget > xCoord do
  114.       moveForward()
  115.     end
  116.   end
  117.   if zTarget < zCoord then
  118.     look("north")
  119.     while zTarget < zCoord do
  120.       moveForward()
  121.     end
  122.   end
  123.   if zTarget > zCoord then
  124.     look("south")
  125.     while zTarget > zCoord do
  126.       moveForward()
  127.     end
  128.   end
  129. end
  130.  
  131. function returnItems()
  132.   xProgress = xCoord
  133.   zProgress = zCoord
  134.   yProgress = yCoord
  135.   oProgress = orientation
  136.  
  137.   goto(xHome, zHome, yTravel)
  138.   goto(xHome, zHome, yHome)
  139.   look("west")
  140.  
  141.   for i = 1,16 do
  142.     turtle.select(i)
  143.     turtle.drop()
  144.     end
  145.     turtle.select(1)
  146.    
  147.     goto(xProgress, zProgress, yTravel)
  148.     goto(xProgress, zProgress, yProgress)
  149.     look(orientations[oProgress])
  150.   end
  151.  
  152. function digLine()
  153.   for i = 1,lineLength do
  154.     if inventoryFull() then
  155.      returnItems()  
  156.    end
  157.     moveForward()
  158.   end
  159. end
  160.  
  161. function digLayer()
  162.   for i = 1,lines do
  163.     digLine()
  164.     if i%2 == 1 and i < lines then
  165.       left()
  166.       moveForward()
  167.       left()
  168.      elseif i < lines then
  169.        right()
  170.        moveForward()
  171.        right()
  172.      end
  173.    end
  174.    goto(xQuarry, zQuarry, yCoord)
  175.    look("north")
  176.    moveDown()
  177.  end
  178.  
  179. function digQuarry(xTarget, zTarget, yTarget)
  180.   xQuarry = xTarget
  181.   zQuarry = zTarget
  182.   yQuarry = yTarget
  183.  
  184.   goto(xQuarry, zQuarry, yTravel)
  185.   goto(xQuarry, zQuarry, yQuarry)
  186.   while yMin > 7 do
  187.      digLayer()
  188.    end
  189.   goto(xQuarry, zQuarry, yQuarry)
  190.   goto(xHome, zHome, yTravel)
  191.   goto(xHome, zHome, yHome)
  192.   yMin = 999
  193. end
  194.  
  195. function getjob()
  196.   while jobAvailable do
  197.     print("Requesting Job")
  198.     rednet.send(manager, "getJob")
  199.     id, message, dis = rednet.receive()
  200.    
  201.     if message == "yes" then
  202.       id, xRec, dis = rednet.receive()
  203.       id, zRec, dis = rednet.receive()
  204.       id, yRec, dis = rednet.receive()
  205.      
  206.       xQuarry = tonumber(xRec)
  207.       zQuarry = tonumber(zRec)
  208.       yQuarry = tonumber(yRec)
  209.       print("Job at"..xQuarry.." "..zQuarry)
  210.       digQuarry(xQuarry, zQuarry, yQuarry)
  211.       print("Finshed Job")
  212.     elseif message == "no" then
  213.       print("No more Jobs")
  214.       jobAvailable = false
  215.     end
  216.   end
  217. end
  218. rednet.close("right")
  219. rednet.open("right")
  220.  
  221.  getjob()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement