Advertisement
Guest User

Quarry

a guest
Oct 24th, 2016
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.97 KB | None | 0 0
  1. xCoord = 404
  2. zCoord = 746
  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.   full = turtle.getItemCount(16) > 0
  35.   turtle.select(1)
  36. end
  37.  
  38. function left()
  39.   orientation = orientation - 1
  40.   orientation = (orientation -1) % 4
  41.   orientation = orientation + 1
  42.  
  43.   turtle.turnLeft()
  44. end
  45.  
  46.  
  47. function right()
  48.   orientation = orientation - 1
  49.   orientation = (orientation + 1) % 4
  50.   orientation = orientation + 1
  51.  
  52.   turtle.turnRight()
  53. end
  54.  
  55. function moveForward()
  56.   xCoord = xCoord + xDiff[orientation]
  57.   zCoord = zCoord + zDiff[orientation]
  58.  
  59.    turtle.dig()
  60.    moved = false
  61.    while not(moved) do
  62.      moved = turtle.forward()
  63.     end
  64.   end
  65.  
  66. function moveUP()
  67.   yCoord = yCoord + 1
  68.  
  69.   turtle.digUp()
  70.  
  71.   moved = false
  72.   while not(moved) do
  73.     moved = turtle.up()
  74.     end
  75.   end
  76.  
  77. function moveDown()
  78.   yCoord = yCoord - 1
  79.  
  80.   turtle.Down()
  81.  
  82.   moved = false
  83.   while not(moved) do
  84.     moved = turtle.Down()
  85.   end
  86.      
  87.     if yMin > yCoord then
  88.       yMin = yCoord
  89.     end
  90.   end
  91.  
  92. function look(direction)
  93.   while direction ~= orientations[orientation] do
  94.     right()
  95.   end  
  96. end
  97.  
  98. function goto(xTarget, zTarget, yTarget)
  99.    while yTarget < yCoord do
  100.       moveDown()
  101.     end
  102.    while yTarget > yCoord do
  103.      moveUP()
  104.    end
  105.  
  106.   if xTarget < xCoord then
  107.     look("west")
  108.     while xTarget < xCoord do
  109.       moveForward()
  110.     end
  111.   end
  112.   if xTarget > xCoord then
  113.     look("east")
  114.     while xTarget > xCoord do
  115.       moveForward()
  116.     end
  117.   end
  118.   if zTarget < zCoord then
  119.     look("north")
  120.     while zTarget < zCoord do
  121.       moveForward()
  122.     end
  123.   end
  124.   if zTarget > zCoord then
  125.     look("south")
  126.     while zTarget > zCoord do
  127.       moveForward()
  128.     end
  129.   end
  130. end
  131.  
  132. function returnItems()
  133.   xProgress = xCoord
  134.   zProgress = zCoord
  135.   yProgress = yCoord
  136.   oProgress = orientation
  137.  
  138.   goto(xHome, zHome, yTravel)
  139.   goto(xHome, zHome, yHome)
  140.   look("west")
  141.  
  142.   for i = 1,16 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,lineLength do
  155.     if inventoryFull() then
  156.      returnItems()  
  157.    end
  158.     moveForward()
  159.   end
  160. end
  161.  
  162. function digLayer()
  163.   for i = 1,lines do
  164.     digLine()
  165.     if i%2 == 1 and i < lines then
  166.       left()
  167.       moveForward()
  168.       left()
  169.      elseif i < lines 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 > 7 do
  188.      digLayer()
  189.    end
  190.   goto(xQuarry, zQuarry, yQuarry)
  191.   goto(xHome, zHome, yTravel)
  192.   goto(xHome, zHome, yHome)
  193.   yMin = 999
  194. end
  195.  
  196. function getjob()
  197.   while jobAvailable do
  198.     print("Requesting Job")
  199.     rednet.send(manager, "getJob")
  200.     id, message, dis = rednet.receive()
  201.    
  202.     if message == "yes" then
  203.       id, xRec, dis = rednet.receive()
  204.       id, zRec, dis = rednet.receive()
  205.       id, yRec, dis = rednet.receive()
  206.      
  207.       xQuarry = tonumber(xRec)
  208.       zQuarry = tonumber(zRec)
  209.       yQuarry = tonumber(yRec)
  210.       print("Job at"..xQuarry.." "..zQuarry)
  211.       digQuarry(xQuarry, zQuarry, yQuarry)
  212.       print("Finshed Job")
  213.     elseif message == "no" then
  214.       print("No more Jobs")
  215.       jobAvailable = false
  216.     end
  217.   end
  218. end
  219. rednet.close("right")
  220. rednet.open("right")
  221.  
  222.  getjob()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement