Advertisement
Nokiyen

flatMining4

May 30th, 2014
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.04 KB | None | 0 0
  1. --[[
  2. ***********
  3. * flatMining
  4. *
  5. * mine in shape of a flat space.
  6. * slot1~5 = ore
  7. * slot6 = chest, slot7,8 = torch *
  8. * slot9 = ironOre, slot10 = goldOre
  9. *
  10. **********
  11. ]]
  12.  
  13.  
  14.  
  15. -- get arguments.
  16. local tArgs = { ... }
  17. -- define vars.
  18. local depth = tArgs[1]
  19. local width = tArgs[2]
  20. local height = tArgs[3]
  21. local side = 16
  22. local oreSlot1 = 1
  23. local oreSlot2 = 2
  24. local oreSlot3 = 3
  25. local oreSlot4 = 4
  26. local oreSlot5 = 5
  27. local ironSlot = 6
  28. local goldSlot = 7
  29. local chestSlot = 8
  30. local torchSlot1 = 9
  31. local torchSlot2 = 10
  32. local torchSlot3 = 11
  33. local torchSlot4 = 12
  34.  
  35.  
  36. --define functions.
  37. function mineStraight(line, floor)
  38.  
  39. local residue = depth*side-2
  40. local height = 1
  41.  
  42. while residue > 0 do
  43. if compare('down') then
  44. dig('down')
  45. end
  46. if compare('up') then
  47. dig('up')
  48. end
  49. drop()
  50. if floor == 1 then
  51. torch(line, residue)
  52. end
  53. if turtle.detect() == false then
  54. move('front')
  55. residue = residue - 1
  56. elseif compare('front') then
  57. dig('front')
  58. move('front')
  59. residue = residue - 1
  60. else
  61. dig('up')
  62. move('up')
  63. height = height + 1
  64. residue, height = detour(residue, height)
  65. end
  66. end
  67.  
  68. while height > 1 do
  69. dig('down')
  70. move('down')
  71. height = height - 1
  72. end
  73.  
  74. if compare('down') then
  75. dig('down')
  76. end
  77. if compare('up') then
  78. dig('up')
  79. end
  80.  
  81. dig('front')
  82. move('front')
  83.  
  84. end
  85.  
  86. function compare(dir)
  87.  
  88. local currentFunc = turtle.compare
  89. if dir == 'up' then
  90. currentFunc = turtle.compareUp
  91. elseif dir == 'down' then
  92. currentFunc = turtle.compareDown
  93. end
  94.  
  95. local flag = false
  96.  
  97. turtle.select(oreSlot1)
  98. flag = currentFunc()
  99. if flag == false then
  100. turtle.select(oreSlot2)
  101. flag = currentFunc()
  102. end
  103. if flag == false then
  104. turtle.select(oreSlot3)
  105. flag = currentFunc()
  106. end
  107. if flag == false then
  108. turtle.select(oreSlot4)
  109. flag = currentFunc()
  110. end
  111. if flag == false then
  112. turtle.select(oreSlot5)
  113. flag = currentFunc()
  114. end
  115. if flag == false then
  116. turtle.select(chestSlot)
  117. flag = currentFunc()
  118. end
  119. turtle.select(1)
  120.  
  121. if flag == true then
  122. return false
  123. else
  124. return true
  125. end
  126.  
  127. end
  128.  
  129. function detour(residue, height)
  130.  
  131. while compare('front') == false and turtle.detect() == true do
  132. dig('up')
  133. move('up')
  134. height = height + 1
  135. end
  136. dig('front')
  137. move('front')
  138. residue = residue -1
  139.  
  140. if residue == 0 then
  141. return residue, height
  142. end
  143.  
  144. while height > 1 do
  145. if compare('front') == false and turtle.detect() == true then
  146. while compare('front') == false and turtle.detect() == true do
  147. dig('up')
  148. move('up')
  149. height = height + 1
  150. end
  151. dig('front')
  152. move('front')
  153. residue = residue - 1
  154. elseif compare('front') or turtle.detect() == false then
  155. dig('front')
  156. move('front')
  157. residue = residue - 1
  158. while compare('down') or turtle.detectDown() == false do
  159. dig('down')
  160. move('down')
  161. height = height - 1
  162. if height == 1 then
  163. return residue, height
  164. end
  165. end
  166. end
  167.  
  168. if residue == 0 then
  169. return residue, height
  170. end
  171. end
  172. return residue, height
  173.  
  174. end
  175.  
  176. function turn(dir)
  177.  
  178. if compare('down') then
  179. dig('down')
  180. end
  181. if compare('up') then
  182. dig('up')
  183. end
  184.  
  185. local currentFunc
  186. if dir%2 == 0 then
  187. currentFunc = turtle.turnLeft
  188. else
  189. currentFunc = turtle.turnRight
  190. end
  191.  
  192. currentFunc()
  193. dig('front')
  194. move('front')
  195. currentFunc()
  196.  
  197. end
  198.  
  199. function isFull()
  200.  
  201. for i=10, 16, 1 do
  202. if turtle.getItemCount(i) == 0 then
  203. return false
  204. end
  205. end
  206. return true
  207.  
  208. end
  209.  
  210. function drop()
  211.  
  212. if isFull() then
  213. for i=10, 12, 1 do
  214. turtle.select(i)
  215. if turtle.compareTo(ironSlot) == false and turtle.compareTo(goldSlot) == false and turtle.compareTo(torchSlot1) == false then
  216. turtle.drop()
  217. end
  218. end
  219. for i=13, 16, 1 do
  220. turtle.select(i)
  221. if turtle.compareTo(ironSlot) == false and turtle.compareTo(goldSlot) == false then
  222. turtle.drop()
  223. end
  224. end
  225. end
  226. if isFull() then
  227. turtle.select(chestSlot)
  228. if turtle.placeDown() then
  229. turtle.select(ironSlot)
  230. turtle.dropDown(turtle.getItemCount(ironSlot)-1)
  231. turtle.select(goldSlot)
  232. turtle.dropDown(turtle.getItemCount(goldSlot)-1)
  233. for i=10, 12, 1 do
  234. turtle.select(i)
  235. if turtle.compareTo(torchSlot1) == false then
  236. turtle.dropDown()
  237. end
  238. end
  239. for i=13, 16, 1 do
  240. turtle.select(i)
  241. turtle.dropDown()
  242. end
  243. end
  244. end
  245. turtle.select(1)
  246.  
  247. end
  248.  
  249. function dig(dir)
  250.  
  251. local currentDig = turtle.dig
  252. local currentDetect = turtle.detect
  253. if dir == 'up' then
  254. currentDig = turtle.digUp
  255. currentDetect = turtle.detectUp
  256. elseif dir == 'down' then
  257. currentDig = turtle.digDown
  258. currentDetect = turtle.detectDown
  259. end
  260.  
  261. local times = 0
  262. while currentDetect() do
  263. currentDig()
  264. times = times + 1
  265. if times == 15 then
  266. break
  267. end
  268. sleep(1)
  269. end
  270.  
  271. end
  272.  
  273. function move(dir)
  274.  
  275. local currentMove = turtle.forward
  276. local currentAttack = turtle.attack
  277. if dir == 'up' then
  278. currentMove = turtle.up
  279. currentAttack = turtle.attackUp
  280. elseif dir == 'down' then
  281. currentMove = turtle.down
  282. currentAttack = turtle.attackDown
  283. end
  284.  
  285. local times = 0
  286. while currentMove() == false do
  287. currentAttack()
  288. times = times + 1
  289. if times == 15 then
  290. return false
  291. end
  292. end
  293. return true
  294.  
  295. end
  296.  
  297. function torch(line, residue)
  298.  
  299. if (line-3)%7 ~= 0 or residue%7 ~= 0 then
  300. return
  301. end
  302.  
  303. if turtle.getItemCount(torchSlot1) == 1 then
  304. return
  305. end
  306.  
  307. turtle.select(torchSlot1)
  308. if turtle.compareTo(torchSlot4) then
  309. turtle.select(torchSlot4)
  310. elseif turtle.compareTo(torchSlot3) then
  311. turtle.select(torchSlot3)
  312. elseif turtle.compareTo(torchSlot2) then
  313. turtle.select(torchSlot2)
  314. end
  315. turtle.placeDown()
  316. turtle.select(1)
  317.  
  318. end
  319.  
  320.  
  321. --main thread
  322. for j=1, height, 1 do
  323. for i=1, width*side-1, 1 do
  324. print('start line'..i..'.')
  325. mineStraight(i)
  326. turn(i+1 + (j-1)%2)
  327. end
  328. mineStraight(depth*side, j)
  329. dig('up')
  330. dig('down')
  331. turtle.turnLeft()
  332. turtle.turnLeft()
  333. if j ~= height then
  334. dig('up')
  335. move('up')
  336. dig('up')
  337. move('up')
  338. dig('up')
  339. move('up')
  340. end
  341. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement