Desert229

minerB

Oct 5th, 2022 (edited)
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.51 KB | None | 0 0
  1. m = 0 --mining counter
  2. ds = 2 --drop slot selection
  3. ic = 0 --item count
  4. d = 0 --distance (length of tunnel)
  5. cl = 0 --current loop
  6. lt = 3 --loop target
  7. fl = turtle.getFuelLevel() --fuel level
  8. lat = 1 --layer target
  9. cla = 1 --current layer
  10. icf = 0 --item count fuel
  11. dirLeft = 0 --turn left instead of right (right is default)
  12.  
  13.  
  14.  
  15. --hints
  16. print("1: Put Cobblestone/Deep Slate in my first inventory slot")
  17. print("2: Put fuel in my second inventory slot")
  18. print("3: Place me right above the item stream")
  19.  
  20.  
  21. --USER INPUTS
  22.  
  23. --left or right?
  24. print("Do you want me to mine leftwards or rightwards? (l/r))
  25. local direction = io.read()
  26. if direction == left or direction == l or direction == L or do
  27. dirLeft = 1
  28. end
  29. if direction == right or direction == r or direction == R do
  30. dirLeft = 0
  31. end
  32. if direction ~= left and direction ~= l and direction ~= right and direction ~= r and direction ~= R and direction ~= L do
  33. print("ERROR: Please enter l for left and r for right.")
  34. error()
  35. end
  36.  
  37. if dirLeft > 0 do
  38. turtle.turnRight() = turtle.turnLeft()
  39. end
  40.  
  41. --length and layers
  42. print("Enter length of tunnels:")
  43. local d = tonumber(io.read())
  44. print("Enter amount of loops:")
  45. local lt = tonumber(io.read())
  46. print("Enter amount of layers (upwards):")
  47. local lat = tonumber(io.read())
  48.  
  49. --checking starting parameters
  50.  
  51. if fl == 0 then
  52. print("ERROR: I need starter fuel")
  53. error()
  54. end
  55.  
  56. turtle.select(1)
  57. ic = turtle.getItemCount()
  58.  
  59. if ic < 1 then
  60. print("ERROR: Put Cobblestone/Deep Slate in my first inventory slot!")
  61. error()
  62. end
  63.  
  64.  
  65. --OPERATIONAL FUNCTIONS
  66.  
  67. --refuel function
  68. local function fuelCheck()
  69. fl = turtle.getFuelLevel()
  70. while fl <= 1000 do
  71. turtle.select(2)
  72. icf = turtle.getItemCount()
  73. if icf > 1 then
  74. turtle.refuel(1)
  75. print("I refuelled to", turtle.getFuelLevel())
  76. else
  77. print("I'm out of fuel!")
  78. error()
  79. end
  80. turtle.select(1)
  81. fl = turtle.getFuelLevel()
  82. end
  83. end
  84.  
  85.  
  86. --drop trash function
  87. function dropCobble(slot)
  88. turtle.select(slot)
  89. turtle.dropDown(turtle.getItemCount() - 1)
  90. end
  91.  
  92. --anti gravel function
  93. local function digUntilEmpty()
  94. while turtle.detect() do
  95. turtle.dig()
  96. end
  97. end
  98.  
  99. --dig straight line
  100. local function digForward()
  101. digUntilEmpty()
  102. turtle.forward()
  103. turtle.digDown()
  104. turtle.digUp()
  105. end
  106.  
  107.  
  108. --MINING OPERATION
  109.  
  110. --layer loop
  111. while cla <= lat do
  112.  
  113. --back and forth loop
  114. while cl < lt do
  115. cl = cl + 1
  116.  
  117. --move turtle up to mining level
  118. if cla > 1 then
  119. for i = 0, (cla-1)*3, 1 do
  120. turtle.digUp()
  121. turtle.up()
  122. turtle.digUp()
  123. end
  124. else
  125. turtle.digUp()
  126. turtle.up()
  127. turtle.digUp()
  128. end
  129.  
  130. --first straight
  131. while m < d do
  132. digForward()
  133. m = m + 1
  134. if m == 10 or m == 20 or m == 30 or m == 40 or m == 50 then
  135. dropCobble(1)
  136. end
  137. end
  138.  
  139. --turn around
  140. if m == d then
  141. turtle.turnRight()
  142. digUntilEmpty()
  143. turtle.forward()
  144. turtle.digUp()
  145. turtle.digDown()
  146. turtle.turnRight()
  147. fuelCheck()
  148. dropCobble(1)
  149. m = 0
  150. end
  151.  
  152. --second straight
  153. while m < d do
  154. digForward()
  155. m = m + 1
  156. if m == 10 or m == 20 or m == 30 or m == 40 or m == 50 then
  157. dropCobble(1)
  158. end
  159. end
  160.  
  161. --user information
  162. print("I just finished loop:", cl, "out of", lt)
  163. print("on layer:", cla, "out of", lat)
  164.  
  165. --item drop-off
  166.  
  167. if cla > 1 then
  168. for i = 0, (cla - 1) * 3, 1 do
  169. turtle.digDown()
  170. turtle.down()
  171. end
  172. else
  173. turtle.digDown()
  174. turtle.down()
  175. end
  176.  
  177. while ds < 16 do --dropping everything except slot 1 and 2
  178. ds = ds + 1
  179. turtle.select(ds)
  180. turtle.dropDown()
  181. end
  182.  
  183. ds = 2 --reset for next loop
  184. m = 0
  185. turtle.select(1)
  186.  
  187. --second turn around unless it's the last loop
  188. if cl < lt then
  189. turtle.turnLeft()
  190. digUntilEmpty()
  191. turtle.forward()
  192. turtle.digDown()
  193. turtle.digUp()
  194. turtle.turnLeft()
  195. end
  196. end --back and forth looping ends
  197. cl = 0 --reset current loop for next layer
  198.  
  199. --bring turtle back to layer starting pos
  200. turtle.turnRight()
  201. for i = 0, lt*2-2, 1 do
  202. turtle.forward()
  203. end
  204. turtle.turnRight()
  205. cla = cla + 1 --finished layer increase current layer
  206. end
  207.  
  208. --end info
  209. print("Fuel level after job:", turtle.getFuelLevel())
  210. print("Job's done!")
Advertisement
Add Comment
Please, Sign In to add comment