edoreld

Untitled

Oct 31st, 2012
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.15 KB | None | 0 0
  1. local tArgs = {...}
  2. local areasToMine = tonumber(tArgs[1])
  3.  
  4. if #tArgs < 1 then
  5. areasToMine = 1
  6. print(" Defaulting to 1 areas to mine")
  7.  
  8. -- Slot Variables
  9. lastMiningSlot = 11
  10. numberOfMiningSlots = lastMiningSlot
  11.  
  12. torchSlot = 12
  13. anchorSlot = 13
  14. chestSlot = 14
  15. outputSlot = 15
  16. fuelChestSlot = 16
  17.  
  18. -- Mining Variables
  19. layer = 0
  20. line = 0
  21.  
  22. -- Inventory variables
  23. room = 0
  24.  
  25. function fuel()
  26. if turtle.getFuelLevel() < 1000 then
  27. -- Deposit inventory contents in the chest
  28. turtle.digDown()
  29. turtle.select(chestSlot)
  30. turtle.placeDown()
  31. turtle.select(lastMiningSlot)
  32. turtle.dropDown()
  33. --
  34.  
  35. -- Use fuel from fuel Chest
  36. turtle.digUp()
  37. turtle.select(fuelChestSlot)
  38. turtle.placeUp()
  39. turtle.suckUp()
  40. turtle.refuel()
  41. turtle.digUp()
  42. --
  43.  
  44. -- Retrieve chest & its contents
  45. turtle.select(lastMiningSlot)
  46. turtle.suckDown()
  47. turtle.digDown()
  48. --
  49.  
  50. turtle.select(1)
  51. end
  52. end
  53.  
  54. function empty()
  55. turtle.digUp()
  56. turtle.select(outputSlot)
  57. turtle.placeUp()
  58. for i = 1,numberOfMiningSlots do
  59. turtle.select(i)
  60. turtle.dropUp()
  61. end
  62. turtle.select(outputSlot)
  63. turtle.digUp()
  64. turtle.select(1)
  65. end
  66.  
  67. function inv()
  68. for i = 1,numberOfMiningSlots do
  69. if turtle.getItemCount(i) == 0 then
  70. room = room + 1
  71. end
  72. end
  73.  
  74. if room == 0 then
  75. empty()
  76. else
  77. room = 0
  78. end
  79. end
  80.  
  81.  
  82.  
  83. function forward()
  84. while not turtle.forward() do
  85. inv()
  86. if not turtle.dig() then
  87. turtle.attack()
  88. end
  89. end
  90. end
  91.  
  92. function up()
  93. while not turtle.up() do
  94. inv()
  95. turtle.digUp()
  96. end
  97. end
  98.  
  99. function down()
  100. while not turtle.down() do
  101. inv()
  102. turtle.digDown()
  103. end
  104. end
  105.  
  106. function updown()
  107. inv()
  108. turtle.digUp()
  109. inv()
  110. turtle.digDown()
  111. end
  112.  
  113. function turnLeft()
  114. turtle.turnLeft()
  115. forward()
  116. turtle.turnLeft()
  117. end
  118.  
  119. function turnRight()
  120. turtle.turnRight()
  121. forward()
  122. turtle.turnRight()
  123. end
  124.  
  125. function moveToChunkAbove()
  126. for i=1,3 do
  127. up()
  128. end
  129. layer = layer + 1
  130. end
  131.  
  132. function moveToChunkBelow()
  133. for i=1,3 do
  134. down()
  135. end
  136. layer = layer - 1
  137. end
  138.  
  139. function moveToChunkRight()
  140. for i=1,5 do
  141. forward()
  142. end
  143. turtle.turnRight()
  144. forward()
  145. turtle.turnRight()
  146. line = line + 1
  147. end
  148.  
  149. function moveToChunkLeft()
  150. for i=1,2 do
  151. turtle.turnLeft()
  152. end
  153. forward()
  154. turtle.turnLeft()
  155. forward()
  156. turtle.turnRight()
  157. line = line + 1
  158. end
  159.  
  160. function returnToOrigin()
  161. for i=1,2 do
  162. turtle.turnLeft()
  163. end
  164. for i=1,6 do
  165. forward()
  166. end
  167. turtle.turnLeft()
  168. for i=1,12 do
  169. forward()
  170. end
  171. turtle.turnLeft()
  172. line = 0
  173. end
  174.  
  175. function placeTorch()
  176. turtle.digDown()
  177. turtle.select(torchSlot)
  178. turtle.placeDown()
  179. turtle.select(1)
  180. end
  181.  
  182. function mineLine()
  183. updown()
  184. for i=1,2 do
  185. forward()
  186. updown()
  187. end
  188. end
  189.  
  190. function mineChunk()
  191. torchPlaced = 0
  192. for i=1,2 do
  193. mineLine()
  194. if torchPlaced == 0 and layer == 0 and line % 2 == 0 then
  195. placeTorch()
  196. torchPlaced = 1
  197. end
  198. turnLeft()
  199. mineLine()
  200. if torchPlaced == 0 and layer == 0 and line % 2 ~= 0 then
  201. placeTorch()
  202. torchPlaced = 1
  203. turnRight()
  204. end
  205. end
  206.  
  207. function mineThickLine()
  208. for i=1,3 do
  209. mineChunk()
  210. end
  211. end
  212.  
  213. function mineLayer()
  214. if layer == 0 then
  215. setAnchor()
  216. end
  217. mineThickLine()
  218. if layer == 0 then
  219. setAnchor()
  220. end
  221. moveToChunkRight()
  222. mineThickLine()
  223. moveToChunkLeft()
  224. mineThickLine()
  225. returnToOrigin()
  226. end
  227.  
  228. function mineArea()
  229. for i=1,3 do
  230. mineLayer()
  231. moveToChunkAbove()
  232. end
  233. for i=1,9 do
  234. down()
  235. end
  236. end
  237.  
  238. function moveToNextArea()
  239. getAnchor()
  240. turtle.select(1)
  241. turtle.turnLeft()
  242. for i=1,12 do
  243. forward()
  244. end
  245. turtle.turnRight()
  246. end
  247.  
  248.  
  249. function setAnchor()
  250. turtle.turnRight()
  251. forward()
  252. turtle.select(anchorSlot)
  253. if not turtle.compareDown() then
  254. turtle.digDown()
  255. turtle.placeDown()
  256. turtle.select(1)
  257. end
  258. for i=1,2 do
  259. turtle.turnRight()
  260. end
  261. forward()
  262. turtle.turnRight()
  263. end
  264.  
  265. function getAnchor()
  266. turtle.turnRight()
  267. forward()
  268. turtle.select(anchorSlot)
  269. turtle.digDown()
  270. turtle.select(1)
  271. for i=1,2 do
  272. turtle.turnRight()
  273. end
  274. forward()
  275. turtle.turnRight()
  276. end
  277.  
  278. turtle.select(1)
  279. for i=1,areasToMine do
  280. fuel()
  281. mineArea()
  282. moveToNextArea()
  283. end
Advertisement
Add Comment
Please, Sign In to add comment