Advertisement
Pokruk

digger

Dec 15th, 2023 (edited)
10
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.00 KB | None | 0 0
  1.  
  2.  
  3. function hasAnyTag(str, tags)
  4. for _, tag in ipairs(tags) do
  5. if string.find(str, tag) ~= nil then
  6. return true
  7. end
  8. end
  9. return false
  10. end
  11.  
  12. function isBlock(itemName)
  13. local blockTags = {"cobblestone"}
  14. return hasAnyTag(itemName, blockTags)
  15. end
  16.  
  17. function isValuable(itemName)
  18. return hasAnyTag(itemName, {"diamond", "gold", "emerald", "iron"})
  19. end
  20. function setToNotValuableBlockSlot()
  21. for i = 1, 16 do
  22. local itemName = turtle.getItemDetail(i).name
  23. if not isValuable(itemName) and isBlock(itemName) then
  24. turtle.select(i)
  25. return true
  26. end
  27. end
  28. return false
  29. end
  30.  
  31. function moveInSpiral(targetSize, toOutside, callback)
  32. local function moveForward(n)
  33. for _ = 1, n do
  34. turtle.forward()
  35. callback()
  36. end
  37. end
  38.  
  39. moveForward(targetSize)
  40. turtle.turnLeft()
  41. for i = targetSize - 1, 1, -1 do
  42. for _ = 1, 2 do
  43. moveForward(i)
  44. turtle.turnLeft()
  45. end
  46. end
  47. end
  48.  
  49. function moveZig(forward, left, callback)
  50. local function moveForward(n)
  51. for _ = 1, n do
  52. callback()
  53. turtle.forward()
  54. end
  55. end
  56. callback()
  57. for i = 1, left-1 do
  58. local even = i % 2 == 0
  59. moveForward(forward-1)
  60. if not even then
  61. turtle.turnLeft()
  62. else
  63. turtle.turnRight()
  64. end
  65. moveForward(1)
  66. if not even then
  67. turtle.turnLeft()
  68. else
  69. turtle.turnRight()
  70. end
  71. end
  72. moveForward(forward-1)
  73.  
  74. end
  75.  
  76. function repeatFunc(callback, n)
  77. for i = 1, n do
  78. callback()
  79. end
  80. end
  81.  
  82. function move(direction, n)
  83. local moveFunc
  84. if "forward" then
  85. moveFunc = turtle.forward
  86. elseif "down" then
  87. moveFunc = turtle.down
  88. elseif "up" then
  89. moveFunc = turtle.up
  90. end
  91.  
  92. for i = 1, n do
  93. moveFunc()
  94. end
  95. end
  96.  
  97. local width = tonumber(arg[1]) or 4
  98. local length = tonumber(arg[2]) or 4
  99. local height = tonumber(arg[3]) or 4
  100.  
  101. if height < 2 then
  102. error("2 is height minimum")
  103. end
  104. if turtle.inspectUp() then
  105. turtle.digUp()
  106. end
  107. turtle.up()
  108. for i = 1, height - 1 do
  109. local width = tonumber(width)
  110. moveZig(tonumber(length), width, function()
  111. if turtle.inspect() then
  112. while turtle.dig() do end
  113. end
  114. turtle.digDown()
  115. end)
  116. if width % 2 == 0 then
  117. turtle.turnLeft()
  118. else
  119. turtle.turnLeft()
  120. turtle.turnLeft()
  121. end
  122. if i == 1 then
  123. turtle.digDown()
  124. end
  125. local isLast = i == height - 1
  126. if not isLast then
  127. if turtle.inspectUp() then
  128. turtle.digUp()
  129. end
  130. turtle.up()
  131. else
  132. repeatFunc(turtle.down, height)
  133. repeatFunc(turtle.forward, length)
  134. turtle.turnLeft()
  135. repeatFunc(turtle.forward, width)
  136. turtle.turnLeft()
  137. end
  138. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement