Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local arg1, arg2 = ...
- local move = require("move1")
- local inspect = require("inspect1")
- local collectLava = require("collectLava1")
- local maxDistance = 35
- if arg2 then
- maxDistance = tonumber(arg2)
- end
- local lineEndMove = 1
- if arg1 then
- if tonumber(arg1) == 1 then
- lineEndMove = 1
- elseif tonumber(arg1) == 2 then
- lineEndMove = 2
- else
- lineEndMove = 3
- end
- end
- 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 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 }
- bFinishedLine = true
- saveData("lastPosition.txt", dataToSave)
- print("No more Lava to collect")
- break
- end
- end
- if maxDistance == cnt then
- local dataToSave = { lastPosition = 0 }
- bFinishedLine = true
- saveData("lastPosition.txt", dataToSave)
- print("Collected all the Lava along the way")
- 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()
- if bFinishedLine then
- if lineEndMove == 1 then
- turtle.turnRight()
- turtle.forward()
- turtle.turnLeft()
- elseif lineEndMove == 2 then
- turtle.turnLeft()
- turtle.forward()
- turtle.turnRight()
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement