Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local move = require("move")
- local inspect = require("inspect")
- local collectLava = require("collectLava")
- function saveData(fileName, data)
- local file = fs.open(fileName, "w") -- Datei im Schreibmodus öffnen
- if file then
- file.write(textutils.serialize(data)) -- Tabelle in die Datei schreiben
- file.close()
- print("Daten gespeichert in:", fileName)
- else
- print("Fehler beim Speichern der Daten.")
- end
- end
- function loadData(fileName)
- if fs.exists(fileName) then
- local file = fs.open(fileName, "r") -- Datei im Lesemodus öffnen
- if file then
- local content = file.readAll()
- file.close()
- return textutils.unserialize(content) -- String in Tabelle umwandeln
- end
- else
- print("Datei nicht gefunden:", fileName)
- end
- return nil -- Standardwert, wenn Datei nicht existiert
- end
- local function selectBucket()
- for i=1, 16, 1 do
- local count = turtle.getItemCount(i)
- if count > 0 then
- turtle.select(i)
- local itemDetail = turtle.getItemDetail()
- if itemDetail then
- if itemDetail.name == "minecraft:bucket" then
- return true
- end
- end
- end
- end
- return false
- end
- local function moreEmpty()
- for i=1, 16, 1 do
- local count = turtle.getItemCount(i)
- if count == 0 then
- return true
- end
- end
- return false
- end
- local function tryOffloadItems()
- local bChest = inspect.Forward({"minecraft:chest"})
- if not bChest then
- return
- end
- for i=1, 16, 1 do
- local numItems = turtle.getItemCount(i)
- if numItems > 0 then
- turtle.select(i)
- local itemDetail = turtle.getItemDetail()
- if itemDetail then
- if not (itemDetail.name == "minecraft:bucket") then
- turtle.drop()
- end
- end
- end
- end
- end
- function LavaTilBottom()
- local cnt = 0
- local bFull = false
- while not turtle.detectDown() do
- if not moreEmpty() then
- if selectBucket() then
- if not (turtle.getItemCount(turtle.getSelectedSlot()) == 1) then
- bFull = true
- break
- end
- else
- bFull = true
- break
- end
- end
- if selectBucket() then
- turtle.placeDown()
- move.Down()
- cnt = cnt + 1
- else
- bFull = true
- break
- end
- end
- while cnt > 0 do
- move.Up()
- cnt = cnt - 1
- end
- return bFull
- end
- local maxDistance = 28
- local cnt = 0
- local loadedData = loadData("lastPosition.txt")
- if loadedData then
- while cnt < tonumber(loadedData.lastPosition) do
- turtle.forward()
- cnt = cnt + 1
- end
- end
- local bFinishedLine = false
- while (not LavaTilBottom()) and maxDistance > cnt do
- if turtle.forward() then
- cnt = cnt + 1
- else
- local dataToSave = { lastPosition = 0 }
- saveData("lastPosition.txt", dataToSave)
- break
- end
- end
- if not bFinishedLine then
- local dataToSave = { lastPosition = cnt }
- saveData("lastPosition.txt", dataToSave)
- end
- turtle.turnLeft()
- turtle.turnLeft()
- while cnt > 0 do
- turtle.forward()
- cnt = cnt - 1
- end
- tryOffloadItems()
- turtle.turnLeft()
- turtle.turnLeft()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement