hunterbr549

Untitled

May 25th, 2019
40
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.69 KB | None | 0 0
  1. --[[
  2. Version
  3. 0.01 5/10/2017
  4. Changelog
  5. 0.01 - Rewriting.
  6. 0.02 - Code Fixing
  7. ]]--
  8.  
  9. -- Area
  10. local distance = 0
  11. local distanceApart = 0
  12. local distanceApartCount = 0
  13. local backwardsCount = 0
  14. local forwardsCount = 0
  15. -- Misc
  16. local noFuelNeeded = 0
  17. local LorR = 0 -- if 0 then left if 1 then right
  18. local Mines = 0
  19. local onlight = 0
  20. local missingItems = 0
  21. -- Inventory
  22. local chests = 0
  23. local fuelSlot = 0
  24. local torch = 0
  25.  
  26. -- ItemCheck
  27. local function itemCount()
  28. fuelSlot = turtle.getItemCount(1)
  29. chests = turtle.getItemCount(2)
  30. torch = turtle.getItemCount(3)
  31. missingItems = 0
  32. end
  33.  
  34. -- Checking
  35. local function check()
  36. if noFuelNeeded == 0 then
  37. if fuelSlot == 0 then
  38. print("Turtle has no fuel")
  39. print("Put fuel in First")
  40. missingItems = 1
  41. else
  42. print("Turtle has Fuel")
  43. end
  44. end
  45. if chests == 0 then
  46. print("No chests in turtle")
  47. print("Put chests in 1 slot")
  48. missingItems = 1
  49. else
  50. print("Turtle has chest")
  51. end
  52. if missingItems == 1 then
  53. print("Items are missing please try again")
  54. print("Turtle will recheck in 3 sec")
  55. end
  56. end
  57.  
  58. -- Refuel
  59. local function refuel()
  60. if noFuelNeeded == 0 then
  61. repeat
  62. if turtle.getFuelLevel() < 120 then
  63. if fuelSlot > 0 then
  64. turtle.select(1)
  65. turtle.refuel(1)
  66. fuelSlot = fuelSlot - 1
  67. else
  68. print("out of fuel")
  69. os.shutdown()
  70. end
  71. end
  72. until turtle.getFuelLevel() > 120
  73. end
  74. end
  75.  
  76. -- ItemDump
  77. local function chestDump()
  78. if turtle.getItemCount(16)> 0 then -- If slot 16 in turtle has item slot 4 to 16 will go to chest
  79. turtle.digDown()
  80. turtle.select(2)
  81. turtle.placeDown()
  82. chests = chests - 1
  83. for slot = 5, 16 do
  84. turtle.select(slot)
  85. sleep(0.6) -- Small fix for slow pc because i had people problem with this
  86. turtle.dropDown()
  87. end
  88. turtle.select(4)
  89. if chests == 0 then
  90. print("Out Of chests")
  91. os.shutdown()
  92. end
  93. end
  94. end
  95.  
  96. -- Every 8 block it place torch
  97. local function placeTorch()
  98. if torch > 0 then
  99. turnAround()
  100. turtle.select(3)
  101. turtle.place()
  102. turnAround()
  103. torch = torch - 1
  104. onlight = 0
  105. end
  106. end
  107.  
  108. local function turnAround()
  109. turtle.turnLeft()
  110. turtle.turnLeft()
  111. end
  112.  
  113. local function dig()
  114. repeat
  115. refuel()
  116. chestDump()
  117. if turtle.detect() then
  118. turtle.dig()
  119. end
  120. if turtle.forward() then -- sometimes sand and gravel and block and mix-up distance
  121. forwardsCount = forwardsCount + 1
  122. onlight = onlight + 1
  123. end
  124. if turtle.detectUp() then
  125. turtle.digUp()
  126. end
  127. if onlight == 8 then
  128. placeTorch()
  129. end
  130. until forwardsCount == distance
  131. end
  132.  
  133. --Back Program
  134. local function back()
  135. turtle.up()
  136. turnAround()
  137. repeat
  138. if turtle.forward() then -- sometimes sand and gravel and block and mix-up distance
  139. backwardsCount = backwardsCount + 1
  140. end
  141. if turtle.detect() then -- Sometimes sand and gravel can happen and this will fix it
  142. if backwardsCount ~= distance then
  143. turtle.dig()
  144. end
  145. end
  146. until backwardsCount == distance
  147. end
  148.  
  149. -- Multimines Program
  150. local function nextMine()
  151. if LorR == 1 then
  152. turtle.turnLeft()
  153. turtle.down()
  154. else
  155. turtle.turnRight()
  156. turtle.down()
  157. end
  158. repeat
  159. if turtle.detect() then
  160. turtle.dig()
  161. end
  162. if turtle.forward() then
  163. distanceApartCount = distanceApartCount + 1
  164. end
  165. if turtle.detectUp() then
  166. turtle.digUp()
  167. end
  168. until distanceApartCount == distanceApart
  169. if LorR == 1 then
  170. turtle.turnLeft()
  171. else
  172. turtle.turnRight()
  173. end
  174. end
  175.  
  176. -- Reset
  177. local function reset()
  178. backwardsCount = 0
  179. forwardsCount = 0
  180. distanceApartCount = 0
  181. onlight = 0
  182. end
  183.  
  184. local function main()
  185. repeat
  186. dig()
  187. back()
  188. reset()
  189. Mines = Mines - 1
  190. until Mines == 0
  191. print("Turtle is done")
  192. end
  193.  
  194. -- Starting
  195. local function start()
  196. print("Welcome to Mining Turtle Program")
  197. print("Slot 1: Fuel, Slot 2: Chests, Optional Slot 3: Torchs")
  198. print("Note: turtle will still work when there is no more torchs")
  199. print("How many block far does each mine be")
  200. distance = tonumber(read())
  201. print("Left or Right")
  202. print("0 = Left and 1 = Right")
  203. LorR = tonumber(read())
  204. print("How many mines: ")
  205. Mines = tonumber(read())
  206. print("Distance Apart from each Mine")
  207. distanceApart = tonumber(read())
  208. distanceApart = distanceApart + 1
  209. if turtle.getFuelLevel() == "unlimited" then
  210. print("Your turtle config does need fuel")
  211. noFuelNeed = 1
  212. end
  213. repeat
  214. itemCount()
  215. check()
  216. sleep(3)
  217. until missingItems == 0
  218. main()
  219. end
  220.  
  221. start()
Add Comment
Please, Sign In to add comment