-- Einstellungen für Graben-Dimensionen local diggingLength = 10 -- Standard-Laenge des Grabens local diggingWidth = 1 -- Standard-Breite des Grabens local diggingDepth = 1 -- Standard-Tiefe des Grabens local refuelAutomatically = true -- Treibstoff automatisch auffuellen local autoDeposit = true -- Items automatisch ablegen local digDirection = "forward" -- Standard Grabrichtung (forward, down, up, back) local currentLanguage = "de" -- Standard-Sprache Deutsch local chestBlockNames = {"minecraft:chest", "sophisticatedstorage:storage"} -- Kisten von Sophisticated Storage local currentChoice = 1 -- Aktuelle Auswahl im Menü local menuOptions = {"Start", "Einstellungen", "Sprache", "Beenden"} -- Menü-Optionen local directions = {"forward", "back", "up", "down"} local directionNames = {"Vorwaerts", "Rueckwaerts", "Nach Oben", "Nach Unten"} -- Variablen zur Positionsspeicherung local position = {x = 0, y = 0, z = 0} local startFacing = "forward" -- Funktion zum Finden eines Wertes in einer Tabelle function tableFind(tbl, value) for i, v in ipairs(tbl) do if v == value then return i end end return nil end -- Funktion zum Anzeigen des Menüs function printMenu() term.clear() term.setCursorPos(1, 1) print("Bitte waehle eine Option:") -- Anzeige des Menüs mit Pfeiltasten-Navigation for i, option in ipairs(menuOptions) do if i == currentChoice then term.setBackgroundColor(colors.gray) term.setTextColor(colors.white) else term.setBackgroundColor(colors.white) term.setTextColor(colors.black) end print(option) end end -- Funktion zur Auswahl der Grabrichtung function setDirection() clearScreen() print("Waehle eine Richtung:") print("1. Vorwaerts") print("2. Rueckwaerts") print("3. Nach Oben") print("4. Nach Unten") local choice = read() if choice == "1" then digDirection = "forward" elseif choice == "2" then digDirection = "back" elseif choice == "3" then digDirection = "up" elseif choice == "4" then digDirection = "down" end end -- Funktion zum Löschen des Bildschirms function clearScreen() term.clear() term.setCursorPos(1, 1) end -- Funktion zum Navigieren durch das Menü mit Pfeiltasten function navigateMenu() local event, key = os.pullEvent("key") -- Auf Tastatureingaben warten if key == keys.up then currentChoice = currentChoice - 1 if currentChoice < 1 then currentChoice = #menuOptions end elseif key == keys.down then currentChoice = currentChoice + 1 if currentChoice > #menuOptions then currentChoice = 1 end elseif key == keys.enter then executeMenuOption(currentChoice) end end -- Funktion zur Ausführung der ausgewählten Option function executeMenuOption(choice) if choice == 1 then startMining() elseif choice == 2 then settingsMenu() elseif choice == 3 then setLanguage() elseif choice == 4 then print("Programm wird beendet.") isRunning = false end end -- Menü zur Sprachwahl function setLanguage() clearScreen() print("Waehle eine Sprache:") print("1. Deutsch") print("2. Englisch") local choice = read() if choice == "1" then currentLanguage = "de" elseif choice == "2" then currentLanguage = "en" end end -- Einstellungen-Menü für Graben function settingsMenu() clearScreen() print("Einstellungen:") print("1. Laenge des Grabens: " .. diggingLength) print("2. Breite des Grabens: " .. diggingWidth) print("3. Tiefe des Grabens: " .. diggingDepth) print("4. Automatisches Auftanken: " .. (refuelAutomatically and "Aktiviert" or "Deaktiviert")) print("5. Automatisches Ablegen: " .. (autoDeposit and "Aktiviert" or "Deaktiviert")) print("6. Grabrichtung: " .. directionNames[tableFind(directions, digDirection)]) print("7. Zurueck") local choice = read() if choice == "1" then print("Neue Laenge:") diggingLength = tonumber(read()) elseif choice == "2" then print("Neue Breite:") diggingWidth = tonumber(read()) elseif choice == "3" then print("Neue Tiefe:") diggingDepth = tonumber(read()) elseif choice == "4" then refuelAutomatically = not refuelAutomatically elseif choice == "5" then autoDeposit = not autoDeposit elseif choice == "6" then setDirection() elseif choice == "7" then return end settingsMenu() end -- Funktion zum Auffüllen des Treibstoffs function refuelIfNeeded() -- Prüfen, ob der Treibstoff zu niedrig ist if turtle.getFuelLevel() < 100 then print("Treibstoff ist niedrig, versuche zu tanken...") if not turtle.refuel(1) then -- 1 bedeutet, dass 1 Treibstoffblock verwendet wird print("Kein Treibstoff gefunden! Bitte fügen Sie Treibstoff hinzu.") return false -- Kein Treibstoff gefunden, beenden end print("Treibstoff wurde aufgefüllt!") end return true -- Treibstoff war ausreichend oder erfolgreich aufgefüllt end -- Graben-Prozess, bei dem die Turtle das Loch in die festgelegte Richtung graebt function startMining() -- Speichern der Startposition position.x, position.y, position.z = 0, 0, 0 startFacing = "forward" clearScreen() print("Mining gestartet!") for depth = 1, diggingDepth do for width = 1, diggingWidth do for length = 1, diggingLength do -- Automatisches Auffüllen von Treibstoff, wenn aktiviert if refuelAutomatically then if not refuelIfNeeded() then return -- Beenden, wenn kein Treibstoff gefunden werden kann end end -- Automatisches Ablegen, wenn aktiviert if autoDeposit then autoDepositItems() end -- Graben je nach gewaelter Richtung if digDirection == "forward" then turtle.dig() turtle.forward() position.x = position.x + 1 elseif digDirection == "down" then turtle.digDown() turtle.down() position.y = position.y - 1 elseif digDirection == "up" then turtle.digUp() turtle.up() position.y = position.y + 1 elseif digDirection == "back" then turtle.digBack() turtle.back() position.x = position.x - 1 end -- Wenn Inventar voll ist, zurück zum Startpunkt if isInventoryFull() then print("Inventar voll. Zurueck zum Start...") returnToStart() autoDepositItems() end end end end print("Mining abgeschlossen!") end -- Funktion zum Zurückfahren zum Startpunkt function returnToStart() -- Berechnung der Rückfahrt zur Startposition while position.x ~= 0 or position.y ~= 0 or position.z ~= 0 do if position.x > 0 then turtle.back() position.x = position.x - 1 elseif position.x < 0 then turtle.forward() position.x = position.x + 1 end if position.y > 0 then turtle.down() position.y = position.y - 1 elseif position.y < 0 then turtle.up() position.y = position.y + 1 end end turtle.turnLeft() -- Wir nehmen an, dass die Turtle nach links drehen muss, um wieder zur Startausrichtung zu kommen turtle.forward() end -- Überprüft, ob das Inventar voll ist function isInventoryFull() for i = 1, 16 do if turtle.getItemCount(i) == 0 then return false end end return true end -- Funktion für das automatische Ablegen von Items function autoDepositItems() local success, data = turtle.inspect() if success and isChestValid(data.name) then print("Kiste vor der Turtle gefunden! Items werden abgelegt...") for i = 1, 16 do local item = turtle.getItemDetail(i) if item then turtle.select(i) turtle.drop() end end return true end -- Kisten auch oben oder unten finden local successUp, dataUp = turtle.inspectUp() local successDown, dataDown = turtle.inspectDown() if successUp and isChestValid(dataUp.name) then print("Kiste oben gefunden! Items werden abgelegt...") for i = 1, 16 do local item = turtle.getItemDetail(i) if item then turtle.select(i) turtle.dropUp() end end return true elseif successDown and isChestValid(dataDown.name) then print("Kiste unten gefunden! Items werden abgelegt...") for i = 1, 16 do local item = turtle.getItemDetail(i) if item then turtle.select(i) turtle.dropDown() end end return true end return false end -- Prüft, ob der Block eine Kiste ist function isChestValid(name) for _, chestName in ipairs(chestBlockNames) do if name == chestName then return true end end return false end -- Hauptschleife while true do printMenu() navigateMenu() end