Advertisement
Guest User

Untitled

a guest
Mar 29th, 2020
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.84 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. end
  36.  
  37. function branch(size, names)
  38. for i=1,size do
  39. turtle.dig()
  40. turtle.forward()
  41. turtle.turnLeft()
  42. local success, data = turtle.inspect()
  43. if success then
  44. if table.contains(names, data.name) then
  45. turtle.dig()
  46. end
  47. end
  48. turtle.turnRight()
  49. turtle.turnRight()
  50. local success, data = turtle.inspect()
  51. if success then
  52. if table.contains(names, data.name) then
  53. turtle.dig()
  54. end
  55. end
  56. turtle.turnLeft()
  57. local success, data = turtle.inspectUp()
  58. if success then
  59. if table.contains(names, data.name) then
  60. turtle.digUp()
  61. end
  62. end
  63. local success, data = turtle.inspectDown()
  64. if success then
  65. if table.contains(names, data.name) then
  66. turtle.digDown()
  67. end
  68. end
  69. end
  70. turtle.turnLeft()
  71. turtle.turnLeft()
  72. for i = 1, size do
  73. turtle.dig()
  74. turtle.forward()
  75. end
  76. turtle.turnLeft()
  77. turtle.turnLeft()
  78. end
  79.  
  80. function getFuel( walked )
  81. turtle.turnLeft()
  82. turtle.turnLeft()
  83. for i=1, walked do
  84. turtle.dig()
  85. turtle.forward()
  86. end
  87. turtle.select(16)
  88.  
  89. local refueled = false
  90. while not refueled do
  91. if turtle.getItemDetail() == nil then
  92. turtle.suck()
  93. turtle.refuel()
  94. if turtle.getFuelLevel() == turtle.getFuelLimit() then
  95. turtle.drop()
  96. refueled = true
  97. end
  98. end
  99. end
  100. turtle.turnLeft()
  101. turtle.turnLeft()
  102. for i=1, walked do
  103. turtle.dig()
  104. turtle.forward()
  105. end
  106.  
  107. end
  108.  
  109. function lowFuel(walked, width)
  110. if turtle.getFuelLevel() < walked*3 + 2*3 + 2*width then
  111. getFuel(walked)
  112. end
  113. end
  114.  
  115. function branchMine(length, width, names)
  116. for i=1,length do
  117. turtle.dig()
  118. turtle.forward()
  119. turtle.dig()
  120. turtle.forward()
  121. turtle.dig()
  122. turtle.forward()
  123.  
  124. turtle.turnLeft()
  125. branch(width, names)
  126. turtle.turnRight()
  127. turtle.turnRight()
  128. branch(width, names)
  129. turtle.turnLeft()
  130.  
  131. lowFuel()
  132. end
  133.  
  134. turtle.turnRight()
  135. turtle.turnRight()
  136.  
  137. for i=1,length do
  138. turtle.dig()
  139. turtle.forward()
  140. turtle.dig()
  141. turtle.forward()
  142. turtle.dig()
  143. turtle.forward()
  144. end
  145.  
  146. turtle.turnRight()
  147. turtle.turnRight()
  148.  
  149. end
  150.  
  151.  
  152. print("Starting branch of "..length.." length, "..width.." width.")
  153. branchMine(length, width, names)
  154. print("Finished")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement