Advertisement
Guest User

Quarry

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