Advertisement
Guest User

Untitled

a guest
Mar 29th, 2020
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.86 KB | None | 0 0
  1. local tArgs = { ... }
  2.  
  3. if #tArgs < 3 then -- No size and name
  4. print( "Usage: branch <length> <width> <block_names>" )
  5. return
  6. end
  7.  
  8. local length = tonumber(tArgs[1])
  9. local width = tonumber(tArgs[2])
  10. local names = {}
  11. for i = 1, #tArgs - 2 do
  12. table.insert(names, tArgs[2+i])
  13. end
  14.  
  15. function table.contains(table, element)
  16. for _, value in pairs(table) do
  17. if value == element then
  18. return true
  19. end
  20. end
  21. return false
  22. end
  23.  
  24. function trash(names)
  25. for i = 1, 16 do
  26. turtle.select(i)
  27. local details = turtle.getItemDetail();
  28.  
  29. if details ~= nil then
  30. if not table.contains(names, details.name) then
  31. turtle.drop()
  32. end
  33. end
  34. end
  35.  
  36. function branch(size, names)
  37. for i=1,size do
  38. turtle.dig()
  39. turtle.forward()
  40. turtle.turnLeft()
  41. local success, data = turtle.inspect()
  42. if success then
  43. if table.contains(names, data.name) then
  44. turtle.dig()
  45. end
  46. end
  47. turtle.turnRight()
  48. turtle.turnRight()
  49. local success, data = turtle.inspect()
  50. if success then
  51. if table.contains(names, data.name) then
  52. turtle.dig()
  53. end
  54. end
  55. turtle.turnLeft()
  56. local success, data = turtle.inspectUp()
  57. if success then
  58. if table.contains(names, data.name) then
  59. turtle.digUp()
  60. end
  61. end
  62. local success, data = turtle.inspectDown()
  63. if success then
  64. if table.contains(names, data.name) then
  65. turtle.digDown()
  66. end
  67. end
  68. end
  69. turtle.turnLeft()
  70. turtle.turnLeft()
  71. for i = 1, size do
  72. turtle.dig()
  73. turtle.forward()
  74. end
  75. turtle.turnLeft()
  76. turtle.turnLeft()
  77. end
  78.  
  79. function getFuel( walked )
  80. turtle.turnLeft()
  81. turtle.turnLeft()
  82. for i=1, walked do
  83. turtle.dig()
  84. turtle.forward()
  85. end
  86. turtle.select(16)
  87.  
  88. local refueled = false
  89. while not refueled do
  90. if turtle.getItemDetail() == nil then
  91. turtle.suck()
  92. turtle.refuel()
  93. if turtle.getFuelLevel() == turtle.getFuelLimit() then
  94. turtle.drop()
  95. refueled = true
  96. end
  97. end
  98. end
  99. turtle.turnLeft()
  100. turtle.turnLeft()
  101. for i=1, walked do
  102. turtle.dig()
  103. turtle.forward()
  104. end
  105.  
  106. end
  107.  
  108. function lowFuel(walked, width)
  109. if turtle.getFuelLevel() < walked*3 + 2*3 + 2*width then
  110. getFuel(walked)
  111. end
  112. end
  113.  
  114. function branchMine(length, width, names)
  115. for i=1,length do
  116. turtle.dig()
  117. turtle.forward()
  118. turtle.dig()
  119. turtle.forward()
  120. turtle.dig()
  121. turtle.forward()
  122.  
  123. turtle.turnLeft()
  124. branch(width, names)
  125. turtle.turnRight()
  126. turtle.turnRight()
  127. branch(width, names)
  128. turtle.turnLeft()
  129.  
  130. lowFuel()
  131. end
  132.  
  133. turtle.turnRight()
  134. turtle.turnRight()
  135.  
  136. for i=1,length do
  137. turtle.dig()
  138. turtle.forward()
  139. turtle.dig()
  140. turtle.forward()
  141. turtle.dig()
  142. turtle.forward()
  143. end
  144.  
  145. turtle.turnRight()
  146. turtle.turnRight()
  147.  
  148. end
  149.  
  150.  
  151. print("Starting branch of "..length.." length, "..width.." width and mining all "..names..".")
  152. branchMine(length, width, name)
  153. print("Finished")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement