babulm

Untitled

May 2nd, 2026 (edited)
12
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 33.50 KB | None | 0 0
  1. -- perfect_miner_fast.lua
  2. -- CC:Tweaked / ComputerCraft Mining Turtle
  3. -- Optimierte Version
  4. --
  5. -- SLOTPLAN:
  6. -- Slot 1 = Bau-/Auffuellmaterial, z.B. Cobblestone
  7. -- Slot 2 = Fuel
  8. -- Slot 3-16 = gesammelte Items
  9. --
  10. -- AUFSTELLUNG:
  11. -- [ KISTE ] [ TURTLE ] ---> Mining-Richtung
  12. --
  13. -- Die Turtle schaut beim Start nach vorne in den Mining-Bereich.
  14. -- Die Kiste steht direkt hinter der Turtle.
  15.  
  16. local BUILD_SLOT = 1
  17. local FUEL_SLOT = 2
  18. local ITEM_FIRST = 3
  19. local ITEM_LAST = 16
  20.  
  21. -- Position relativ zum Start
  22. -- x = vorne
  23. -- y = rechts positiv / links negativ
  24. -- z = unten positiv
  25. local x, y, z = 0, 0, 0
  26.  
  27. -- Richtung: 0 vorne, 1 rechts, 2 hinten, 3 links
  28. local dir = 0
  29.  
  30. local mode = ""
  31. local length = 0
  32. local width = 0
  33. local depth = 0
  34. local height = 0
  35. local sideSign = 1
  36.  
  37. local blocksTarget = 0
  38. local blocksDone = 0
  39. local unloads = 0
  40. local trashDropped = 0
  41. local bedrockHit = false
  42. local startClock = os.clock()
  43. local isReturning = false
  44.  
  45. local cfg = {
  46. filterMode = "blacklist", -- all, blacklist, whitelist
  47. throwTrashDown = true,
  48. stackItems = true,
  49. lowFuelReturn = true,
  50. reserveFuel = 200,
  51. bridgeMode = false,
  52. fluidMode = "stop", -- stop, seal, ignore
  53. bedrockStop = true,
  54. progressEvery = 50,
  55. maintenanceEvery = 10,
  56. }
  57.  
  58. local TRASH_ITEMS = {}
  59. local KEEP_ITEMS = {}
  60.  
  61. -- =========================================================
  62. -- UI
  63. -- =========================================================
  64.  
  65. local function clear()
  66. term.clear()
  67. term.setCursorPos(1, 1)
  68. end
  69.  
  70. local function pause(msg)
  71. if msg then print(msg) end
  72. print("Enter druecken...")
  73. read()
  74. end
  75.  
  76. local function yn(text, default)
  77. while true do
  78. if default == true then
  79. write(text .. " (J/n): ")
  80. elseif default == false then
  81. write(text .. " (j/N): ")
  82. else
  83. write(text .. " (j/n): ")
  84. end
  85.  
  86. local a = string.lower(read())
  87.  
  88. if a == "" and default ~= nil then return default end
  89. if a == "j" or a == "ja" or a == "y" or a == "yes" then return true end
  90. if a == "n" or a == "nein" or a == "no" then return false end
  91.  
  92. print("Bitte j oder n eingeben.")
  93. end
  94. end
  95.  
  96. local function askNumber(text, min, default)
  97. min = min or 1
  98.  
  99. while true do
  100. if default then
  101. write(text .. " [" .. default .. "]: ")
  102. else
  103. write(text .. ": ")
  104. end
  105.  
  106. local input = read()
  107.  
  108. if input == "" and default then
  109. return default
  110. end
  111.  
  112. local n = tonumber(input)
  113.  
  114. if n and n >= min and math.floor(n) == n then
  115. return n
  116. end
  117.  
  118. print("Bitte eine ganze Zahl >= " .. min .. " eingeben.")
  119. end
  120. end
  121.  
  122. local function askChoice(text, choices, default)
  123. while true do
  124. print(text)
  125.  
  126. for i, c in ipairs(choices) do
  127. print(i .. " = " .. c.label)
  128. end
  129.  
  130. if default then
  131. write("Auswahl [" .. default .. "]: ")
  132. else
  133. write("Auswahl: ")
  134. end
  135.  
  136. local input = read()
  137.  
  138. if input == "" and default then
  139. return choices[default].value
  140. end
  141.  
  142. local n = tonumber(input)
  143.  
  144. if n and choices[n] then
  145. return choices[n].value
  146. end
  147.  
  148. print("Ungueltige Auswahl.")
  149. end
  150. end
  151.  
  152. local function drawSlotPlan()
  153. clear()
  154. print("=== PERFECT MINER FAST ===")
  155. print("")
  156. print("Aufstellung:")
  157. print("")
  158. print(" [ KISTE ] [ TURTLE ] ---> Mining-Richtung")
  159. print(" vorne")
  160. print("")
  161. print("Die Turtle muss nach vorne in den Mining-Bereich schauen.")
  162. print("Die Kiste muss direkt HINTER der Turtle stehen.")
  163. print("")
  164. print("Inventar:")
  165. print("+------+------+------+------+")
  166. print("| 1 | 2 | 3 | 4 |")
  167. print("|Block | Fuel | Item | Item |")
  168. print("+------+------+------+------+")
  169. print("| 5 | 6 | 7 | 8 |")
  170. print("| Item | Item | Item | Item |")
  171. print("+------+------+------+------+")
  172. print("| 9 | 10 | 11 | 12 |")
  173. print("| Item | Item | Item | Item |")
  174. print("+------+------+------+------+")
  175. print("| 13 | 14 | 15 | 16 |")
  176. print("| Item | Item | Item | Item |")
  177. print("+------+------+------+------+")
  178. print("")
  179. print("Slot 1: Bau-/Auffuellmaterial")
  180. print("Slot 2: Fuel")
  181. print("Slots 3-16: Sammel-Items")
  182. print("")
  183. print("Slot 1 und 2 werden nie in die Kiste entleert.")
  184. print("")
  185. pause()
  186. end
  187.  
  188. -- =========================================================
  189. -- ITEM-LISTEN
  190. -- =========================================================
  191.  
  192. local function add(t, name)
  193. t[name] = true
  194. end
  195.  
  196. local function setupDefaultLists()
  197. TRASH_ITEMS = {
  198. ["minecraft:cobblestone"] = true,
  199. ["minecraft:cobbled_deepslate"] = true,
  200. ["minecraft:gravel"] = true,
  201. ["minecraft:sand"] = true,
  202. ["minecraft:dirt"] = true,
  203. ["minecraft:flint"] = true,
  204. }
  205.  
  206. KEEP_ITEMS = {
  207. ["minecraft:coal"] = true,
  208. ["minecraft:charcoal"] = true,
  209.  
  210. ["minecraft:raw_iron"] = true,
  211. ["minecraft:raw_gold"] = true,
  212. ["minecraft:raw_copper"] = true,
  213.  
  214. ["minecraft:iron_ingot"] = true,
  215. ["minecraft:gold_ingot"] = true,
  216. ["minecraft:copper_ingot"] = true,
  217.  
  218. ["minecraft:iron_nugget"] = true,
  219. ["minecraft:gold_nugget"] = true,
  220.  
  221. ["minecraft:redstone"] = true,
  222. ["minecraft:lapis_lazuli"] = true,
  223. ["minecraft:diamond"] = true,
  224. ["minecraft:emerald"] = true,
  225.  
  226. ["minecraft:iron_ore"] = true,
  227. ["minecraft:deepslate_iron_ore"] = true,
  228. ["minecraft:gold_ore"] = true,
  229. ["minecraft:deepslate_gold_ore"] = true,
  230. ["minecraft:copper_ore"] = true,
  231. ["minecraft:deepslate_copper_ore"] = true,
  232. ["minecraft:coal_ore"] = true,
  233. ["minecraft:deepslate_coal_ore"] = true,
  234. ["minecraft:redstone_ore"] = true,
  235. ["minecraft:deepslate_redstone_ore"] = true,
  236. ["minecraft:lapis_ore"] = true,
  237. ["minecraft:deepslate_lapis_ore"] = true,
  238. ["minecraft:diamond_ore"] = true,
  239. ["minecraft:deepslate_diamond_ore"] = true,
  240. ["minecraft:emerald_ore"] = true,
  241. ["minecraft:deepslate_emerald_ore"] = true,
  242.  
  243. ["minecraft:ancient_debris"] = true,
  244. ["minecraft:nether_quartz_ore"] = true,
  245. ["minecraft:quartz"] = true,
  246.  
  247. ["minecraft:andesite"] = true,
  248. ["minecraft:tuff"] = true,
  249. }
  250. end
  251.  
  252. -- =========================================================
  253. -- FUEL
  254. -- =========================================================
  255.  
  256. local function fuel()
  257. return turtle.getFuelLevel()
  258. end
  259.  
  260. local function fuelUnlimited()
  261. return fuel() == "unlimited"
  262. end
  263.  
  264. local function refuelOne()
  265. if fuelUnlimited() then return true end
  266.  
  267. local old = turtle.getSelectedSlot()
  268. turtle.select(FUEL_SLOT)
  269.  
  270. if turtle.getItemCount(FUEL_SLOT) <= 0 then
  271. turtle.select(old)
  272. return false
  273. end
  274.  
  275. local ok = turtle.refuel(1)
  276. turtle.select(old)
  277. return ok
  278. end
  279.  
  280. local function topUpFuel()
  281. if fuelUnlimited() then return true end
  282.  
  283. while fuel() < cfg.reserveFuel and turtle.getItemCount(FUEL_SLOT) > 1 do
  284. if not refuelOne() then break end
  285. end
  286.  
  287. return fuel() > 2
  288. end
  289.  
  290. local function ensureFuelBasic()
  291. if fuelUnlimited() then return true end
  292.  
  293. while fuel() <= 2 do
  294. if not refuelOne() then
  295. print("")
  296. print("Fuel ist zu niedrig.")
  297. print("Lege Fuel in Slot 2 und druecke Enter.")
  298. read()
  299. end
  300. end
  301.  
  302. return true
  303. end
  304.  
  305. local function estimateHomeDistance()
  306. return math.abs(x) + math.abs(y) + math.abs(z) + 8
  307. end
  308.  
  309. -- =========================================================
  310. -- INVENTAR
  311. -- =========================================================
  312.  
  313. local function shouldTrash(name)
  314. if not name then return false end
  315.  
  316. if cfg.filterMode == "all" then
  317. return false
  318. elseif cfg.filterMode == "blacklist" then
  319. return TRASH_ITEMS[name] == true
  320. elseif cfg.filterMode == "whitelist" then
  321. return KEEP_ITEMS[name] ~= true
  322. end
  323.  
  324. return false
  325. end
  326.  
  327. local function throwTrash()
  328. local old = turtle.getSelectedSlot()
  329.  
  330. for i = ITEM_FIRST, ITEM_LAST do
  331. local d = turtle.getItemDetail(i)
  332.  
  333. if d and shouldTrash(d.name) then
  334. turtle.select(i)
  335.  
  336. if cfg.throwTrashDown then
  337. turtle.dropDown()
  338. else
  339. turtle.drop()
  340. end
  341.  
  342. trashDropped = trashDropped + d.count
  343. end
  344. end
  345.  
  346. turtle.select(old)
  347. end
  348.  
  349. local function stackItems()
  350. if not cfg.stackItems then return end
  351.  
  352. for source = ITEM_FIRST, ITEM_LAST do
  353. if turtle.getItemCount(source) > 0 then
  354. turtle.select(source)
  355.  
  356. for target = ITEM_FIRST, ITEM_LAST do
  357. if source ~= target and turtle.getItemCount(target) > 0 then
  358. if turtle.compareTo(target) then
  359. turtle.transferTo(target)
  360. end
  361. end
  362. end
  363. end
  364. end
  365.  
  366. turtle.select(ITEM_FIRST)
  367. end
  368.  
  369. local function inventoryAlmostFull()
  370. local empty = 0
  371. local space = 0
  372.  
  373. for i = ITEM_FIRST, ITEM_LAST do
  374. if turtle.getItemCount(i) == 0 then empty = empty + 1 end
  375. space = space + turtle.getItemSpace(i)
  376. end
  377.  
  378. return empty <= 1 or space < 64
  379. end
  380.  
  381. -- =========================================================
  382. -- DREHEN
  383. -- =========================================================
  384.  
  385. local function turnLeft()
  386. turtle.turnLeft()
  387. dir = (dir + 3) % 4
  388. end
  389.  
  390. local function turnRight()
  391. turtle.turnRight()
  392. dir = (dir + 1) % 4
  393. end
  394.  
  395. local function turnTo(target)
  396. if dir == target then return end
  397.  
  398. local diff = (target - dir) % 4
  399.  
  400. if diff == 1 then
  401. turnRight()
  402. elseif diff == 3 then
  403. turnLeft()
  404. elseif diff == 2 then
  405. turnRight()
  406. turnRight()
  407. end
  408. end
  409.  
  410. local function updateForwardPos()
  411. if dir == 0 then
  412. x = x + 1
  413. elseif dir == 1 then
  414. y = y + 1
  415. elseif dir == 2 then
  416. x = x - 1
  417. elseif dir == 3 then
  418. y = y - 1
  419. end
  420. end
  421.  
  422. -- =========================================================
  423. -- FLUESSIGKEITEN / BAUEN
  424. -- =========================================================
  425.  
  426. local function isFluidName(name)
  427. return name == "minecraft:water"
  428. or name == "minecraft:lava"
  429. or name == "minecraft:flowing_water"
  430. or name == "minecraft:flowing_lava"
  431. end
  432.  
  433. local function hasBuildBlock()
  434. return turtle.getItemCount(BUILD_SLOT) > 0
  435. end
  436.  
  437. local function placeBuildForward()
  438. if not hasBuildBlock() then return false end
  439.  
  440. local old = turtle.getSelectedSlot()
  441. turtle.select(BUILD_SLOT)
  442. local ok = turtle.place()
  443. turtle.select(old)
  444. return ok
  445. end
  446.  
  447. local function placeBuildDown()
  448. if not hasBuildBlock() then return false end
  449.  
  450. local old = turtle.getSelectedSlot()
  451. turtle.select(BUILD_SLOT)
  452. local ok = turtle.placeDown()
  453. turtle.select(old)
  454. return ok
  455. end
  456.  
  457. local function handleFluidForward()
  458. if cfg.fluidMode == "ignore" then return true end
  459.  
  460. local ok, data = turtle.inspect()
  461.  
  462. if ok and data and data.name and isFluidName(data.name) then
  463. print("")
  464. print("Fluessigkeit vor der Turtle: " .. data.name)
  465.  
  466. if cfg.fluidMode == "seal" then
  467. if placeBuildForward() then
  468. sleep(0.1)
  469. return true
  470. end
  471.  
  472. print("Keine Bau-/Auffuellbloecke in Slot 1.")
  473. end
  474.  
  475. print("Bitte sichern und Enter druecken.")
  476. read()
  477. end
  478.  
  479. return true
  480. end
  481.  
  482. local function handleFluidDown()
  483. if cfg.fluidMode == "ignore" then return true end
  484.  
  485. local ok, data = turtle.inspectDown()
  486.  
  487. if ok and data and data.name and isFluidName(data.name) then
  488. print("")
  489. print("Fluessigkeit unter der Turtle: " .. data.name)
  490.  
  491. if cfg.fluidMode == "seal" then
  492. if placeBuildDown() then
  493. sleep(0.1)
  494. return true
  495. end
  496.  
  497. print("Keine Bau-/Auffuellbloecke in Slot 1.")
  498. end
  499.  
  500. print("Bitte sichern und Enter druecken.")
  501. read()
  502. end
  503.  
  504. return true
  505. end
  506.  
  507. local function bridgeIfNeeded()
  508. -- Wichtig:
  509. -- Es wird NUR gesetzt, wenn Brueckenmodus aktiv ist UND unter der Turtle wirklich Luft ist.
  510. -- Bereits ausgehobene Bloecke werden nicht wieder aufgefuellt.
  511. if cfg.bridgeMode and not turtle.detectDown() then
  512. placeBuildDown()
  513. end
  514. end
  515.  
  516. -- =========================================================
  517. -- GRABEN / BEWEGEN
  518. -- =========================================================
  519.  
  520. local function safeDigForward()
  521. handleFluidForward()
  522.  
  523. local loops = 0
  524.  
  525. while turtle.detect() do
  526. if cfg.bedrockStop then
  527. local ok, data = turtle.inspect()
  528. if ok and data and data.name == "minecraft:bedrock" then
  529. bedrockHit = true
  530. return false
  531. end
  532. end
  533.  
  534. turtle.dig()
  535. loops = loops + 1
  536.  
  537. -- Nur bei nachfallendem Sand/Gravel mehrfach versuchen.
  538. if loops > 30 then break end
  539. sleep(0.05)
  540. end
  541.  
  542. return true
  543. end
  544.  
  545. local function safeDigUp()
  546. local loops = 0
  547.  
  548. while turtle.detectUp() do
  549. turtle.digUp()
  550. loops = loops + 1
  551. if loops > 30 then break end
  552. sleep(0.05)
  553. end
  554.  
  555. return true
  556. end
  557.  
  558. local function safeDigDown()
  559. handleFluidDown()
  560.  
  561. local loops = 0
  562.  
  563. while turtle.detectDown() do
  564. if cfg.bedrockStop then
  565. local ok, data = turtle.inspectDown()
  566. if ok and data and data.name == "minecraft:bedrock" then
  567. bedrockHit = true
  568. return false
  569. end
  570. end
  571.  
  572. turtle.digDown()
  573. loops = loops + 1
  574. if loops > 30 then break end
  575. sleep(0.05)
  576. end
  577.  
  578. return true
  579. end
  580.  
  581. local function forwardRaw()
  582. ensureFuelBasic()
  583.  
  584. if not safeDigForward() then
  585. return false
  586. end
  587.  
  588. while not turtle.forward() do
  589. turtle.attack()
  590.  
  591. if not safeDigForward() then
  592. return false
  593. end
  594.  
  595. sleep(0.05)
  596. end
  597.  
  598. updateForwardPos()
  599. bridgeIfNeeded()
  600. return true
  601. end
  602.  
  603. local function upRaw()
  604. ensureFuelBasic()
  605. safeDigUp()
  606.  
  607. while not turtle.up() do
  608. turtle.attackUp()
  609. safeDigUp()
  610. sleep(0.05)
  611. end
  612.  
  613. z = z - 1
  614. return true
  615. end
  616.  
  617. local function downRaw()
  618. ensureFuelBasic()
  619.  
  620. if not safeDigDown() then
  621. return false
  622. end
  623.  
  624. while not turtle.down() do
  625. turtle.attackDown()
  626.  
  627. if not safeDigDown() then
  628. return false
  629. end
  630.  
  631. sleep(0.05)
  632. end
  633.  
  634. z = z + 1
  635. bridgeIfNeeded()
  636. return true
  637. end
  638.  
  639. local function moveX(tx)
  640. while x < tx do
  641. turnTo(0)
  642. if not forwardRaw() then return false end
  643. end
  644.  
  645. while x > tx do
  646. turnTo(2)
  647. if not forwardRaw() then return false end
  648. end
  649.  
  650. return true
  651. end
  652.  
  653. local function moveY(ty)
  654. while y < ty do
  655. turnTo(1)
  656. if not forwardRaw() then return false end
  657. end
  658.  
  659. while y > ty do
  660. turnTo(3)
  661. if not forwardRaw() then return false end
  662. end
  663.  
  664. return true
  665. end
  666.  
  667. local function moveZ(tz)
  668. while z < tz do
  669. if not downRaw() then return false end
  670. end
  671.  
  672. while z > tz do
  673. if not upRaw() then return false end
  674. end
  675.  
  676. return true
  677. end
  678.  
  679. local function goTo(tx, ty, tz)
  680. -- Reihenfolge ist bewusst so:
  681. -- Erst vertikal, dann horizontal.
  682. -- In den meisten Modi bewegt sich die Turtle dadurch durch bereits freigelegte Luft.
  683. if not moveZ(tz) then return false end
  684. if not moveX(tx) then return false end
  685. if not moveY(ty) then return false end
  686. return true
  687. end
  688.  
  689. -- =========================================================
  690. -- WARTUNG / KISTE
  691. -- =========================================================
  692.  
  693. local function dropIntoChest()
  694. turnTo(2)
  695.  
  696. for i = ITEM_FIRST, ITEM_LAST do
  697. turtle.select(i)
  698.  
  699. while turtle.getItemCount(i) > 0 do
  700. local ok = turtle.drop()
  701.  
  702. if not ok then
  703. print("")
  704. print("Kiste voll oder nicht erreichbar.")
  705. print("Bitte Kiste leeren/pruefen und Enter druecken.")
  706. read()
  707. end
  708. end
  709. end
  710.  
  711. turtle.select(ITEM_FIRST)
  712. unloads = unloads + 1
  713. end
  714.  
  715. local function goHomeAndUnload()
  716. if isReturning then return end
  717. isReturning = true
  718.  
  719. local sx, sy, sz, sd = x, y, z, dir
  720.  
  721. print("")
  722. print("Fahre zur Kiste...")
  723. goTo(0, 0, 0)
  724. dropIntoChest()
  725.  
  726. print("Fahre zurueck...")
  727. goTo(sx, sy, sz)
  728. turnTo(sd)
  729.  
  730. isReturning = false
  731. end
  732.  
  733. local function showProgress(force)
  734. if not force and blocksDone % cfg.progressEvery ~= 0 then
  735. return
  736. end
  737.  
  738. local elapsed = os.clock() - startClock
  739. local percent = 0
  740. local eta = "?"
  741.  
  742. if blocksTarget > 0 then
  743. percent = math.floor((blocksDone / blocksTarget) * 100)
  744. end
  745.  
  746. if blocksDone > 0 then
  747. local perBlock = elapsed / blocksDone
  748. local remaining = math.max(0, blocksTarget - blocksDone)
  749. local seconds = math.floor(perBlock * remaining)
  750. eta = math.floor(seconds / 60) .. "m " .. (seconds % 60) .. "s"
  751. end
  752.  
  753. print(
  754. "Fortschritt " .. percent .. "% | " ..
  755. blocksDone .. "/" .. blocksTarget .. " | " ..
  756. "Fuel " .. tostring(fuel()) .. " | " ..
  757. "Entladungen " .. unloads .. " | " ..
  758. "ETA " .. eta
  759. )
  760. end
  761.  
  762. local function maintenance(force)
  763. if isReturning then return end
  764.  
  765. if not force and blocksDone % cfg.maintenanceEvery ~= 0 then
  766. return
  767. end
  768.  
  769. throwTrash()
  770. stackItems()
  771.  
  772. if cfg.lowFuelReturn and not fuelUnlimited() then
  773. topUpFuel()
  774.  
  775. if fuel() < estimateHomeDistance() + 5 then
  776. print("Fuel niedrig. Kehre zur Kiste zurueck.")
  777. goHomeAndUnload()
  778. end
  779. end
  780.  
  781. if inventoryAlmostFull() then
  782. goHomeAndUnload()
  783. end
  784. end
  785.  
  786. local function markBlock()
  787. blocksDone = blocksDone + 1
  788. maintenance(false)
  789. showProgress(false)
  790. end
  791.  
  792. local function visit(tx, ty, tz)
  793. if bedrockHit then return false end
  794.  
  795. if not goTo(tx, ty, tz) then
  796. return false
  797. end
  798.  
  799. markBlock()
  800. return true
  801. end
  802.  
  803. -- =========================================================
  804. -- OPTIMIERTE MINING-PFADE
  805. -- =========================================================
  806.  
  807. local function visitPlaneOptimized(tx, yMin, yMax, zMin, zMax, reverseY)
  808. -- Optimierte Flaeche bei festem x.
  809. -- Die Turtle laeuft in einer Schlange, damit sie nicht staendig zurueckfaehrt.
  810.  
  811. local yStart, yEnd, yStep
  812.  
  813. if reverseY then
  814. yStart = yMax
  815. yEnd = yMin
  816. yStep = -1
  817. else
  818. yStart = yMin
  819. yEnd = yMax
  820. yStep = 1
  821. end
  822.  
  823. local row = 0
  824. local ty = yStart
  825.  
  826. while true do
  827. local reverseZ = (row % 2 == 1)
  828.  
  829. if reverseZ then
  830. for tz = zMax, zMin, -1 do
  831. if not visit(tx, ty, tz) then return false end
  832. end
  833. else
  834. for tz = zMin, zMax do
  835. if not visit(tx, ty, tz) then return false end
  836. end
  837. end
  838.  
  839. if ty == yEnd then break end
  840.  
  841. ty = ty + yStep
  842. row = row + 1
  843. end
  844.  
  845. return true
  846. end
  847.  
  848. local function mineTunnel1x2(len)
  849. blocksTarget = len * 2
  850.  
  851. for tx = 1, len do
  852. if bedrockHit then break end
  853.  
  854. if tx % 2 == 1 then
  855. visit(tx, 0, 0)
  856. visit(tx, 0, -1)
  857. else
  858. visit(tx, 0, -1)
  859. visit(tx, 0, 0)
  860. end
  861. end
  862. end
  863.  
  864. local function mineTunnel(size, len)
  865. -- 3x3 oder 5x5 Tunnel.
  866. -- Pro x-Ebene wird eine Schlangenflaeche abgefahren.
  867. -- Zwischen Ebenen bleibt die Turtle am letzten Punkt und geht direkt in die naechste Ebene.
  868. local radius = math.floor(size / 2)
  869. local yMin = -radius
  870. local yMax = radius
  871. local zMin = -(size - 1)
  872. local zMax = 0
  873.  
  874. blocksTarget = len * size * size
  875.  
  876. for tx = 1, len do
  877. if bedrockHit then break end
  878. visitPlaneOptimized(tx, yMin, yMax, zMin, zMax, tx % 2 == 0)
  879. end
  880. end
  881.  
  882. local function mineQuarry(len, wid, dep, sign)
  883. -- Quader nach vorne, zur Seite und nach unten.
  884. -- Jede Ebene wird in einer X/Y-Schlange abgelaufen.
  885. -- Zwischen den Ebenen startet die naechste Ebene nahe am letzten Punkt.
  886. blocksTarget = len * wid * dep
  887.  
  888. for level = 0, dep - 1 do
  889. if bedrockHit then break end
  890.  
  891. print("")
  892. print("Ebene " .. (level + 1) .. " / " .. dep)
  893.  
  894. local yStart, yEnd, yStep
  895.  
  896. if level % 2 == 0 then
  897. yStart = 0
  898. yEnd = wid - 1
  899. yStep = 1
  900. else
  901. yStart = wid - 1
  902. yEnd = 0
  903. yStep = -1
  904. end
  905.  
  906. local row = 0
  907. local yi = yStart
  908.  
  909. while true do
  910. local targetY = yi * sign
  911. local reverseX = (row % 2 == 1)
  912.  
  913. if reverseX then
  914. for tx = len, 1, -1 do
  915. if not visit(tx, targetY, level) then return end
  916. end
  917. else
  918. for tx = 1, len do
  919. if not visit(tx, targetY, level) then return end
  920. end
  921. end
  922.  
  923. if yi == yEnd then break end
  924.  
  925. yi = yi + yStep
  926. row = row + 1
  927. end
  928. end
  929. end
  930.  
  931. local function mineRoom(len, wid, hei, sign)
  932. -- Raum nach vorne, zur Seite und nach oben.
  933. -- z ist negativ, weil oben.
  934. blocksTarget = len * wid * hei
  935.  
  936. for h = 0, hei - 1 do
  937. local targetZ = -h
  938.  
  939. print("")
  940. print("Hoehe " .. (h + 1) .. " / " .. hei)
  941.  
  942. local yStart, yEnd, yStep
  943.  
  944. if h % 2 == 0 then
  945. yStart = 0
  946. yEnd = wid - 1
  947. yStep = 1
  948. else
  949. yStart = wid - 1
  950. yEnd = 0
  951. yStep = -1
  952. end
  953.  
  954. local row = 0
  955. local yi = yStart
  956.  
  957. while true do
  958. local targetY = yi * sign
  959. local reverseX = (row % 2 == 1)
  960.  
  961. if reverseX then
  962. for tx = len, 1, -1 do
  963. if not visit(tx, targetY, targetZ) then return end
  964. end
  965. else
  966. for tx = 1, len do
  967. if not visit(tx, targetY, targetZ) then return end
  968. end
  969. end
  970.  
  971. if yi == yEnd then break end
  972.  
  973. yi = yi + yStep
  974. row = row + 1
  975. end
  976. end
  977. end
  978.  
  979. local function mineStaircase(dep, wid)
  980. -- Treppe nach unten.
  981. -- Pro Stufe: 1 nach vorne, 1 nach unten.
  982. -- Hoehe 3, damit man selbst bequem laufen kann.
  983. local left = math.floor((wid - 1) / 2)
  984. local right = wid - 1 - left
  985.  
  986. blocksTarget = dep * wid * 3
  987.  
  988. for step = 1, dep do
  989. if bedrockHit then break end
  990.  
  991. local yMin = -left
  992. local yMax = right
  993.  
  994. -- Um die Stufe herum 3 hoch frei machen.
  995. -- zBottom ist die aktuelle Stufe, zTop zwei Bloecke darueber.
  996. local zTop = step - 2
  997. local zBottom = step
  998.  
  999. visitPlaneOptimized(step, yMin, yMax, zTop, zBottom, step % 2 == 0)
  1000. end
  1001. end
  1002.  
  1003. local function mineShaft(size, dep)
  1004. -- Schacht startet VOR der Turtle, damit die Kiste hinter der Turtle sicher bleibt.
  1005. -- 1x1: x=1,y=0
  1006. -- 3x3: x=1..3,y=-1..1
  1007. local radius = math.floor(size / 2)
  1008. local yMin = -radius
  1009. local yMax = radius
  1010. local xMin = 1
  1011. local xMax = size
  1012.  
  1013. blocksTarget = size * size * dep
  1014.  
  1015. for level = 1, dep do
  1016. if bedrockHit then break end
  1017.  
  1018. print("")
  1019. print("Schacht-Ebene " .. level .. " / " .. dep)
  1020.  
  1021. local reverseX = level % 2 == 0
  1022.  
  1023. if reverseX then
  1024. for tx = xMax, xMin, -1 do
  1025. visitPlaneOptimized(tx, yMin, yMax, level, level, tx % 2 == 0)
  1026. end
  1027. else
  1028. for tx = xMin, xMax do
  1029. visitPlaneOptimized(tx, yMin, yMax, level, level, tx % 2 == 0)
  1030. end
  1031. end
  1032. end
  1033. end
  1034.  
  1035. local function mineStripMine(mainLen, branchLen, spacing)
  1036. -- Haupttunnel 1x2.
  1037. -- Alle X Bloecke Seitenarme links und rechts, ebenfalls 1x2.
  1038. blocksTarget = mainLen * 2 + math.floor(mainLen / spacing) * branchLen * 4
  1039.  
  1040. for tx = 1, mainLen do
  1041. if tx % 2 == 1 then
  1042. visit(tx, 0, 0)
  1043. visit(tx, 0, -1)
  1044. else
  1045. visit(tx, 0, -1)
  1046. visit(tx, 0, 0)
  1047. end
  1048.  
  1049. if tx % spacing == 0 then
  1050. local saveX = tx
  1051.  
  1052. -- rechter Seitenarm
  1053. for by = 1, branchLen do
  1054. visit(saveX, by, 0)
  1055. visit(saveX, by, -1)
  1056. end
  1057.  
  1058. -- zur Mitte zurueck
  1059. goTo(saveX, 0, -1)
  1060.  
  1061. -- linker Seitenarm
  1062. for by = -1, -branchLen, -1 do
  1063. visit(saveX, by, -1)
  1064. visit(saveX, by, 0)
  1065. end
  1066.  
  1067. -- zur Hauptstrecke zurueck
  1068. goTo(saveX, 0, 0)
  1069. end
  1070. end
  1071. end
  1072.  
  1073. local function mineChunkQuarry(dep)
  1074. mineQuarry(16, 16, dep, 1)
  1075. end
  1076.  
  1077. -- =========================================================
  1078. -- SETUP
  1079. -- =========================================================
  1080.  
  1081. local function checkChestBehind()
  1082. local old = dir
  1083. turnTo(2)
  1084. local has = turtle.detect()
  1085. turnTo(old)
  1086.  
  1087. if not has then
  1088. print("")
  1089. print("Warnung: Hinter der Turtle wurde kein Block erkannt.")
  1090. return yn("Trotzdem starten", false)
  1091. end
  1092.  
  1093. return true
  1094. end
  1095.  
  1096. local function askFuelAndChestFirst()
  1097. drawSlotPlan()
  1098. clear()
  1099.  
  1100. print("=== Schritt 1: Kiste und Fuel ===")
  1101. print("")
  1102.  
  1103. if not yn("Steht die Kiste direkt hinter der Turtle", nil) then
  1104. print("Bitte Kiste direkt hinter die Turtle stellen und neu starten.")
  1105. return false
  1106. end
  1107.  
  1108. if not yn("Ist Fuel in Slot 2", nil) then
  1109. print("Bitte Fuel in Slot 2 legen und neu starten.")
  1110. return false
  1111. end
  1112.  
  1113. if not checkChestBehind() then
  1114. print("Abbruch.")
  1115. return false
  1116. end
  1117.  
  1118. return true
  1119. end
  1120.  
  1121. local function chooseProgram()
  1122. clear()
  1123. print("=== Schritt 2: Programm waehlen ===")
  1124. print("")
  1125.  
  1126. mode = askChoice("Was soll die Turtle machen?", {
  1127. { label = "Tunnel 1x2, fragt nur Laenge", value = "tunnel_1x2" },
  1128. { label = "Tunnel 3x3, fragt nur Laenge", value = "tunnel_3x3" },
  1129. { label = "Tunnel 5x5, fragt nur Laenge", value = "tunnel_5x5" },
  1130. { label = "Treppe nach unten, fragt Tiefe und Breite", value = "staircase" },
  1131. { label = "Raum ausheben", value = "room" },
  1132. { label = "Schacht 1x1 nach unten", value = "shaft_1x1" },
  1133. { label = "Schacht 3x3 nach unten", value = "shaft_3x3" },
  1134. { label = "Stripmine mit Seitenarmen", value = "stripmine" },
  1135. { label = "Chunk Quarry 16x16", value = "chunk" },
  1136. { label = "Eigenen Bereich: Laenge, Breite, Tiefe", value = "quarry" },
  1137. }, 10)
  1138. end
  1139.  
  1140. local function askProgramQuestions()
  1141. clear()
  1142. print("=== Schritt 3: Masse ===")
  1143. print("")
  1144.  
  1145. if mode == "tunnel_1x2" then
  1146. length = askNumber("Tunnel-Laenge", 1)
  1147.  
  1148. elseif mode == "tunnel_3x3" then
  1149. length = askNumber("Tunnel-Laenge", 1)
  1150.  
  1151. elseif mode == "tunnel_5x5" then
  1152. length = askNumber("Tunnel-Laenge", 1)
  1153.  
  1154. elseif mode == "staircase" then
  1155. depth = askNumber("Treppen-Tiefe nach unten", 1)
  1156. width = askNumber("Treppen-Breite", 1, 3)
  1157.  
  1158. elseif mode == "room" then
  1159. length = askNumber("Raum-Laenge nach vorne", 1)
  1160. sideSign = askChoice("Raum-Breite nach rechts oder links?", {
  1161. { label = "rechts", value = 1 },
  1162. { label = "links", value = -1 },
  1163. }, 1)
  1164. width = askNumber("Raum-Breite", 1)
  1165. height = askNumber("Raum-Hoehe nach oben", 1, 3)
  1166.  
  1167. elseif mode == "shaft_1x1" then
  1168. depth = askNumber("Schacht-Tiefe", 1)
  1169.  
  1170. elseif mode == "shaft_3x3" then
  1171. depth = askNumber("Schacht-Tiefe", 1)
  1172.  
  1173. elseif mode == "stripmine" then
  1174. length = askNumber("Haupttunnel-Laenge", 1)
  1175. width = askNumber("Seitenarm-Laenge", 1, 16)
  1176. depth = askNumber("Abstand zwischen Seitenarmen", 1, 4)
  1177.  
  1178. elseif mode == "chunk" then
  1179. depth = askNumber("Chunk-Quarry-Tiefe", 1)
  1180.  
  1181. elseif mode == "quarry" then
  1182. length = askNumber("Laenge nach vorne", 1)
  1183. sideSign = askChoice("Breite nach rechts oder links?", {
  1184. { label = "rechts", value = 1 },
  1185. { label = "links", value = -1 },
  1186. }, 1)
  1187. width = askNumber("Breite", 1)
  1188. depth = askNumber("Tiefe nach unten", 1)
  1189. end
  1190. end
  1191.  
  1192. local function configureFilters()
  1193. clear()
  1194. print("=== Schritt 4: Material-Filter ===")
  1195. print("")
  1196.  
  1197. cfg.filterMode = askChoice("Material-Filter:", {
  1198. { label = "Alles behalten", value = "all" },
  1199. { label = "Blacklist: nur Trash wegwerfen", value = "blacklist" },
  1200. { label = "Whitelist: nur wichtige Items behalten", value = "whitelist" },
  1201. }, 2)
  1202.  
  1203. if cfg.filterMode == "blacklist" then
  1204. print("")
  1205. print("Trash-Liste konfigurieren:")
  1206. TRASH_ITEMS["minecraft:cobblestone"] = yn("Cobblestone wegwerfen", true)
  1207. TRASH_ITEMS["minecraft:cobbled_deepslate"] = yn("Cobbled Deepslate wegwerfen", true)
  1208. TRASH_ITEMS["minecraft:gravel"] = yn("Gravel wegwerfen", true)
  1209. TRASH_ITEMS["minecraft:sand"] = yn("Sand wegwerfen", true)
  1210. TRASH_ITEMS["minecraft:dirt"] = yn("Dirt wegwerfen", true)
  1211. TRASH_ITEMS["minecraft:flint"] = yn("Flint wegwerfen", true)
  1212.  
  1213. if yn("Granite wegwerfen", false) then add(TRASH_ITEMS, "minecraft:granite") end
  1214. if yn("Diorite wegwerfen", false) then add(TRASH_ITEMS, "minecraft:diorite") end
  1215.  
  1216. TRASH_ITEMS["minecraft:andesite"] = false
  1217. TRASH_ITEMS["minecraft:tuff"] = false
  1218.  
  1219. print("")
  1220. print("Andesite und Tuff werden gesammelt.")
  1221. pause()
  1222.  
  1223. elseif cfg.filterMode == "whitelist" then
  1224. print("")
  1225. print("Whitelist aktiv: Nur Items auf der Sammelliste bleiben im Inventar.")
  1226.  
  1227. if yn("Andesite sammeln", true) then add(KEEP_ITEMS, "minecraft:andesite") end
  1228. if yn("Tuff sammeln", true) then add(KEEP_ITEMS, "minecraft:tuff") end
  1229. if yn("Granite sammeln", false) then add(KEEP_ITEMS, "minecraft:granite") end
  1230. if yn("Diorite sammeln", false) then add(KEEP_ITEMS, "minecraft:diorite") end
  1231. if yn("Cobblestone sammeln", false) then add(KEEP_ITEMS, "minecraft:cobblestone") end
  1232. if yn("Cobbled Deepslate sammeln", false) then add(KEEP_ITEMS, "minecraft:cobbled_deepslate") end
  1233. end
  1234. end
  1235.  
  1236. local function configureAutomation()
  1237. clear()
  1238. print("=== Schritt 5: Automatik / Geschwindigkeit ===")
  1239. print("")
  1240.  
  1241. cfg.throwTrashDown = yn("Trash direkt nach unten werfen", true)
  1242. cfg.stackItems = yn("Items regelmaessig zusammenstacken", true)
  1243.  
  1244. print("")
  1245. cfg.lowFuelReturn = yn("Bei niedrigem Fuel automatisch zur Kiste", true)
  1246. cfg.reserveFuel = askNumber("Fuel-Reserve", 10, 200)
  1247.  
  1248. print("")
  1249. print("Hinweis: Brueckenmodus setzt nur dann Bloecke aus Slot 1,")
  1250. print("wenn unter der Turtle Luft ist.")
  1251. cfg.bridgeMode = yn("Bruecken-/Bodenmodus mit Slot 1 aktivieren", false)
  1252.  
  1253. print("")
  1254. cfg.fluidMode = askChoice("Lava/Wasser-Verhalten:", {
  1255. { label = "Stoppen und auf Enter warten", value = "stop" },
  1256. { label = "Mit Block aus Slot 1 abdichten", value = "seal" },
  1257. { label = "Ignorieren", value = "ignore" },
  1258. }, 1)
  1259.  
  1260. cfg.bedrockStop = yn("Bei Bedrock automatisch stoppen", true)
  1261.  
  1262. print("")
  1263. cfg.maintenanceEvery = askNumber("Trash/Stack-Check alle wie viele Bloecke", 1, 10)
  1264. cfg.progressEvery = askNumber("Fortschritt alle wie viele Bloecke anzeigen", 1, 50)
  1265. end
  1266.  
  1267. local function initialRefuel()
  1268. if fuelUnlimited() then
  1269. print("Fuel ist unlimited.")
  1270. return true
  1271. end
  1272.  
  1273. print("Fuel-Level: " .. tostring(fuel()))
  1274. topUpFuel()
  1275. print("Fuel-Level nach Auto-Refuel: " .. tostring(fuel()))
  1276.  
  1277. if fuel() <= 2 then
  1278. print("Zu wenig Fuel. Lege Fuel in Slot 2.")
  1279. return false
  1280. end
  1281.  
  1282. return true
  1283. end
  1284.  
  1285. local function showSummary()
  1286. clear()
  1287. print("=== Schritt 6: Zusammenfassung ===")
  1288. print("")
  1289. print("Modus: " .. mode)
  1290.  
  1291. if mode == "tunnel_1x2" or mode == "tunnel_3x3" or mode == "tunnel_5x5" then
  1292. print("Laenge: " .. length)
  1293. elseif mode == "staircase" then
  1294. print("Tiefe: " .. depth)
  1295. print("Breite: " .. width)
  1296. elseif mode == "room" then
  1297. print("Laenge: " .. length)
  1298. print("Breite: " .. width)
  1299. print("Hoehe: " .. height)
  1300. print("Richtung: " .. (sideSign == 1 and "rechts" or "links"))
  1301. elseif mode == "shaft_1x1" or mode == "shaft_3x3" then
  1302. print("Tiefe: " .. depth)
  1303. elseif mode == "stripmine" then
  1304. print("Haupttunnel-Laenge: " .. length)
  1305. print("Seitenarm-Laenge: " .. width)
  1306. print("Abstand: " .. depth)
  1307. elseif mode == "chunk" then
  1308. print("Chunk: 16x16")
  1309. print("Tiefe: " .. depth)
  1310. elseif mode == "quarry" then
  1311. print("Laenge: " .. length)
  1312. print("Breite: " .. width)
  1313. print("Tiefe: " .. depth)
  1314. print("Richtung: " .. (sideSign == 1 and "rechts" or "links"))
  1315. end
  1316.  
  1317. print("")
  1318. print("Slot 1: Bau-/Auffuellmaterial")
  1319. print("Slot 2: Fuel")
  1320. print("Slots 3-16: Items")
  1321. print("")
  1322. print("Filter: " .. cfg.filterMode)
  1323. print("Trash nach unten: " .. tostring(cfg.throwTrashDown))
  1324. print("Stacken: " .. tostring(cfg.stackItems))
  1325. print("Fuel-Reserve: " .. cfg.reserveFuel)
  1326. print("Brueckenmodus: " .. tostring(cfg.bridgeMode))
  1327. print("Fluessigkeiten: " .. cfg.fluidMode)
  1328. print("Bedrock-Stopp: " .. tostring(cfg.bedrockStop))
  1329. print("Auto-Crafting: aus")
  1330. print("")
  1331. end
  1332.  
  1333. local function setup()
  1334. setupDefaultLists()
  1335.  
  1336. if not askFuelAndChestFirst() then return false end
  1337.  
  1338. chooseProgram()
  1339. askProgramQuestions()
  1340. configureFilters()
  1341. configureAutomation()
  1342. showSummary()
  1343.  
  1344. return yn("Starten", nil)
  1345. end
  1346.  
  1347. -- =========================================================
  1348. -- START
  1349. -- =========================================================
  1350.  
  1351. local function runSelectedMode()
  1352. startClock = os.clock()
  1353.  
  1354. if mode == "tunnel_1x2" then
  1355. mineTunnel1x2(length)
  1356.  
  1357. elseif mode == "tunnel_3x3" then
  1358. mineTunnel(3, length)
  1359.  
  1360. elseif mode == "tunnel_5x5" then
  1361. mineTunnel(5, length)
  1362.  
  1363. elseif mode == "staircase" then
  1364. mineStaircase(depth, width)
  1365.  
  1366. elseif mode == "room" then
  1367. mineRoom(length, width, height, sideSign)
  1368.  
  1369. elseif mode == "shaft_1x1" then
  1370. mineShaft(1, depth)
  1371.  
  1372. elseif mode == "shaft_3x3" then
  1373. mineShaft(3, depth)
  1374.  
  1375. elseif mode == "stripmine" then
  1376. mineStripMine(length, width, depth)
  1377.  
  1378. elseif mode == "chunk" then
  1379. mineChunkQuarry(depth)
  1380.  
  1381. elseif mode == "quarry" then
  1382. mineQuarry(length, width, depth, sideSign)
  1383. end
  1384. end
  1385.  
  1386. if setup() then
  1387. clear()
  1388. print("Starte optimiertes Mining-Programm...")
  1389. print("")
  1390.  
  1391. if initialRefuel() then
  1392. runSelectedMode()
  1393.  
  1394. print("")
  1395. print("Mining beendet. Fahre zur Kiste...")
  1396. goTo(0, 0, 0)
  1397. dropIntoChest()
  1398. showProgress(true)
  1399.  
  1400. print("")
  1401. print("=== Fertig ===")
  1402. print("Modus: " .. mode)
  1403. print("Bloecke bearbeitet: " .. blocksDone .. " / " .. blocksTarget)
  1404. print("Entladungen: " .. unloads)
  1405. print("Trash gedroppt: ca. " .. trashDropped .. " Items")
  1406. print("Fuel uebrig: " .. tostring(fuel()))
  1407. print("Laufzeit: " .. math.floor(os.clock() - startClock) .. " Sekunden")
  1408.  
  1409. if bedrockHit then
  1410. print("Hinweis: Bedrock wurde erreicht.")
  1411. end
  1412. else
  1413. print("Abbruch wegen Fuel.")
  1414. end
  1415. else
  1416. print("Abbruch.")
  1417. end
Add Comment
Please, Sign In to add comment