Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- mining_menu.lua
- local settings = {
- lang = "de",
- length = 10,
- width = 1,
- depth = 10,
- autoRefuel = true,
- autoDump = true
- }
- local function loadSettings()
- if fs.exists("mining_config") then
- local f = fs.open("mining_config", "r")
- settings = textutils.unserialize(f.readAll())
- f.close()
- end
- end
- local function saveSettings()
- local f = fs.open("mining_config", "w")
- f.write(textutils.serialize(settings))
- f.close()
- end
- local texts = {
- ["de"] = {
- start = "Start",
- settings = "Einstellungen",
- language = "Sprache",
- length = "Länge",
- width = "Breite",
- depth = "Tiefe",
- refuel = "Autom. Auftanken",
- dump = "In Truhe ablegen",
- back = "Zurück",
- run = "Mining gestartet..."},
- ["en"] = {
- start = "Start",
- settings = "Settings",
- language = "Language",
- length = "Length",
- width = "Width",
- depth = "Depth",
- refuel = "Auto Refuel",
- dump = "Dump to Chest",
- back = "Back",
- run = "Mining started..."
- }
- }
- local function readNumber(prompt)
- print(prompt)
- local input = read()
- return tonumber(input) or 1
- end
- local function toggleOption(key)
- settings[key] = not settings[key]
- end
- local function selectLanguage()
- print("1 - Deutsch")
- print("2 - English")
- local choice = read()
- if choice == "1" then settings.lang = "de"
- elseif choice == "2" then settings.lang = "en"
- end
- end
- local function showSettings()
- local t = texts[settings.lang]
- while true do
- term.clear()
- print("=== " .. t.settings .. " ===")
- print("1 - " .. t.length .. ": " .. settings.length)
- print("2 - " .. t.width .. ": " .. settings.width)
- print("3 - " .. t.depth .. ": " .. settings.depth)
- print("4 - " .. t.refuel .. ": " .. tostring(settings.autoRefuel))
- print("5 - " .. t.dump .. ": " .. tostring(settings.autoDump))
- print("6 - " .. t.back)
- local choice = read()
- if choice == "1" then settings.length = readNumber(t.length)
- elseif choice == "2" then settings.width = readNumber(t.width)
- elseif choice == "3" then settings.depth = readNumber(t.depth)
- elseif choice == "4" then toggleOption("autoRefuel")
- elseif choice == "5" then toggleOption("autoDump")
- elseif choice == "6" then return
- end
- saveSettings()
- end
- end
- local function refuelIfNeeded()
- if turtle.getFuelLevel() < 100 and settings.autoRefuel then
- for i = 1, 16 do
- turtle.select(i)
- if turtle.refuel(0) then
- turtle.refuel()
- break
- end
- end
- end
- end
- local function dumpInventory()
- if not settings.autoDump then return end
- for i = 1, 16 do
- turtle.select(i)
- turtle.drop()
- end
- end
- local function mine()
- local t = texts[settings.lang]
- term.clear()
- print(t.run)
- for w = 1, settings.width do
- for l = 1, settings.length do
- refuelIfNeeded()
- while turtle.detect() do turtle.dig() end
- turtle.forward()
- end
- if w < settings.width then
- if w % 2 == 1 then
- turtle.turnRight()
- while turtle.detect() do turtle.dig() end
- turtle.forward()
- turtle.turnRight()
- else
- turtle.turnLeft()
- while turtle.detect() do turtle.dig() end
- turtle.forward()
- turtle.turnLeft()
- end
- end
- end
- for d = 1, settings.depth - 1 do
- turtle.digDown()
- turtle.down()
- mine()
- end
- for _ = 1, settings.depth - 1 do
- turtle.up()
- end
- dumpInventory()
- end
- local function mainMenu()
- loadSettings()
- while true do
- local t = texts[settings.lang]
- term.clear()
- print("=== Mining Turtle ===")
- print("1 - " .. t.start)
- print("2 - " .. t.settings)
- print("3 - " .. t.language)
- local choice = read()
- if choice == "1" then mine()
- elseif choice == "2" then showSettings()
- elseif choice == "3" then selectLanguage()
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment