Advertisement
Nokiyen

flatMining3

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