Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- state = "charging"
- position = 0
- while true do
- -- print("state = " .. state .. ", position = " .. position .. ", fuel = " .. turtle.getFuelLevel())
- if state == "nextposition" then
- position = position + 1
- if position > 35 then
- position = 0
- end
- if position >= 0 and position <= 8 then
- turtle.turnLeft()
- if position > 0 then
- turtle.forward()
- turtle.turnRight()
- end
- end
- if position >= 9 and position <= 17 then
- turtle.turnLeft()
- if position > 9 then
- turtle.forward()
- turtle.turnRight()
- end
- end
- if position >= 18 and position <= 26 then
- turtle.turnLeft()
- if position > 18 then
- turtle.forward()
- turtle.turnRight()
- end
- end
- if position >= 27 and position <= 35 then
- turtle.turnLeft()
- if position > 27 then
- turtle.forward()
- turtle.turnRight()
- end
- end
- -- there might be items on the ground, pick them up
- turtle.select(1)
- turtle.suck()
- if turtle.getItemCount(2) > 0 then -- we have excess items, drop them
- turtle.turnRight()
- turtle.turnRight()
- for n=2,4 do
- turtle.select(n)
- turtle.drop()
- end
- turtle.turnRight()
- turtle.turnRight()
- end
- state = "logging"
- end
- if state == "logging" then
- turtle.select(1)
- if turtle.getItemCount(1) > 0 and turtle.compareTo(16) == true then
- turtle.place()
- turtle.select(15)
- if turtle.compare() == true then
- turtle.select(2)
- turtle.dig()
- turtle.forward()
- while turtle.compareUp() == true do
- turtle.digUp()
- turtle.up()
- end
- while turtle.detectDown() == false do
- turtle.down()
- end
- turtle.back()
- turtle.turnRight()
- turtle.turnRight()
- turtle.drop()
- turtle.turnRight()
- turtle.turnRight()
- turtle.select(1)
- turtle.place()
- end
- state = "nextposition"
- else
- state = "reload"
- end
- end
- if state == "charging" then
- if turtle.getFuelLevel() > 1000 then
- turtle.forward()
- turtle.forward()
- turtle.forward()
- turtle.forward()
- turtle.turnLeft()
- turtle.forward()
- turtle.forward()
- turtle.forward()
- turtle.forward()
- state = "logging"
- position = 0
- print("switching to logging state")
- end
- end
- if state == "reload" then
- -- prepare turtle to return to center of farm
- turtle.down()
- turtle.down()
- turtle.back()
- turtle.back()
- turtle.back()
- turtle.back()
- turtle.turnRight()
- -- now get it to the center block
- if position >= 0 and position <= 8 then
- while position < 4 do
- turtle.back()
- position = position + 1
- end
- while position > 4 do
- turtle.forward()
- position = position - 1
- end
- end
- if position >= 9 and position <= 17 then
- while position < 13 do
- turtle.back()
- position = position + 1
- end
- while position > 13 do
- turtle.forward()
- position = position - 1
- end
- turtle.turnRight()
- end
- if position >= 18 and position <= 26 then
- while position < 22 do
- turtle.back()
- position = position + 1
- end
- while position > 22 do
- turtle.forward()
- position = position - 1
- end
- turtle.turnRight()
- turtle.turnRight()
- end
- if position >= 27 and position <= 35 then
- while position < 31 do
- turtle.back()
- position = position + 1
- end
- while position > 31 do
- turtle.forward()
- position = position - 1
- end
- turtle.turnLeft()
- end
- -- now get it to the chest with the saplings
- turtle.turnRight()
- turtle.turnRight()
- for n=1,8 do
- turtle.forward()
- end
- turtle.up()
- turtle.up()
- turtle.up()
- turtle.forward()
- turtle.forward()
- -- we should be on top of the chest, get some saplings
- turtle.select(1)
- turtle.suckDown()
- -- and get turtle back to center block
- turtle.turnLeft()
- turtle.turnLeft()
- turtle.forward()
- turtle.forward()
- turtle.down()
- turtle.down()
- turtle.down()
- for n=1,8 do
- turtle.forward()
- end
- turtle.up()
- turtle.up()
- state = "charging"
- end
- if turtle.getFuelLevel() < 100 then
- state = "reload"
- end
- os.queueEvent("loop")
- os.pullEvent()
- end
Advertisement
Add Comment
Please, Sign In to add comment