Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local richtung = 0
- function forceForward()
- while not turtle.forward() do
- turtle.dig()
- end
- end
- function saveState(mode)
- local f = io.open("sugar.sav", "w")
- f:write(tostring(mode).."\n")
- f:write(tostring(richtung))
- f:close()
- end
- function init()
- local f = fs.open("sugar.sav", "r")
- local mode = f:readLine()
- local tmpRichtung = f:readLine()
- write(mode)
- write(tmpRichtung)
- f:close()
- if (mode) and (tonumber(mode) == 1) then
- returnToStart()
- else
- if (tmpRichtung) then
- richtung = tonumber(tmpRichtung)
- end
- turtle.select(16)
- if not turtle.compareDown() then
- turtle.back()
- end
- end
- saveState(0)
- end
- function waitForRefuel()
- while turtle.getFuelLevel() < 1000 do
- sleep(0.5)
- end
- end
- function turn()
- if richtung % 4 < 2 then
- turtle.turnRight()
- elseif richtung % 4 <= 3 then
- turtle.turnLeft()
- end
- if richtung < 3 then
- richtung = richtung + 1
- else
- richtung = 0
- end
- saveState(0)
- end
- function returnToStart()
- turtle.select(15)
- while not turtle.compareDown() do
- forceForward()
- end
- for i=1, 14, 1 do
- turtle.select(i)
- turtle.drop()
- end
- turtle.turnRight()
- waitForRefuel()
- richtung = 0
- end
- function go()
- turtle.select(15)
- if (turtle.compare()) then
- turtle.turnRight()
- saveState(1)
- returnToStart()
- saveState(0)
- end
- turtle.select(16)
- if (turtle.compare()) or not (turtle.detect()) then
- turtle.dig()
- if (turtle.forward()) then
- if not turtle.compareDown() then
- turtle.back()
- turn()
- go()
- end
- else
- turn()
- go()
- end
- else
- turn()
- go()
- end
- end
- init()
- while true do
- go()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement