Advertisement
Guest User

Untitled

a guest
Mar 20th, 2019
313
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.88 KB | None | 0 0
  1. local blacklist = {
  2. ["minecraft:bedrock"] = true,
  3. ["minecraft:stone"] = true,
  4. ["minecraft:cobblestone"] = true,
  5. ["minecraft:dirt"] = true,
  6. ["minecraft:grass"] = true,
  7. ["minecraft:gravel"] = true,
  8. ["minecraft:sand"] = true,
  9. ["minecraft:water"] = true,
  10. ["minecraft:flowing_water"] = true,
  11. ["minecraft:lava"] = true,
  12. ["minecraft:flowing_lava"] = true
  13. }
  14.  
  15. local tArgs = {...}
  16. if #tArgs ~= 1 then
  17. print("Usage: ShaftMiner <distance>")
  18. return
  19. end
  20.  
  21. local length = tonumber(tArgs[1])
  22. local dist = 0
  23. local dir = 0
  24.  
  25. local function refuel()
  26. if turtle.getFuelLevel() < 100 then
  27. turtle.refuel(1)
  28. end
  29. end
  30.  
  31. local function turn(to)
  32. local rel = (to + 4 - dir) % 4
  33.  
  34. if rel == 1 then
  35. turtle.turnRight()
  36. elseif rel == 2 then
  37. turtle.turnRight()
  38. turtle.turnRight()
  39. elseif rel == 3 then
  40. turtle.turnLeft()
  41. end
  42.  
  43. dir = to
  44. end
  45.  
  46. local function reverse(to)
  47. if to < 4 then
  48. return (to + 2) % 4
  49. elseif to == 4 then
  50. return 5
  51. elseif to == 5 then
  52. return 4
  53. end
  54. end
  55.  
  56. local function trymove(to)
  57. refuel()
  58. if to < 4 then
  59. turn(to)
  60. return turtle.forward()
  61. elseif to == 4 then
  62. return turtle.up()
  63. elseif to == 5 then
  64. return turtle.down()
  65. end
  66. end
  67.  
  68. local function move(to)
  69. refuel()
  70. while not trymove(to) do end
  71. end
  72.  
  73. local function dig(to)
  74. refuel()
  75. if to < 4 then
  76. turn(to)
  77. turtle.dig()
  78. elseif to == 4 then
  79. turtle.digUp()
  80. elseif to == 5 then
  81. turtle.digDown()
  82. end
  83. end
  84.  
  85. local function moveDig(to)
  86. while not trymove(to) do dig(to) end
  87. end
  88.  
  89. local function inspect(to)
  90. refuel()
  91. if to < 4 then
  92. turn(to)
  93. return turtle.inspect()
  94. elseif to == 4 then
  95. return turtle.inspectUp()
  96. elseif to == 5 then
  97. return turtle.inspectDown()
  98. end
  99. end
  100.  
  101. local function unload()
  102. print("Unloading items...")
  103.  
  104. for n=2,16 do
  105. turtle.select(n)
  106. turtle.drop()
  107. end
  108.  
  109. turtle.select(1)
  110.  
  111. print("Unloaded!")
  112. end
  113.  
  114. local function checkFull()
  115. if turtle.getItemCount(16) > 0 then
  116. print("Inventory full, returning home...")
  117. return true
  118. else
  119. return false
  120. end
  121. end
  122.  
  123. local function dropoff()
  124. for n=1,dist do move(2) end
  125. unload()
  126. for n=1,dist do move(0) end
  127. end
  128.  
  129. local function mineVein()
  130. local n = 1
  131. local stack = {}
  132.  
  133. while n > 0 do
  134. local cur = (stack[n] or -1) + 1
  135. stack[n] = cur
  136. if cur < 6 then
  137. local success, data = inspect(cur)
  138. if success and not blacklist[data.name] then
  139. moveDig(cur)
  140. n = n + 1
  141. end
  142. else
  143. stack[n] = nil
  144. n = n - 1
  145. if n > 0 then moveDig(reverse(stack[n])) end
  146. end
  147. if checkFull() then
  148. for i=n-1,1,-1 do moveDig(reverse(stack[i])) end
  149. dropoff()
  150. for i=1,n-1 do moveDig(stack[i]) end
  151. end
  152. end
  153. end
  154.  
  155. while dist < length do
  156. moveDig(0)
  157. dist = dist + 1
  158. if checkFull() then dropoff() end
  159. mineVein()
  160. end
  161.  
  162. print("Finished shaft, returning home!")
  163.  
  164. for i=1,dist do move(2) end
  165. unload()
  166. turn(0)
  167.  
  168. print("Finished!")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement