chico0991

Graben

Sep 2nd, 2025 (edited)
359
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 9.89 KB | Gaming | 0 0
  1. -- Einstellungen für Graben-Dimensionen
  2. local diggingLength = 10  -- Standard-Laenge des Grabens
  3. local diggingWidth = 1    -- Standard-Breite des Grabens
  4. local diggingDepth = 1    -- Standard-Tiefe des Grabens
  5. local refuelAutomatically = true  -- Treibstoff automatisch auffuellen
  6. local autoDeposit = true  -- Items automatisch ablegen
  7. local digDirection = "forward"  -- Standard Grabrichtung (forward, down, up, back)
  8. local currentLanguage = "de"  -- Standard-Sprache Deutsch
  9. local chestBlockNames = {"minecraft:chest", "sophisticatedstorage:storage"} -- Kisten von Sophisticated Storage
  10. local currentChoice = 1  -- Aktuelle Auswahl im Menü
  11. local menuOptions = {"Start", "Einstellungen", "Sprache", "Beenden"}  -- Menü-Optionen
  12. local directions = {"forward", "back", "up", "down"}
  13. local directionNames = {"Vorwaerts", "Rueckwaerts", "Nach Oben", "Nach Unten"}
  14.  
  15. -- Variablen zur Positionsspeicherung
  16. local position = {x = 0, y = 0, z = 0}
  17. local startFacing = "forward"
  18.  
  19. -- Funktion zum Finden eines Wertes in einer Tabelle
  20. function tableFind(tbl, value)
  21.     for i, v in ipairs(tbl) do
  22.         if v == value then
  23.             return i
  24.         end
  25.     end
  26.     return nil
  27. end
  28.  
  29. -- Funktion zum Anzeigen des Menüs
  30. function printMenu()
  31.     term.clear()
  32.     term.setCursorPos(1, 1)
  33.     print("Bitte waehle eine Option:")
  34.  
  35.     -- Anzeige des Menüs mit Pfeiltasten-Navigation
  36.     for i, option in ipairs(menuOptions) do
  37.         if i == currentChoice then
  38.             term.setBackgroundColor(colors.gray)
  39.             term.setTextColor(colors.white)
  40.         else
  41.             term.setBackgroundColor(colors.white)
  42.             term.setTextColor(colors.black)
  43.         end
  44.         print(option)
  45.     end
  46. end
  47.  
  48. -- Funktion zur Auswahl der Grabrichtung
  49. function setDirection()
  50.     clearScreen()
  51.     print("Waehle eine Richtung:")
  52.     print("1. Vorwaerts")
  53.     print("2. Rueckwaerts")
  54.     print("3. Nach Oben")
  55.     print("4. Nach Unten")
  56.     local choice = read()
  57.     if choice == "1" then
  58.         digDirection = "forward"
  59.     elseif choice == "2" then
  60.         digDirection = "back"
  61.     elseif choice == "3" then
  62.         digDirection = "up"
  63.     elseif choice == "4" then
  64.         digDirection = "down"
  65.     end
  66. end
  67.  
  68. -- Funktion zum Löschen des Bildschirms
  69. function clearScreen()
  70.     term.clear()
  71.     term.setCursorPos(1, 1)
  72. end
  73.  
  74. -- Funktion zum Navigieren durch das Menü mit Pfeiltasten
  75. function navigateMenu()
  76.     local event, key = os.pullEvent("key")  -- Auf Tastatureingaben warten
  77.     if key == keys.up then
  78.         currentChoice = currentChoice - 1
  79.         if currentChoice < 1 then
  80.             currentChoice = #menuOptions
  81.         end
  82.     elseif key == keys.down then
  83.         currentChoice = currentChoice + 1
  84.         if currentChoice > #menuOptions then
  85.             currentChoice = 1
  86.         end
  87.     elseif key == keys.enter then
  88.         executeMenuOption(currentChoice)
  89.     end
  90. end
  91.  
  92. -- Funktion zur Ausführung der ausgewählten Option
  93. function executeMenuOption(choice)
  94.     if choice == 1 then
  95.         startMining()
  96.     elseif choice == 2 then
  97.         settingsMenu()
  98.     elseif choice == 3 then
  99.         setLanguage()
  100.     elseif choice == 4 then
  101.         print("Programm wird beendet.")
  102.         isRunning = false
  103.     end
  104. end
  105.  
  106. -- Menü zur Sprachwahl
  107. function setLanguage()
  108.     clearScreen()
  109.     print("Waehle eine Sprache:")
  110.     print("1. Deutsch")
  111.     print("2. Englisch")
  112.     local choice = read()
  113.     if choice == "1" then
  114.         currentLanguage = "de"
  115.     elseif choice == "2" then
  116.         currentLanguage = "en"
  117.     end
  118. end
  119.  
  120. -- Einstellungen-Menü für Graben
  121. function settingsMenu()
  122.     clearScreen()
  123.     print("Einstellungen:")
  124.     print("1. Laenge des Grabens: " .. diggingLength)
  125.     print("2. Breite des Grabens: " .. diggingWidth)
  126.     print("3. Tiefe des Grabens: " .. diggingDepth)
  127.     print("4. Automatisches Auftanken: " .. (refuelAutomatically and "Aktiviert" or "Deaktiviert"))
  128.     print("5. Automatisches Ablegen: " .. (autoDeposit and "Aktiviert" or "Deaktiviert"))
  129.     print("6. Grabrichtung: " .. directionNames[tableFind(directions, digDirection)])
  130.     print("7. Zurueck")
  131.    
  132.     local choice = read()
  133.     if choice == "1" then
  134.         print("Neue Laenge:")
  135.         diggingLength = tonumber(read())
  136.     elseif choice == "2" then
  137.         print("Neue Breite:")
  138.         diggingWidth = tonumber(read())
  139.     elseif choice == "3" then
  140.         print("Neue Tiefe:")
  141.         diggingDepth = tonumber(read())
  142.     elseif choice == "4" then
  143.         refuelAutomatically = not refuelAutomatically
  144.     elseif choice == "5" then
  145.         autoDeposit = not autoDeposit
  146.     elseif choice == "6" then
  147.         setDirection()
  148.     elseif choice == "7" then
  149.         return
  150.     end
  151.     settingsMenu()
  152. end
  153.  
  154. -- Funktion zum Auffüllen des Treibstoffs
  155. function refuelIfNeeded()
  156.     -- Prüfen, ob der Treibstoff zu niedrig ist
  157.     if turtle.getFuelLevel() < 100 then
  158.         print("Treibstoff ist niedrig, versuche zu tanken...")
  159.         if not turtle.refuel(1) then  -- 1 bedeutet, dass 1 Treibstoffblock verwendet wird
  160.             print("Kein Treibstoff gefunden! Bitte fügen Sie Treibstoff hinzu.")
  161.             return false  -- Kein Treibstoff gefunden, beenden
  162.         end
  163.         print("Treibstoff wurde aufgefüllt!")
  164.     end
  165.     return true  -- Treibstoff war ausreichend oder erfolgreich aufgefüllt
  166. end
  167.  
  168. -- Graben-Prozess, bei dem die Turtle das Loch in die festgelegte Richtung graebt
  169. function startMining()
  170.     -- Speichern der Startposition
  171.     position.x, position.y, position.z = 0, 0, 0
  172.     startFacing = "forward"
  173.  
  174.     clearScreen()
  175.     print("Mining gestartet!")
  176.    
  177.     for depth = 1, diggingDepth do
  178.         for width = 1, diggingWidth do
  179.             for length = 1, diggingLength do
  180.                 -- Automatisches Auffüllen von Treibstoff, wenn aktiviert
  181.                 if refuelAutomatically then
  182.                     if not refuelIfNeeded() then
  183.                         return  -- Beenden, wenn kein Treibstoff gefunden werden kann
  184.                     end
  185.                 end
  186.                
  187.                 -- Automatisches Ablegen, wenn aktiviert
  188.                 if autoDeposit then
  189.                     autoDepositItems()
  190.                 end
  191.  
  192.                 -- Graben je nach gewaelter Richtung
  193.                 if digDirection == "forward" then
  194.                     turtle.dig()
  195.                     turtle.forward()
  196.                     position.x = position.x + 1
  197.                 elseif digDirection == "down" then
  198.                     turtle.digDown()
  199.                     turtle.down()
  200.                     position.y = position.y - 1
  201.                 elseif digDirection == "up" then
  202.                     turtle.digUp()
  203.                     turtle.up()
  204.                     position.y = position.y + 1
  205.                 elseif digDirection == "back" then
  206.                     turtle.digBack()
  207.                     turtle.back()
  208.                     position.x = position.x - 1
  209.                 end
  210.  
  211.                 -- Wenn Inventar voll ist, zurück zum Startpunkt
  212.                 if isInventoryFull() then
  213.                     print("Inventar voll. Zurueck zum Start...")
  214.                     returnToStart()
  215.                     autoDepositItems()
  216.                 end
  217.             end
  218.         end
  219.     end
  220.     print("Mining abgeschlossen!")
  221. end
  222.  
  223. -- Funktion zum Zurückfahren zum Startpunkt
  224. function returnToStart()
  225.     -- Berechnung der Rückfahrt zur Startposition
  226.     while position.x ~= 0 or position.y ~= 0 or position.z ~= 0 do
  227.         if position.x > 0 then
  228.             turtle.back()
  229.             position.x = position.x - 1
  230.         elseif position.x < 0 then
  231.             turtle.forward()
  232.             position.x = position.x + 1
  233.         end
  234.        
  235.         if position.y > 0 then
  236.             turtle.down()
  237.             position.y = position.y - 1
  238.         elseif position.y < 0 then
  239.             turtle.up()
  240.             position.y = position.y + 1
  241.         end
  242.     end
  243.     turtle.turnLeft()  -- Wir nehmen an, dass die Turtle nach links drehen muss, um wieder zur Startausrichtung zu kommen
  244.     turtle.forward()
  245. end
  246.  
  247. -- Überprüft, ob das Inventar voll ist
  248. function isInventoryFull()
  249.     for i = 1, 16 do
  250.         if turtle.getItemCount(i) == 0 then
  251.             return false
  252.         end
  253.     end
  254.     return true
  255. end
  256.  
  257. -- Funktion für das automatische Ablegen von Items
  258. function autoDepositItems()
  259.     local success, data = turtle.inspect()
  260.     if success and isChestValid(data.name) then
  261.         print("Kiste vor der Turtle gefunden! Items werden abgelegt...")
  262.         for i = 1, 16 do
  263.             local item = turtle.getItemDetail(i)
  264.             if item then
  265.                 turtle.select(i)
  266.                 turtle.drop()
  267.             end
  268.         end
  269.         return true
  270.     end
  271.  
  272.     -- Kisten auch oben oder unten finden
  273.     local successUp, dataUp = turtle.inspectUp()
  274.     local successDown, dataDown = turtle.inspectDown()
  275.     if successUp and isChestValid(dataUp.name) then
  276.         print("Kiste oben gefunden! Items werden abgelegt...")
  277.         for i = 1, 16 do
  278.             local item = turtle.getItemDetail(i)
  279.             if item then
  280.                 turtle.select(i)
  281.                 turtle.dropUp()
  282.             end
  283.         end
  284.         return true
  285.     elseif successDown and isChestValid(dataDown.name) then
  286.         print("Kiste unten gefunden! Items werden abgelegt...")
  287.         for i = 1, 16 do
  288.             local item = turtle.getItemDetail(i)
  289.             if item then
  290.                 turtle.select(i)
  291.                 turtle.dropDown()
  292.             end
  293.         end
  294.         return true
  295.     end
  296.     return false
  297. end
  298.  
  299. -- Prüft, ob der Block eine Kiste ist
  300. function isChestValid(name)
  301.     for _, chestName in ipairs(chestBlockNames) do
  302.         if name == chestName then
  303.             return true
  304.         end
  305.     end
  306.     return false
  307. end
  308.  
  309. -- Hauptschleife
  310. while true do
  311.     printMenu()
  312.     navigateMenu()
  313. end
  314.  
Advertisement
Add Comment
Please, Sign In to add comment