chico0991

Buddeln

Sep 2nd, 2025 (edited)
355
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.88 KB | Gaming | 0 0
  1. -- mining_menu.lua
  2. local settings = {
  3.   lang = "de",
  4.   length = 10,
  5.   width = 1,
  6.   depth = 10,
  7.   autoRefuel = true,
  8.   autoDump = true
  9. }
  10. local function loadSettings()
  11.   if fs.exists("mining_config") then
  12.     local f = fs.open("mining_config", "r")
  13.     settings = textutils.unserialize(f.readAll())
  14.     f.close()
  15.   end
  16. end
  17.  
  18. local function saveSettings()
  19.   local f = fs.open("mining_config", "w")
  20.   f.write(textutils.serialize(settings))
  21.   f.close()
  22. end
  23.  
  24. local texts = {
  25.   ["de"] = {
  26.     start = "Start",
  27.     settings = "Einstellungen",
  28.     language = "Sprache",
  29.     length = "Länge",
  30.     width = "Breite",
  31.     depth = "Tiefe",
  32.     refuel = "Autom. Auftanken",
  33.     dump = "In Truhe ablegen",
  34.     back = "Zurück",
  35.     run = "Mining gestartet..."},
  36.   ["en"] = {
  37.     start = "Start",
  38.     settings = "Settings",
  39.     language = "Language",
  40.     length = "Length",
  41.     width = "Width",
  42.     depth = "Depth",
  43.     refuel = "Auto Refuel",
  44.     dump = "Dump to Chest",
  45.     back = "Back",
  46.     run = "Mining started..."
  47.   }
  48. }
  49. local function readNumber(prompt)
  50.   print(prompt)
  51.   local input = read()
  52.   return tonumber(input) or 1
  53. end
  54. local function toggleOption(key)
  55.   settings[key] = not settings[key]
  56. end
  57. local function selectLanguage()
  58.   print("1 - Deutsch")
  59.   print("2 - English")
  60.   local choice = read()
  61.   if choice == "1" then settings.lang = "de"
  62.   elseif choice == "2" then settings.lang = "en"
  63.   end
  64. end
  65. local function showSettings()
  66.   local t = texts[settings.lang]
  67.   while true do
  68.     term.clear()
  69.     print("=== " .. t.settings .. " ===")
  70.     print("1 - " .. t.length .. ": " .. settings.length)
  71.     print("2 - " .. t.width .. ": " .. settings.width)
  72.     print("3 - " .. t.depth .. ": " .. settings.depth)
  73.     print("4 - " .. t.refuel .. ": " .. tostring(settings.autoRefuel))
  74.     print("5 - " .. t.dump .. ": " .. tostring(settings.autoDump))
  75.     print("6 - " .. t.back)
  76.     local choice = read()
  77.     if choice == "1" then settings.length = readNumber(t.length)
  78.     elseif choice == "2" then settings.width = readNumber(t.width)
  79.     elseif choice == "3" then settings.depth = readNumber(t.depth)
  80.     elseif choice == "4" then toggleOption("autoRefuel")
  81.     elseif choice == "5" then toggleOption("autoDump")
  82.     elseif choice == "6" then return
  83.     end
  84.     saveSettings()
  85.   end
  86. end
  87. local function refuelIfNeeded()
  88.   if turtle.getFuelLevel() < 100 and settings.autoRefuel then
  89.     for i = 1, 16 do
  90.       turtle.select(i)
  91.       if turtle.refuel(0) then
  92.         turtle.refuel()
  93.         break
  94.       end
  95.     end
  96.   end
  97. end
  98. local function dumpInventory()
  99.   if not settings.autoDump then return end
  100.   for i = 1, 16 do
  101.     turtle.select(i)
  102.     turtle.drop()
  103.   end
  104. end
  105. local function mine()
  106.   local t = texts[settings.lang]
  107.   term.clear()
  108.   print(t.run)
  109.   for w = 1, settings.width do
  110.     for l = 1, settings.length do
  111.       refuelIfNeeded()
  112.       while turtle.detect() do turtle.dig() end
  113.       turtle.forward()
  114.     end
  115.     if w < settings.width then
  116.       if w % 2 == 1 then
  117.         turtle.turnRight()
  118.         while turtle.detect() do turtle.dig() end
  119.         turtle.forward()
  120.         turtle.turnRight()
  121.       else
  122.         turtle.turnLeft()
  123.         while turtle.detect() do turtle.dig() end
  124.         turtle.forward()
  125.         turtle.turnLeft()
  126.       end
  127.     end
  128.   end
  129.   for d = 1, settings.depth - 1 do
  130.     turtle.digDown()
  131.     turtle.down()
  132.     mine()
  133.   end
  134.   for _ = 1, settings.depth - 1 do
  135.     turtle.up()
  136.   end
  137.   dumpInventory()
  138. end
  139. local function mainMenu()
  140.   loadSettings()
  141.   while true do
  142.     local t = texts[settings.lang]
  143.     term.clear()
  144.     print("=== Mining Turtle ===")
  145.     print("1 - " .. t.start)
  146.     print("2 - " .. t.settings)
  147.     print("3 - " .. t.language)
  148.     local choice = read()
  149.     if choice == "1" then mine()
  150.     elseif choice == "2" then showSettings()
  151.     elseif choice == "3" then selectLanguage()
  152.     end
  153.   end
  154. end
Advertisement
Add Comment
Please, Sign In to add comment