Advertisement
DabDaddy6223

quarryclient

Mar 10th, 2023 (edited)
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.50 KB | None | 0 0
  1. XPos = 0
  2. YPos = 0
  3. ZPos = 0
  4. InitialX = 0
  5. InitialY = 0
  6. InitialZ = 0
  7. Facing = 0 -- 0 - +x, 1 - -x, 2 - +z, 3 - -z
  8.  
  9. function moveTo(x, y, z)
  10. end
  11.  
  12. function correctPosition(expectedX, expectedY, expectedZ)
  13. end
  14.  
  15. function getDimensions(data)
  16.     local tab = {}
  17.  
  18.     for str in string.gmatch(data, "([^x]+)") do
  19.         table.insert(tab, str)
  20.     end
  21.  
  22.     return tab[1], tab[2], tab[3]
  23. end
  24.  
  25. function turnAround()
  26.     turtle.turnLeft()
  27.     turtle.turnLeft()
  28. end
  29.  
  30. function setFacingDirection()
  31.     if not turtle.detect() then
  32.         turtle.forward()
  33.         local x, y, z = gps.locate()
  34.         if x > InitialX then
  35.             Facing = 0
  36.         elseif x < InitialX then
  37.             Facing = 1
  38.         elseif z > InitialZ then
  39.             Facing = 2
  40.         elseif z < InitialZ then
  41.             Facing = 3
  42.         end
  43.         turnAround()
  44.         turtle.forward()
  45.         turnAround()
  46.     end
  47. end
  48.  
  49. function prepare()
  50.     setFacingDirection()
  51.     InitialY = InitialY - 1
  52.     XPos, YPos, ZPos = InitialX, InitialY, InitialZ
  53. end
  54.  
  55. function stripLayer(w, d)
  56.     local pivotX, pivotY, pivotZ = InitialX, InitialY, InitialZ
  57.     for i = 1, (d / 2) do
  58.         while XPos < (pivotX + w - 1) do
  59.             turtle.dig()
  60.             turtle.forward()
  61.             XPos, YPos, ZPos = gps.locate()
  62.         end
  63.  
  64.         turtle.turnLeft()
  65.         turtle.dig()
  66.         turtle.forward()
  67.         turtle.turnLeft()
  68.  
  69.         XPos, YPos, ZPos = gps.locate()
  70.         pivotX, pivotY, pivotZ = XPos, YPos, ZPos
  71.  
  72.         while XPos > (pivotX - w + 1) do
  73.             turtle.dig()
  74.             turtle.forward()
  75.             XPos, YPos, ZPos = gps.locate()
  76.         end
  77.  
  78.         turtle.turnRight()
  79.         turtle.dig()
  80.         turtle.forward()
  81.         turtle.turnRight()
  82.  
  83.         XPos, YPos, ZPos = gps.locate()
  84.         pivotX, pivotY, pivotZ = XPos, YPos, ZPos
  85.     end
  86. end
  87.  
  88. function move(w, d, h)
  89.     for i = 1, h do
  90.         turtle.digDown()
  91.         turtle.down()
  92.         stripLayer(w, d)
  93.         turtle.turnRight()
  94.         for j = 1, w do
  95.             turtle.forward()
  96.         end
  97.         turtle.turnLeft()
  98.     end
  99. end
  100.  
  101. function main()
  102.     local modem = peripheral.find("modem", rednet.open)
  103.     rednet.broadcast("turtle", "turtnettoserver")
  104.  
  105.     local id, message = rednet.receive("turtnettoclient")
  106.     local width, height, depth = getDimensions(message)
  107.  
  108.     InitialX, InitialY, InitialZ = gps.locate()
  109.    
  110.     turtle.refuel()
  111.     prepare()
  112.     move(width, depth, height)
  113. end
  114.  
  115. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement