Advertisement
Nokiyen

flatMining3

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