Advertisement
MrHG

SDMiner 2.0

Aug 4th, 2018
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.59 KB | None | 0 0
  1. -- uses Robust Turtle API: pastebin get 0TnEBf2P t
  2. os.loadAPI("t")
  3. local args = {...}
  4. local versionNumber = "2.0"
  5. local programName = "StarDustMiner"
  6. local programNameShort = "SDMiner"
  7. local startInventory = 2
  8. local torchEnabled = false
  9. local torchData
  10.  
  11. if #args ~= 2 then
  12. print ("Usage: "..programNameShort.." (Main Tunnel Length) (Individual Tunnel Length)")
  13. return
  14. else
  15. mainTL = tonumber(args[1])
  16. indivTL = tonumber(args[2])
  17. if mainTL < 1 then
  18. print("Main Tunnel Length must be positive")
  19. return
  20. end
  21. if indivTL < 1 then
  22. print("Individual Tunnel Length must be positive")
  23. return
  24. end
  25. -- INITIAL SETUP FASE
  26. term.clear()
  27. term.setCursorPos(1,1)
  28.  
  29. print("Welcome to"..programName.."Version "..versionNumber.." !")
  30. print("(Coded by MrHG using RobustTurtleAPI)")
  31. print("")
  32. sleep(1)
  33. print("Please ensure the Mining turtle is facing away ")
  34. print("from the container.")
  35. print("")
  36.  
  37. -- FUEL CALCULATION
  38. -- for every 2 blocks after block 1 in MainTL, add 4 times IndivTL.
  39. -- then add 1 for every time you add 4xIndivTL. Then add another MainTL
  40. -- then add 80 just in case.
  41. local blocksToTravel = (2*mainTL) + (((math.floor(mainTL/2)+1)*4) * indivTL + 1) + 80
  42. if blocksToTravel>3000 then
  43. print("This will result in a mine bigger than 3000 blocks. Are you sure? (y/n)")
  44. if read()~="y" then
  45. print("Aborting operation")
  46. return
  47. end
  48. end
  49. print("Operation will need " .. blocksToTravel .. " fuel.")
  50. print("~" .. math.floor(blocksToTravel/80) .. " Pieces of coal.")
  51. print("Please ensure these are located in the top left slot.")
  52. print("WOULD YOU LIKE TO ENABLE TORCH MODE?")
  53. if read() == "y" then
  54. torchEnabled = true
  55. end
  56. if torchEnabled == true then
  57. print("Put torches to the right of the fuel.")
  58. print("Starting in 3 Seconds...")
  59. sleep(3)
  60. torchData = turtle.getItemDetail(2)
  61. term.clear()
  62. print("Commencing Dig.")
  63. end
  64.  
  65. function checkForTorches()
  66. if torchEnabled == true then
  67. if torchData then
  68. elseif turtle.getItemDetail(2).name == torchData.name then
  69. startInventory = 3
  70. torchEnabled = true
  71. return
  72. else
  73. print("No torches found, Disabling Torch Mode.")
  74. startInventory = 2
  75. torchEnabled = false
  76. return
  77. end
  78. end
  79. else
  80. startInventory = 2
  81. end
  82. end
  83.  
  84. function Refuel(amountOfRequiredFuel)
  85. turtle.select(1)
  86. if (turtle.getFuelLevel() == "unlimited") then
  87. -- that's pretty neat dude.
  88. return
  89. end
  90. if (turtle.getFuelLevel() < amountOfRequiredFuel) then
  91. while (true) do
  92. if turtle.refuel(1) then
  93. if (turtle.getFuelLevel() > amountOfRequiredFuel) then
  94. break
  95. end
  96. else
  97. print("Turtle could not refuel. Please check why.")
  98. error()
  99. end
  100. end
  101. end
  102. end
  103.  
  104. function DigIndivTunnel()
  105. for i=1,indivTL do
  106. Refuel(160)
  107. t.dig()
  108. t.forward()
  109. t.digUp()
  110. end
  111. print("Tunnel Complete, returning.")
  112. if (torchEnabled) then
  113. turtle.select(2)
  114. checkForTorches()
  115. turtle.placeUp()
  116. end
  117. t.turnAround()
  118. Refuel(indivTL)
  119. t.forward(indivTL)
  120. print("Returned.")
  121. end
  122.  
  123. function EmptyInventory()
  124. local itemsDepositedCount = 0
  125. for i=startInventory,16 do
  126. turtle.select(i)
  127. itemsDepositedCount = itemsDepositedCount + turtle.getItemCount()
  128. if turtle.getItemCount() == 0 then
  129. --twiddle your thumbs
  130. elseif not turtle.drop() then
  131. print("Container full. Please empty it.")
  132. error()
  133. end
  134. end
  135. print("Deposited "..itemsDepositedCount.." Items.")
  136. turtle.select(1)
  137. end
  138.  
  139. -- Main Block
  140. checkForTorches()
  141. t.turnAround()
  142. EmptyInventory()
  143. print("Inventory emptied. Heading out.")
  144. t.turnAround()
  145. local blocksAwayFromContainer = 0
  146. for i=1,mainTL do
  147. Refuel(160)
  148. t.dig()
  149. t.forward()
  150. blocksAwayFromContainer = blocksAwayFromContainer + 1
  151. t.digUp()
  152. if not (i%2 == 0) then
  153. t.left()
  154. DigIndivTunnel()
  155. -- Inventory check
  156. turtle.select(14)
  157. if turtle.getItemCount() > 0 then
  158. t.right()
  159. t.forward(blocksAwayFromContainer)
  160. EmptyInventory()
  161. t.turnAround()
  162. t.forward(blocksAwayFromContainer)
  163. t.right()
  164. end
  165. DigIndivTunnel()
  166. turtle.select(14)
  167. if turtle.getItemCount() > 0 then
  168. t.left()
  169. t.forward(blocksAwayFromContainer)
  170. EmptyInventory()
  171. t.turnAround()
  172. t.forward(blocksAwayFromContainer)
  173. else
  174. t.right()
  175. end
  176. else
  177. Refuel(160)
  178. t.right()
  179. t.dig()
  180. t.up()
  181. t.dig()
  182. if (torchEnabled) then
  183. turtle.select(2)
  184. checkForTorches()
  185. turtle.place()
  186. end
  187. t.turnAround()
  188. t.dig()
  189. t.down()
  190. t.dig()
  191. t.right()
  192. end
  193. end
  194. end
  195. t.turnAround()
  196. t.forward(blocksAwayFromContainer)
  197. EmptyInventory()
  198. print("Dig Complete! Thank you for using "..programName.."!")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement