Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- lavaslot = 15
- chestslot = 16
- comingBack = false
- length = 5
- x,z,orient = 0,0,0
- function start()
- if loadLoc() then
- checkChest()
- fixOrient()
- isComingBack()
- end
- end
- function checkChest()
- if turtle.getItemCount(chestslot) == 0 then
- turtle.select(chestslot)
- turtle.dig()
- end
- turtle.select(1)
- end
- function fixOrient()
- if orient == 1 then
- if x == length and isEven(z) == false then
- right()
- elseif x == length and isEven(z) then
- print("hep")
- forward()
- right()
- end
- if x == 0 and isEven(z) == false then
- forward()
- left()
- elseif x == 0 and isEven(z) then
- left()
- end
- end
- end
- function isComingBack()
- if isEven(z) then
- comingBack = false
- else
- comingBack = true
- end
- end
- function saveLoc()
- h = fs.open("location.dat","w")
- h.writeLine(tostring(x))
- h.writeLine(tostring(z))
- h.writeLine(tostring(orient))
- h.close()
- end
- function loadLoc()
- if fs.exists("location.dat") then
- h = fs.open("location.dat","r")
- x = tonumber(h.readLine())
- z = tonumber(h.readLine())
- orient = tonumber(h.readLine())
- h.close()
- return true
- else
- return false
- end
- end
- function isEven(number)
- if number%2 == 0 then
- return true
- else
- return false
- end
- end
- function grabLava()
- turtle.select(lavaslot)
- if turtle.place() then
- if turtle.refuel() == false then
- turtle.place()
- end
- end
- if turtle.placeUp() then
- if turtle.refuel() == false then
- turtle.placeUp()
- end
- end
- if turtle.placeDown() then
- if turtle.refuel() == false then
- turtle.placeDown()
- end
- end
- turtle.select(1)
- end
- function dig()
- grabLava()
- turtle.digUp()
- turtle.digDown()
- end
- --[[
- function forward()
- while turtle.forward() == false do
- turtle.dig()
- sleep(0)
- end
- saveLoc()
- if orient == 0 then
- x = x+1
- elseif orient == 1 then
- z = z+1
- elseif orient == 2 then
- x = x-1
- elseif orient == 3 then
- z = z-1
- end
- end
- --]]
- function forward()
- local cont = true
- turtle.dig()
- while cont do
- if orient == 0 then
- x = x+1
- elseif orient == 1 then
- z = z+1
- elseif orient == 2 then
- x = x-1
- elseif orient == 3 then
- z = z-1
- end
- saveLoc()
- if turtle.forward() then
- cont = false
- else
- turtle.dig()
- if orient == 0 then
- x = x-1
- elseif orient == 1 then
- z = z-1
- elseif orient == 2 then
- x = x+1
- elseif orient == 3 then
- z = z+1
- end
- saveLoc()
- sleep(1)
- end
- end
- end
- function right()
- if orient == 3 then
- orient = 0
- else
- orient = orient+1
- end
- saveLoc()
- turtle.turnRight()
- end
- function left()
- if orient == 0 then
- orient = 3
- else
- orient = orient-1
- end
- saveLoc()
- turtle.turnLeft()
- end
- function dump()
- if turtle.getItemCount(14) > 0 then
- turtle.select(chestslot)
- while turtle.place() == false do
- turtle.dig()
- sleep(0)
- end
- for i = 1, 14 do
- turtle.select(i)
- while turtle.drop() == false and turtle.getItemCount(i) > 0 do
- sleep(0)
- end
- end
- turtle.select(chestslot)
- while turtle.dig() == false do
- sleep(0)
- end
- turtle.select(1)
- end
- end
- function move()
- if comingBack then
- if x > 0 then
- forward()
- else
- left()
- forward()
- left()
- comingBack = false
- end
- else
- if x < length then
- forward()
- else
- right()
- forward()
- right()
- comingBack = true
- end
- end
- end
- start()
- while true do
- dig()
- dump()
- move()
- sleep(0)
- end
Advertisement
Add Comment
Please, Sign In to add comment