Advertisement
Nokiyen

flatMining3

May 25th, 2014
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.46 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, 16, 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. end
  206. if turtle.getItemCount(16) ~= 0 then
  207. turtle.select(chestSlot)
  208. if turtle.placeDown() then
  209. turtle.select(ironSlot)
  210. turtle.dropDown(turtle.getItemCount(ironSlot)-1)
  211. turtle.select(goldSlot)
  212. turtle.dropDown(turtle.getItemCount(goldSlot)-1)
  213. for i=10, 16, 1 do
  214. turtle.select(i)
  215. if turtle.compareTo(torchSlot1) == false then
  216. turtle.dropDown()
  217. end
  218. end
  219. end
  220. end
  221. turtle.select(1)
  222.  
  223. end
  224.  
  225. function dig(dir)
  226.  
  227. local currentDig = turtle.dig
  228. local currentDetect = turtle.detect
  229. if dir == 'up' then
  230. currentDig = turtle.digUp
  231. currentDetect = turtle.detectUp
  232. elseif dir == 'down' then
  233. currentDig = turtle.digDown
  234. currentDetect = turtle.detectDown
  235. end
  236.  
  237. local times = 0
  238. while currentDetect() do
  239. currentDig()
  240. times = times + 1
  241. if times == 15 then
  242. break
  243. end
  244. sleep(1)
  245. end
  246.  
  247. end
  248.  
  249. function move(dir)
  250.  
  251. local currentMove = turtle.forward
  252. local currentAttack = turtle.attack
  253. if dir == 'up' then
  254. currentMove = turtle.up
  255. currentAttack = turtle.attackUp
  256. elseif dir == 'down' then
  257. currentMove = turtle.down
  258. currentAttack = turtle.attackDown
  259. end
  260.  
  261. local times = 0
  262. while currentMove() == false do
  263. currentAttack()
  264. times = times + 1
  265. if times == 15 then
  266. return false
  267. end
  268. end
  269. return true
  270.  
  271. end
  272.  
  273. function torch(line, residue)
  274.  
  275. if (line-3)%7 ~= 0 or residue%7 ~= 0 then
  276. return
  277. end
  278.  
  279. if turtle.getItemCount(torchSlot1) == 1 then
  280. return
  281. end
  282.  
  283. turtle.select(torchSlot1)
  284. if turtle.compareTo(torchSlot4) then
  285. turtle.select(torchSlot4)
  286. elseif turtle.compareTo(torchSlot3) then
  287. turtle.select(torchSlot3)
  288. elseif turtle.compareTo(torchSlot2) then
  289. turtle.select(torchSlot2)
  290. end
  291. turtle.placeDown()
  292. turtle.select(1)
  293.  
  294. end
  295.  
  296.  
  297. --main thread.
  298. for i=1, width*side-1, 1 do
  299. print('start line'..i..'.')
  300. mineStraight(i)
  301. turn(i+1)
  302. end
  303. mineStraight(area*side)
  304. dig('up')
  305. dig('down')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement