Advertisement
MrHG

SDMiner 2.1

Aug 4th, 2018
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.90 KB | None | 0 0
  1. -- uses Robust Turtle API: pastebin get 0TnEBf2P t
  2. os.loadAPI("t")
  3. local args = {...}
  4. local versionNumber = "2.1"
  5. local programName = "StarDustMiner"
  6. local programNameShort = "SDMiner"
  7. local startInventory = 2
  8. local torchEnabled = true
  9. local torchName = "minecraft:torch"
  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. -- FUEL CALCULATION
  34. -- for every 2 blocks after block 1 in MainTL, add 4 times IndivTL.
  35. -- then add 1 for every time you add 4xIndivTL. Then add another MainTL
  36. -- then add 80 just in case.
  37. local blocksToTravel = (2*mainTL) + (((math.floor(mainTL/2)+1)*4) * indivTL + 1) + 80
  38. if blocksToTravel>3000 then
  39. print("This will result in a mine bigger than 3000 blocks. Are you sure? (y/n)")
  40. if read()~="y" then
  41. print("Aborting operation")
  42. return
  43. end
  44. end
  45. print("Operation will need " .. blocksToTravel .. " fuel.")
  46. print("~" .. math.floor(blocksToTravel/80) .. " Pieces of coal.")
  47. print("Please ensure these are located in the top left slot.")
  48. print("To enable Torchmode, put torches next to the fuel.")
  49. print("Starting in 3 Seconds...")
  50. sleep(3)
  51. term.clear()
  52. print("Commencing Dig.")
  53. end
  54.  
  55. function DisableTorchMode()
  56. print("No torches found, Disabling Torch Mode.")
  57. startInventory = 2
  58. torchEnabled = false
  59. return false
  60. end
  61.  
  62. function checkForTorches()
  63. if torchEnabled == true then
  64. if turtle.getItemDetail(2) then
  65. if turtle.getItemDetail(2).name == torchName then
  66. startInventory = 3
  67. torchEnabled = true
  68. return true
  69. else
  70. DisableTorchMode()
  71. end
  72. else
  73. DisableTorchMode()
  74. end
  75. else
  76. startInventory = 2
  77. end
  78. end
  79.  
  80. function Refuel(amountOfRequiredFuel)
  81. turtle.select(1)
  82. if (turtle.getFuelLevel() == "unlimited") then
  83. -- that's pretty neat dude.
  84. return
  85. end
  86. if (turtle.getFuelLevel() < amountOfRequiredFuel) then
  87. while (true) do
  88. if turtle.refuel(1) then
  89. if (turtle.getFuelLevel() > amountOfRequiredFuel) then
  90. break
  91. end
  92. else
  93. print("Turtle could not refuel. Please check why.")
  94. error()
  95. end
  96. end
  97. end
  98. end
  99.  
  100. function PlaceTorch()
  101. if checkForTorches() then
  102. t.back()
  103. t.digUp()
  104. t.up()
  105. t.dig()
  106. t.place(2)
  107. t.down()
  108. t.forward()
  109. end
  110. end
  111.  
  112. function DigIndivTunnel()
  113. for i=1,indivTL do
  114. Refuel(160)
  115. t.dig()
  116. t.forward()
  117. t.digUp()
  118. if indivTL % 7 ~= 0 and i % 7 == 0 and torchEnabled then
  119. t.up()
  120. t.right()
  121. t.forward()
  122. t.dig()
  123. t.back()
  124. t.place(2)
  125. t.left()
  126. t.down()
  127. end
  128. end
  129. if (torchEnabled) then
  130. PlaceTorch()
  131. end
  132. t.turnAround()
  133. Refuel(indivTL)
  134. t.forward(indivTL)
  135. end
  136.  
  137. function EmptyInventory()
  138. local itemsDepositedCount = 0
  139. for i=startInventory,16 do
  140. turtle.select(i)
  141. itemsDepositedCount = itemsDepositedCount + turtle.getItemCount()
  142. if turtle.getItemCount() == 0 then
  143. --twiddle your thumbs
  144. elseif not turtle.drop() then
  145. print("Container full. Please empty it.")
  146. error()
  147. end
  148. end
  149. print("Deposited "..itemsDepositedCount.." Items.")
  150. if not torchEnabled then
  151. print("Torch mode currently Disabled.")
  152. print("Insert torches in slot 2 to enable.")
  153. sleep(3)
  154. torchEnabled = true
  155. if checkForTorches() then
  156. print("Torch mode Enabled.")
  157. end
  158. end
  159. turtle.select(1)
  160. end
  161.  
  162. -- Main Block
  163. checkForTorches()
  164. t.turnAround()
  165. EmptyInventory()
  166. print("Inventory emptied. Heading out.")
  167. t.turnAround()
  168. local blocksAwayFromContainer = 0
  169. for i=1,mainTL do
  170. Refuel(160)
  171. t.dig()
  172. t.forward()
  173. blocksAwayFromContainer = blocksAwayFromContainer + 1
  174. t.digUp()
  175. if not (i%2 == 0) then
  176. t.left()
  177. DigIndivTunnel()
  178. -- Inventory check
  179. turtle.select(14)
  180. if turtle.getItemCount() > 0 then
  181. t.right()
  182. t.forward(blocksAwayFromContainer)
  183. EmptyInventory()
  184. t.turnAround()
  185. t.forward(blocksAwayFromContainer)
  186. t.right()
  187. end
  188. DigIndivTunnel()
  189. turtle.select(14)
  190. if turtle.getItemCount() > 0 then
  191. t.left()
  192. t.forward(blocksAwayFromContainer)
  193. EmptyInventory()
  194. t.turnAround()
  195. t.forward(blocksAwayFromContainer)
  196. else
  197. t.right()
  198. end
  199. else
  200. Refuel(160)
  201. t.right()
  202. t.dig()
  203. t.up()
  204. t.dig()
  205. if (torchEnabled) then
  206. if checkForTorches() then
  207. t.place(2)
  208. end
  209. end
  210. t.turnAround()
  211. t.dig()
  212. t.down()
  213. t.dig()
  214. t.right()
  215. end
  216. end
  217. t.turnAround()
  218. t.forward(mainTL)
  219. EmptyInventory()
  220. t.turnAround()
  221. print("")
  222. print("Dig Complete!")
  223. print("Thank you for using "..programName.."!")
  224. print("")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement