Advertisement
ceribia

straight

Jun 17th, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.40 KB | None | 0 0
  1. local fuel = {}
  2. fuel['chest'] = 1
  3. fuel['material'] = 2
  4.  
  5. local fill = {}
  6. fill['chest'] = 3
  7. fill['material'] = 4
  8.  
  9. local loot = {}
  10. loot['chest'] = 5
  11. loot['material'] = 6
  12. loot['lastItem'] = true
  13.  
  14. local firstSlot = 6
  15.  
  16. local function placeChest(item)
  17. turtle.turnLeft()
  18. turtle.turnLeft()
  19.  
  20. if turtle.detect() then
  21. error("Block behind us")
  22. end
  23.  
  24. turtle.select(item.chest)
  25.  
  26. if turtle.place() == false then
  27. error("Failed to place chest from slot " .. item.chest)
  28. end
  29. end
  30.  
  31. local function getChest(item)
  32. turtle.select(item.chest)
  33.  
  34. if turtle.dig() == false then
  35. error("Failed to retreive chest to slot " .. item.chest)
  36. end
  37.  
  38. turtle.turnLeft()
  39. turtle.turnLeft()
  40. end
  41.  
  42. local function unload(item)
  43. placeChest(item)
  44.  
  45. if item.lastItem then
  46. for n=item.material,16 do
  47. turtle.select(n)
  48. turtle.drop()
  49. end
  50. else
  51. turtle.select(item.material)
  52. turtle.drop()
  53. end
  54.  
  55. getChest(item)
  56. end
  57.  
  58. local function reload(item)
  59. placeChest(item)
  60.  
  61. turtle.select(item.material)
  62. while turtle.getItemSpace() > 0 do
  63. if turtle.suck(turtle.getItemSpace()) == false then
  64. error("Couldn't get an item for slot " .. item.material)
  65. end
  66. end
  67.  
  68. getChest(item)
  69. end
  70.  
  71. local function refuel(item, fuelLimit)
  72. if fuelLimit == nil then
  73. fuelLimit = turtle.getFuelLimit()
  74. end
  75.  
  76. while turtle.getFuelLevel() < fuelLimit do
  77. turtle.select(item.material)
  78. if turtle.getItemCount() > 1 then
  79. turtle.refuel(turtle.getItemCount() - 1)
  80. else
  81. reload(item)
  82. end
  83. end
  84. end
  85.  
  86. local Item = {}
  87. Item["detect"] = {}
  88. Item["detect"]["forward"] = turtle.detect
  89. Item["detect"]["left"] = turtle.detect
  90. Item["detect"]["right"] = turtle.detect
  91. Item["detect"]["up"] = turtle.detectUp
  92. Item["detect"]["down"] = turtle.detectDown
  93. Item["place"] = {}
  94. Item["place"]["forward"] = turtle.place
  95. Item["place"]["left"] = turtle.place
  96. Item["place"]["right"] = turtle.place
  97. Item["place"]["up"] = turtle.placeUp
  98. Item["place"]["down"] = turtle.placeDown
  99. local function place(item, direction)
  100. turtle.select(item.material)
  101. if turtle.getItemCount() <= 1 then
  102. reload(item)
  103. end
  104.  
  105. if direction == "left" then
  106. turtle.turnLeft()
  107. elseif direction == "right" then
  108. turtle.turnRight()
  109. end
  110.  
  111. if Item["detect"][direction]() == false then
  112. if Item["place"][direction]() == false then
  113. error("Failed to place an item from slot " .. item.material)
  114. end
  115. end
  116.  
  117. if direction == "left" then
  118. turtle.turnRight()
  119. elseif direction == "right" then
  120. turtle.turnLeft()
  121. end
  122. end
  123.  
  124. local function isFull()
  125. for n=firstSlot,16 do
  126. if turtle.getItemCount(n) == 0 then
  127. --Empty slots
  128. return false;
  129. end
  130. end
  131. print( "No empty slots left." )
  132. return true;
  133. end
  134.  
  135. local function forwards()
  136. if turtle.getFuelLimit() ~= 0 and turtle.getFuelLevel() < 10000 then
  137. refuel(fuel, 20000)
  138. end
  139.  
  140. if isFull() then
  141. unload(loot)
  142. end
  143.  
  144. turtle.select(loot.material)
  145. while not turtle.forward() do
  146. if not turtle.dig() then
  147. if turtle.attack() then
  148. -- Do Nothing
  149. else
  150. sleep( 0.5 )
  151. end
  152. end
  153. end
  154. return true
  155. end
  156.  
  157. -----------------------------------------------------------------------------
  158. --Main Program
  159. -----------------------------------------------------------------------------
  160. local tArgs = { ... }
  161. if #tArgs < 1 then
  162. print( "My Version Usage: straight length [number]" )
  163. return
  164. end
  165.  
  166. local length = tonumber( tArgs[1] )
  167. local turtleNumber
  168. if tArgs[2] ~= nil then
  169. turtleNumber = tonumber( tArgs[2] )
  170. else
  171. turtle = tonumber( os.getComputerLabel() )
  172. end
  173.  
  174. print( "Tunneling..." )
  175. reload(fuel)
  176. reload(fill)
  177.  
  178. --Tunnel forward filling in the edge
  179. for tunnelLength=1,length do
  180. print("Mining " .. tunnelLength .. " / " .. length)
  181.  
  182. forwards()
  183.  
  184. --Fill your edge
  185. if turtleNumber == 1 then
  186. place(fill, "up")
  187. place(fill, "left")
  188. elseif turtleNumber == 2 then
  189. place(fill, "up")
  190. elseif turtleNumber == 3 then
  191. place(fill, "up")
  192. place(fill, "right")
  193. elseif turtleNumber == 4 then
  194. place(fill, "left")
  195. elseif turtleNumber == 5 then
  196. -- Place Nothing
  197. elseif turtleNumber == 6 then
  198. place(fill, "right")
  199. elseif turtleNumber == 7 then
  200. place(fill, "down")
  201. place(fill, "left")
  202. elseif turtleNumber == 8 then
  203. place(fill, "down")
  204. elseif turtleNumber == 9 then
  205. place(fill, "right")
  206. place(fill, "down")
  207. end
  208. end
  209.  
  210. print( "Emptying" )
  211. unload(fuel)
  212. unload(fill)
  213. unload(loot)
  214.  
  215. print( "Done" )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement