edoreld

Miner

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