Advertisement
Steanly

Untitled

Jul 22nd, 2014
227
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.25 KB | None | 0 0
  1. --Variable Declarations
  2. local mainShaftDim = "2x2"
  3. local sideShaftDim = "2x1"
  4. local shaftFreq = "3"
  5. local totalCost = 0
  6. local input = ""
  7. local length = 0
  8. local currentPos = 1
  9. local chestDist = 0
  10. local doFuel = false
  11.  
  12. --Function Declarations
  13. function oreDetect()
  14. --[[ This function is a WIP system for the turtle to detect ores when it
  15. is mining and dig out the entire vein. It will do so by comparing items
  16. around it to specific slots in its inventory which will contain common
  17. blocks such as smooth stone, gravel, dirt, etc.
  18. If one of these ores is identified, then the turtle will dig out the block
  19. and then move into the space that the block occupied and 'sense' the blocks
  20. around it again to try and find the continuation of the vein.
  21. Once the turtle has finished identifying the vein, it will return to it's
  22. initial position. This last task may either be completed by recording
  23. movement as the turtle moves or by using a GPS wireless system and a
  24. basic 'goto' function for the initial coordinates.
  25. ]]
  26. end
  27.  
  28. function refuel()
  29. for i=1,15,1 do
  30. turtle.select(i)
  31. turtle.refuel(turtle.getItemCount(i))
  32. end
  33. turtle.select(1)
  34. end
  35.  
  36. function mainShaft()
  37. turtle.select(1)
  38. for i=1,4,1 do
  39. while turtle.detect() == true do
  40. turtle.dig()
  41. end
  42. turtle.forward()
  43. if not turtle.detectDown() then
  44. turtle.placeDown()
  45. end
  46. while turtle.detectUp() do
  47. turtle.digUp()
  48. end
  49. turtle.turnRight()
  50. while turtle.detect() == true do
  51. turtle.dig()
  52. end
  53. turtle.forward()
  54. if not turtle.detectDown() then
  55. turtle.placeDown()
  56. end
  57. while turtle.detectUp() do
  58. turtle.digUp()
  59. end
  60. turtle.turnRight()
  61. turtle.turnRight()
  62. while turtle.detect() do
  63. turtle.dig()
  64. end
  65. turtle.forward()
  66. if not turtle.detectDown() then
  67. turtle.placeDown()
  68. end
  69. turtle.turnRight()
  70. end
  71. turtle.turnRight()
  72. turtle.turnRight()
  73. turtle.select(16)
  74. turtle.forward()
  75. turtle.placeUp()
  76. turtle.turnLeft()
  77. turtle.forward()
  78. turtle.placeUp()
  79. turtle.turnLeft()
  80. turtle.forward()
  81. turtle.turnLeft()
  82. turtle.forward()
  83. turtle.turnRight()
  84. end
  85.  
  86. function sideShaft()
  87. turtle.select(1)
  88. for i=0,10,1 do
  89. while turtle.detect() == true do
  90. turtle.dig()
  91. end
  92. turtle.forward()
  93. if turtle.detectDown() == false then
  94. turtle.placeDown()
  95. end
  96. while turtle.detectUp() == true do
  97. turtle.digUp()
  98. end
  99. end
  100. turtle.select(16)
  101. turtle.turnRight()
  102. turtle.turnRight()
  103. turtle.place()
  104. turtle.turnRight()
  105. turtle.turnRight()
  106. turtle.select(1)
  107. for i=0,10,1 do
  108. while turtle.detect() == true do
  109. turtle.dig()
  110. end
  111. turtle.forward()
  112. if turtle.detectDown() == false then
  113. turtle.placeDown()
  114. end
  115. while turtle.detectUp() == true do
  116. turtle.digUp()
  117. end
  118. end
  119. turtle.turnRight()
  120. turtle.turnRight()
  121. turtle.select(16)
  122. turtle.place()
  123. turtle.up()
  124. for i=1,23,1 do
  125. while turtle.detect() do
  126. turtle.dig()
  127. end
  128. turtle.forward()
  129. end
  130. turtle.down()
  131. end
  132.  
  133. function deposit()
  134. for i=1, (chestDist), 1 do
  135. turtle.forward()
  136. end
  137. for i=1, 15, 1 do
  138. turtle.select(i)
  139. turtle.drop()
  140. end
  141. refuel()
  142. if turtle.getItemCount(16) < 6 then
  143. stopMining()
  144. end
  145.  
  146. end
  147. turtle.turnRight()
  148. turtle.turnRight()
  149. for i=1, (chestDist), 1 do
  150. turtle.forward()
  151. end
  152.  
  153. end
  154.  
  155. function stopMining()
  156. if turtle.getFuelLevel() < (108 + 2 * chestDist) then
  157. print("I am low on fuel.")
  158. local remainFuel = 0
  159. for i=currentPos, length, 1 do
  160. remainFuel = (108 + 2 * (4 * i + 1))
  161. end
  162. print("I need "..remainFuel.." to finish.")
  163. print("That's "..(remainFuel/80).." coal or "..(remainFuel/1000).." lava.")
  164. print("Type (cont) to refuel & continue mining.")
  165. doFuel = true
  166. end
  167. if turtle.getItemCount(16) < 6 then
  168. print("I am low on torches.")
  169. print("Place more in slot 16...")
  170. while turtle.getItemCount(16) < 6 do
  171. sleep(1)
  172. end
  173. print("Type (cont) to continue mining.")
  174. doFuel = false
  175. end
  176. local cont = false
  177. while cont == false do
  178. --[[if rs.getInput("right") == true then --Flickers RS torch on right of chest
  179. rs.setOutput("right", false)
  180. else
  181. rs.setOutput("right", true)
  182. end]]
  183. local input = io.read()
  184. if input == "cont" then
  185. if doFuel then
  186. refuel()
  187. end
  188. turtle.turnRight()
  189. turtle.turnRight()
  190. for i=1, chestDist, 1 do
  191. turtle.forward()
  192. end
  193. currentPos = currentPos + 1
  194. run()
  195. else
  196. print("Incorrect input.")
  197. end
  198. end
  199. end
  200.  
  201. function run()
  202. while currentPos < length do
  203. chestDist = (currentPos * 4 + 4)
  204. mainShaft()
  205. turtle.turnLeft()
  206. sideShaft()
  207. sideShaft()
  208. turtle.turnLeft()
  209. deposit()
  210. currentPos = currentPos + 1
  211. end
  212. end
  213.  
  214. function idle()
  215. print("Mining Complete")
  216. print("Type (end) to terminate program")
  217. local input = "null"
  218. rs.setOutput("right", true)
  219. while input ~= "end" do
  220. input = io.read()
  221. end
  222. rs.setOutput("right", false)
  223. end
  224.  
  225. --Execution
  226. print("----------------------------------")
  227. print("Branch Mine Turtle Activated")
  228. print("----------------------------------")
  229. sleep(2)
  230. print("Beginning Mine w. Following Specs:")
  231. print("Main Shaft: "..mainShaftDim)
  232. print("Side Shafts: "..sideShaftDim)
  233. print("Branch Frequency: "..shaftFreq)
  234. print("----------------------------------")
  235.  
  236. print("Number of Shafts:")
  237. length = tonumber(read())
  238. currentPos = 0
  239. print("----------------------------------")
  240. for x = length, 0, -1 do
  241. totalCost = totalCost + (108 + 2 * (4 * x + 1))
  242. end
  243. print("Current Fuel: "..turtle.getFuelLevel())
  244. print("Fuel cost: "..totalCost)
  245. print("Coal cost: "..(totalCost/80))
  246. print("Lava cost: "..(totalCost/1000))
  247. sleep(2)
  248. print("----------------------------------")
  249. print("Would you like to refuel now (y/n)?")
  250. input = io.read()
  251. if input == "y" then
  252. refuel()
  253. print("Refueled.")
  254. else
  255. print("Did not refuel.")
  256. end
  257. print("Turtle now has "..turtle.getFuelLevel().." fuel.")
  258. print("----------------------------------")
  259. print("Now beginning mining!")
  260.  
  261. run()
  262. turtle.turnRight()
  263. turtle.turnRight()
  264. for i=1, chestDist, 1 do
  265. turtle.forward()
  266. end
  267. idle()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement