Advertisement
tahg

dig

May 15th, 2013
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.03 KB | None | 0 0
  1. local args = {...}
  2. if #args < 2 then return end
  3. os.loadAPI("utils")
  4. local maxX, maxZ = 0 + args[1], 0 + args[2]
  5. local count
  6. local curX, curZ = turtle.x, turtle.z
  7. local curY = turtle.y
  8. for i = 1,16 do
  9. if turtle.getItemCount(i) == 0 then
  10. count = i - 1
  11. break
  12. end
  13. end
  14.  
  15. local function suck()
  16. while turtle.suck() do end
  17. turtle.dig()
  18. end
  19.  
  20. local function suckDown()
  21. while turtle.suckDown() do end
  22. turtle.digDown()
  23. end
  24.  
  25. local function suckUp()
  26. while turtle.suckUp() do end
  27. turtle.digUp()
  28. end
  29.  
  30. local function matches(func)
  31. if not count then return false end
  32. for i = 1, count do
  33. turtle.select(i)
  34. if func() then return true end
  35. end
  36. return false
  37. end
  38.  
  39. local function tunnel(x)
  40. local func, func2, func3
  41. for j = 1, 2 do
  42. if j == 1 then
  43. func = turtle.compareUp
  44. func2 = suckUp
  45. else
  46. func = turtle.compareDown
  47. func2 = suckDown
  48. end
  49. for i = 1, x do
  50. turtle.select(count + 1)
  51. turtle.turnLeft()
  52. if not matches(turtle.compare) then
  53. suck()
  54. end
  55. turtle.turnRight()
  56. turtle.turnRight()
  57. if not matches(turtle.compare) then
  58. suck()
  59. end
  60. turtle.turnLeft()
  61. if not matches(func) then
  62. func2()
  63. end
  64. if i ~= x then
  65. suck()
  66. if not utils.forward() then return false end
  67. end
  68. end
  69. turtle.turnLeft()
  70. turtle.turnLeft()
  71. if j == 1 then
  72. turtle.digDown()
  73. turtle.down()
  74. else
  75. turtle.digUp()
  76. turtle.up()
  77. end
  78. end
  79. return true
  80. end
  81.  
  82. while true do
  83. for z = curY % 4, maxZ - 1, 4 do
  84. while turtle.getFuelLevel() < 2 * (maxZ + maxZ - curY + 25) do
  85. os.sleep(1)
  86. end
  87. if not utils.goto(0, curY, z) then
  88. utils.goto(0, 0, 0)
  89. return
  90. end
  91. turtle.rotate(1, 0)
  92. if not tunnel(maxX) then return end
  93. utils.goto(0, 0, 0)
  94. turtle.rotate(-1, 0)
  95. for i = count + 1, 16 do
  96. turtle.select(i)
  97. turtle.drop()
  98. end
  99. end
  100. curY = curY - 2
  101. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement