jseely

mineshaft

Nov 17th, 2012
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.81 KB | None | 0 0
  1. module(...)
  2.  
  3. local U = require "utils"
  4. local T = require "turtle"
  5. local mT = require "miningTurtle"
  6.  
  7. local wood = {}
  8. local nextColDir = "up"
  9. local nextRowDir = "right"
  10.  
  11. function digTunnel(length)
  12. for i = 1, length, 1 do
  13. for k = 1, 4, 1 do
  14. if not digSide(nextColDir) then
  15. return false
  16. end
  17. mT.invFull("back", 2)
  18. nextColDir = T.swapColDir(nextColDir)
  19. T.turn(nextRowDir)
  20. nextRowDir = T.swapRowDir(nextRowDir)
  21. for j = 1, 3, 1 do
  22. if not digCenter(nextColDir) then
  23. return false
  24. end
  25. mT.invFull("back", 2)
  26. nextColDir = T.swapColDir(nextColDir)
  27. end
  28. if not digSide(nextColDir) then
  29. return false
  30. end
  31. mT.invFull("back", 2)
  32. nextColDir = T.swapColDir(nextColDir)
  33. T.turn(nextRowDir)
  34. end
  35. if not addSupports() then
  36. return false
  37. end
  38. mT.invFull(nextRowDir, 2)
  39. end
  40. return true
  41. end
  42.  
  43. function addSupports()
  44. T.turn(nextRowDir)
  45. mT.forward()
  46. T.turn(nextRowDir)
  47. mT.forward()
  48. T.turn(nextRowDir)
  49. if not placeBeams(nextColDir) then
  50. return false
  51. end
  52. nextColDir = T.swapColDir(nextColDir)
  53. T.turn(nextRowDir)
  54. T.turn(nextRowDir)
  55. nextRowDir = T.swapRowDir(nextRowDir)
  56. mT.forward()
  57. if nextColDir == "up" then
  58. mT.digDown()
  59. if not placeWood("down") then
  60. return false
  61. end
  62. mT.up()
  63. mT.up()
  64. if not placeWood("up") then
  65. return false
  66. end
  67. elseif nextColDir == "down" then
  68. if not placeWood("up") then
  69. return false
  70. end
  71. mT.down()
  72. mT.down()
  73. mT.digDown()
  74. if not placeWood("down") then
  75. return false
  76. end
  77. end
  78. nextColDir = T.swapColDir(nextColDir)
  79. mT.forward()
  80. if not placeBeams(nextColDir) then
  81. return false
  82. end
  83. nextColDir = T.swapColDir(nextColDir)
  84. T.turn(nextRowDir)
  85. nextRowDir = T.swapRowDir(nextRowDir)
  86. mT.forward()
  87. T.turn(nextRowDir)
  88. mT.forward()
  89. nextRowDir = T.swapRowDir(nextRowDir)
  90. T.turn(nextRowDir)
  91. return true
  92. end
  93.  
  94. function placeBeams(direction)
  95. success = true
  96. if direction == "up" then
  97. mT.digDown()
  98. sucess = placeWood("down")
  99. sucess = placeWood("front")
  100. mT.up()
  101. sucess = placeWood("front")
  102. mT.up()
  103. sucess = placeWood("front")
  104. sucess = placeWood("up")
  105. elseif direction == "down" then
  106. sucess = placeWood("up")
  107. sucess = placeWood("front")
  108. mT.down()
  109. sucess = placeWood("front")
  110. mT.down()
  111. mT.digDown()
  112. sucess = placeWood("front")
  113. sucess = placeWood("down")
  114. end
  115. return success
  116. end
  117.  
  118. function digSide(direction)
  119. local success = true
  120. mT.dig()
  121. mT.forward()
  122. if direction == "up" then
  123. mT.digDown()
  124. success = placeWood("down")
  125. for i = 1, 2, 1 do
  126. mT.digUp()
  127. mT.up()
  128. end
  129. mT.digUp()
  130. success = placeWood("up")
  131. else
  132. mT.digUp()
  133. success = placeWood("up")
  134. for i = 1, 2, 1 do
  135. mT.digDown()
  136. mT.down()
  137. end
  138. mT.digDown()
  139. success = placeWood("down")
  140. end
  141. return success
  142. end
  143.  
  144. function digCenter(direction)
  145. local success = true
  146. mT.dig()
  147. mT.forward()
  148. if direction == "up" then
  149. mT.digUp()
  150. mT.up()
  151. mT.digUp()
  152. mT.up()
  153. mT.digUp()
  154. else
  155. mT.digUp()
  156. for i = 1, 2, 1 do
  157. mT.digDown()
  158. mT.down()
  159. end
  160. end
  161. return success
  162. end
  163.  
  164. function placeWood(dir)
  165. hasWood = true
  166. if (wood == nil) or (U.sum(wood) == 0) then
  167. hasWood = findWood()
  168. end
  169. if not hasWood then
  170. return false
  171. end
  172.  
  173. woodSlot = 1
  174. for i = 1, 14, 1 do
  175. if wood[i] > 0 then
  176. woodSlot = i
  177. end
  178. end
  179. turtle.select(woodSlot)
  180. success = true
  181. if dir == "front" then
  182. success = turtle.place()
  183. elseif dir == "up" then
  184. success = turtle.placeUp()
  185. elseif dir == "down" then
  186. success = turtle.placeDown()
  187. end
  188. wood[woodSlot] = turtle.getItemCount(woodSlot)
  189. return success
  190. end
  191.  
  192. function findWood()
  193. for i = 1, 14, 1 do
  194. turtle.select(i)
  195. wood[i] = turtle.getItemCount(i)
  196. end
  197. if not (U.sum(wood) == 0) then
  198. return true
  199. else
  200. return false
  201. end
  202. end
Advertisement
Add Comment
Please, Sign In to add comment