Cwackers

Spiral TurtleDig

Mar 25th, 2022 (edited)
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.12 KB | None | 0 0
  1. local args = {...}
  2.  
  3. if not #args == 3 then
  4. print("Usage: Args start x,y,z")
  5. return
  6. end
  7.  
  8. local spiralSize = 4
  9. local bottom = -58
  10.  
  11. local x, y, z = gps.locate(5)
  12.  
  13. if not x then
  14. print("co-ord get failed")
  15. else
  16. print("start co-ord " .. x .. ", " .. y .. ", " .. z)
  17. end
  18.  
  19. function returnStart()
  20. local facing = 0
  21. while not turtle.forward() do turtle.dig() end
  22. local a,b,c = gps.locate(5)
  23. if x-a == -1 then
  24. facing = 1
  25. elseif z-c == 1 then
  26. facing = 2
  27. elseif x-a == 1 then
  28. facing = 3
  29. else
  30. facing = 0
  31. end
  32.  
  33. turtle.turnRight()
  34. turtle.turnRight()
  35. while not turtle.forward() do turtle.dig() end
  36. facing = (facing)%4
  37. print("facing = " .. facing)
  38. turtle.turnRight()
  39. turtle.turnRight()
  40.  
  41. for i=0,facing do
  42. turtle.turnRight()
  43. end
  44.  
  45. local xMove = x - args[1]
  46. local zMove = args[3] - z
  47.  
  48. print(xMove)
  49. print(zMove)
  50.  
  51. for i=0, xMove-1 do
  52. while not turtle.forward() do turtle.dig() end
  53. end
  54. turtle.turnLeft()
  55. for i=0, zMove-1 do
  56. while not turtle.forward() do turtle.dig() end
  57. end
  58.  
  59. turtle.turnRight()
  60. turtle.turnRight()
  61. end
  62.  
  63. function checkInv()
  64. isFull = true
  65.  
  66. for i=1,15 do
  67. if turtle.getItemCount(i) == 0 then
  68. isFull = false
  69. end
  70. end
  71.  
  72. if isFull == true then
  73. emptyInv()
  74. end
  75. end
  76.  
  77. function emptyInv()
  78. turtle.select(16)
  79. while turtle.detectUp() do
  80. turtle.digUp()
  81. sleep(0.2)
  82. end
  83. turtle.up()
  84. while not turtle.placeDown() do turtle.digDown() end
  85. for i=1,15 do
  86. turtle.select(i)
  87. turtle.dropDown()
  88. end
  89. turtle.select(16)
  90. turtle.digDown()
  91. sleep(0.1)
  92. turtle.select(1)
  93. turtle.down()
  94. end
  95.  
  96. function mineLayer()
  97. local spiralCount = spiralSize
  98. for i=1,spiralSize do
  99. for j=1,4 do
  100. for k=1,spiralCount do
  101. while not turtle.forward() do turtle.dig() end
  102. end
  103. turtle.turnRight()
  104. checkInv()
  105. end
  106. spiralCount = spiralCount - 2
  107. turtle.turnRight()
  108. turtle.forward()
  109. turtle.turnLeft()
  110. end
  111. end
  112.  
  113. returnStart()
  114. for l=bottom,args[2] do
  115. mineLayer()
  116. while turtle.detectDown() do
  117. turtle.digDown()
  118. end
  119. turtle.down()
  120. end
  121. emptyInv()
Advertisement
Add Comment
Please, Sign In to add comment