Lorc520

paste_test

Apr 30th, 2025 (edited)
42
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.85 KB | None | 0 0
  1. -- === SETTINGS ===
  2. local useBlacklist = true
  3.  
  4. function openSettings()
  5. while true do
  6. print("\n=== SETTINGS ===")
  7. print("1. Toggle blacklist (currently " .. (useBlacklist and "ON" or "OFF") .. ")")
  8. print("2. Back to main menu")
  9. write("Select option: ")
  10. local input = read()
  11. if input == "1" then
  12. useBlacklist = not useBlacklist
  13. print("Blacklist is now " .. (useBlacklist and "ENABLED" or "DISABLED"))
  14. elseif input == "2" then
  15. return
  16. else
  17. print("Invalid input.")
  18. end
  19. end
  20. end
  21.  
  22. -- === USER INPUT ===
  23. local length, width, depth
  24.  
  25. while not length do
  26. print("Enter length or type 'settings':")
  27. local input = read()
  28. if input == "settings" then
  29. openSettings()
  30. else
  31. length = tonumber(input)
  32. end
  33. end
  34.  
  35. print("Enter width:")
  36. width = tonumber(read())
  37.  
  38. print("Enter depth:")
  39. depth = tonumber(read())
  40.  
  41. -- === STATE ===
  42. local x, y, z = 0, 0, 0
  43. local dir = 0
  44. local bucketSlot = 16
  45. local lastFuelPercent = -1
  46. local needsRefuel = false
  47.  
  48. -- === BLACKLIST ===
  49. local blacklist = {
  50. ["minecraft:cobbled_deepslate"] = true,
  51. ["minecraft:cobblestone"] = true
  52. }
  53.  
  54. -- === REFUELING SYSTEM ===
  55. function getFuelPercent()
  56. local current = turtle.getFuelLevel()
  57. local max = 20000
  58. return current / max
  59. end
  60.  
  61. function tryConsumeFuel()
  62. local percent = getFuelPercent()
  63. if percent < 0.05 then needsRefuel = true end
  64. if not needsRefuel then return end
  65.  
  66. if getFuelPercent() < 0.05 then
  67. for i = 1, 15 do
  68. turtle.select(i)
  69. while turtle.getItemCount(i) > 0 do
  70. if turtle.refuel(1) then
  71. print("Consumed fuel from slot " .. i .. ", current fuel level: " .. turtle.getFuelLevel())
  72. else
  73. break
  74. end
  75. end
  76. end
  77. end
  78.  
  79. if getFuelPercent() >= 0.05 then
  80. needsRefuel = false
  81. end
  82. turtle.select(1)
  83. end
  84.  
  85. -- === LAVA COLLECTION FUNCTION ===
  86. function tryCollectLava()
  87. turtle.select(bucketSlot)
  88. local detail = turtle.getItemDetail(bucketSlot)
  89. if detail and detail.name == "minecraft:bucket" then
  90. if turtle.place() then
  91. sleep(0.2)
  92. local newDetail = turtle.getItemDetail(bucketSlot)
  93. if newDetail and newDetail.name == "minecraft:lava_bucket" then
  94. if turtle.refuel(1) then
  95. print("Lava bucket consumed, fuel: " .. turtle.getFuelLevel())
  96. if getFuelPercent() >= 0.05 then
  97. needsRefuel = false
  98. end
  99. else
  100. print("Lava bucket not consumed.")
  101. end
  102. else
  103. print("No lava source in front.")
  104. end
  105. end
  106. end
  107. turtle.select(1)
  108. end
  109.  
  110. -- === BLACKLIST FILTER ===
  111. function dropBlacklistedItems()
  112. if not useBlacklist then return end
  113. for i = 1, 15 do
  114. turtle.select(i)
  115. local detail = turtle.getItemDetail(i)
  116. if detail and blacklist[detail.name] then
  117. turtle.dropDown()
  118. print("Dropped blacklisted item: " .. detail.name)
  119. end
  120. end
  121. turtle.select(1)
  122. end
  123.  
  124. -- === FUEL MONITOR ===
  125. function monitorFuel()
  126. local percent = getFuelPercent()
  127. if lastFuelPercent == -1 then
  128. lastFuelPercent = percent
  129. elseif math.abs(percent - lastFuelPercent) >= 0.05 then
  130. print("Fuel level changed: " .. math.floor(percent * 100) .. "%")
  131. lastFuelPercent = percent
  132. end
  133. end
  134.  
  135. -- === MOVEMENT HELPERS ===
  136. function tryDig() while turtle.detect() do turtle.dig(); sleep(0.4) end end
  137. function tryDigDown() while turtle.detectDown() do turtle.digDown(); sleep(0.4) end end
  138. function tryDigUp() while turtle.detectUp() do turtle.digUp(); sleep(0.4) end end
  139.  
  140. function forward()
  141. tryConsumeFuel()
  142. tryCollectLava()
  143. tryDig()
  144. dropBlacklistedItems()
  145. monitorFuel()
  146. while not turtle.forward() do sleep(0.2) end
  147. if dir == 0 then z = z + 1
  148. elseif dir == 1 then x = x + 1
  149. elseif dir == 2 then z = z - 1
  150. elseif dir == 3 then x = x - 1 end
  151. end
  152.  
  153. function back()
  154. tryConsumeFuel()
  155. tryCollectLava()
  156. tryDig()
  157. dropBlacklistedItems()
  158. monitorFuel()
  159. while not turtle.back() do sleep(0.2) end
  160. if dir == 0 then z = z - 1
  161. elseif dir == 1 then x = x - 1
  162. elseif dir == 2 then z = z + 1
  163. elseif dir == 3 then x = x + 1 end
  164. end
  165.  
  166. function down()
  167. tryConsumeFuel()
  168. tryCollectLava()
  169. tryDigDown()
  170. monitorFuel()
  171. while not turtle.down() do sleep(0.2) end
  172. y = y - 1
  173. end
  174.  
  175. function up()
  176. tryConsumeFuel()
  177. tryCollectLava()
  178. tryDigUp()
  179. monitorFuel()
  180. while not turtle.up() do sleep(0.2) end
  181. y = y + 1
  182. end
  183.  
  184. function turnLeft()
  185. turtle.turnLeft()
  186. dir = (dir - 1) % 4
  187. if dir < 0 then dir = dir + 4 end
  188. end
  189.  
  190. function turnRight()
  191. turtle.turnRight()
  192. dir = (dir + 1) % 4
  193. end
  194.  
  195. function face(target)
  196. while dir ~= target do turnRight() end
  197. end
  198.  
  199. -- === COORDINATE NAVIGATION ===
  200. function goTo(targetX, targetY, targetZ, targetDir)
  201. while y < targetY do up() end
  202. while y > targetY do down() end
  203.  
  204. if x < targetX then face(1) while x < targetX do forward() end
  205. elseif x > targetX then face(3) while x > targetX do forward() end end
  206.  
  207. if z < targetZ then face(0) while z < targetZ do forward() end
  208. elseif z > targetZ then face(2) while z > targetZ do forward() end end
  209.  
  210. face(targetDir or 0)
  211. end
  212.  
  213. -- === INVENTORY HANDLING ===
  214. function isInventoryFull()
  215. for i = 1, 15 do
  216. if turtle.getItemCount(i) == 0 then return false end
  217. end
  218. return true
  219. end
  220.  
  221. function dropItems()
  222. local saveX, saveY, saveZ, saveDir = x, y, z, dir
  223. goTo(0, 0, 0, 2)
  224. for i = 1, 15 do
  225. turtle.select(i)
  226. turtle.drop()
  227. end
  228. turtle.select(1)
  229. goTo(saveX, saveY, saveZ, saveDir)
  230. end
  231.  
  232. -- === MINING ===
  233. function mineLayer()
  234. for row = 1, width do
  235. for col = 1, length - 1 do
  236. forward()
  237. if isInventoryFull() then dropItems() end
  238. end
  239. if row < width then
  240. if row % 2 == 1 then turnRight(); forward(); turnRight()
  241. else turnLeft(); forward(); turnLeft() end
  242. end
  243. end
  244. if width % 2 == 1 then face(2) for i = 1, length - 1 do forward() end end
  245. face(3) for i = 1, width - 1 do forward() end
  246. face(0)
  247. dropBlacklistedItems()
  248. end
  249.  
  250. -- === MAIN ===
  251. print("Starting mining...")
  252. turtle.digDown()
  253. down()
  254.  
  255. for d = 1, depth do
  256. mineLayer()
  257. if d < depth then down() end
  258. end
  259.  
  260. goTo(0, 0, 0, 2)
  261. for i = 1, 15 do
  262. turtle.select(i)
  263. turtle.drop()
  264. end
  265. turtle.select(1)
  266. goTo(0, 0, 0, 0)
  267. print("Mining complete. Ready to unload into chest.")
  268.  
Advertisement
Add Comment
Please, Sign In to add comment