Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Changelog v1.01
- -- Fixed tree growing in turtle
- -- Possibly fixed random crashes
- --Changelog v1.02
- -- Added basic session support,
- -- - if the server crashed while it was planting bonemeal it will return to its original position.
- --Changelog v1.03
- -- Removed rebooting the turtle, will now run on it's own. (Damnit h variable)
- if(turtle.detect()) then
- turtle.down()
- if turtle.detect() then
- print("I've crashed, woops.")
- for i=1,7 do
- turtle.back()
- end
- turtle.turnLeft()
- for i=1,8 do turtle.back() end
- end
- end
- if (turtle.detect() and not turtle.detectDown()) then
- print("Detected crash, going back.")
- while not turtle.detectDown() do
- turtle.back()
- end
- turtle.turnLeft()
- for i=1,8 do turtle.back() end
- end
- h = 0
- function checkFuel()
- if turtle.getFuelLevel() < 200 then
- print("Turtle refueling.")
- turtle.select(4)
- turtle.turnLeft()
- turtle.turnLeft()
- turtle.suck()
- if turtle.refuel() then
- print("Turtle refueled.")
- else
- print("The turtle could not refuel.")
- turtle.turnLeft()
- turtle.turnLeft()
- checkFuel()
- end
- turtle.turnLeft()
- turtle.turnLeft()
- checkFuel()
- end
- end
- function newFuel()
- turtle.select(16)
- if turtle.refuel() then
- print("Turtle refueled.")
- else
- print("Turtle could not refuel. Retrying in 10 seconds..")
- sleep(10)
- newFuel()
- end
- end
- function checkSapling()
- print("Checking Saplings.")
- if turtle.getItemCount(1) < 8 then
- print("Need moar saplings.")
- turtle.select(1)
- turtle.turnLeft()
- turtle.suck()
- if turtle.getItemCount(1) < 8 then
- turtle.suck()
- end
- turtle.select(2)
- turtle.drop()
- turtle.select(3)
- turtle.drop()
- turtle.select(1)
- turtle.turnRight()
- end
- end
- function checkBonemeal()
- turtle.select(14)
- print("Attempting to get bonemeal..")
- if turtle.getItemCount(14) < 1 then
- if turtle.suckUp() then
- print("Got bonemeal!")
- sleep(5)
- os.reboot()
- end
- end
- if turtle.getItemCount(14) < 2 then
- print(".. need moar bonemeal.")
- if turtle.suckUp() then
- turtle.select(15)
- turtle.dropUp()
- sleep(5)
- os.reboot()
- end
- end
- end
- function moveToPosition()
- print("Awayyyyyyy!")
- for i=1,8 do turtle.forward() turtle.attack() end
- turtle.turnRight()
- for i=1,7 do turtle.forward() turtle.attack() end
- end
- function placeSapling()
- turtle.select(1)
- if not turtle.detect() then
- for i=1,2 do turtle.forward() end
- turtle.turnLeft()
- turtle.place()
- turtle.turnRight()
- turtle.back()
- turtle.place()
- turtle.turnLeft()
- turtle.place()
- turtle.turnRight()
- turtle.back()
- turtle.place()
- turtle.select(14)
- else
- print("Saplings were already there, ignoring.")
- end
- sleep(2)
- print("Attempting to bonemeal..")
- turtle.place()
- end
- function checkTree()
- turtle.select(16)
- turtle.digUp()
- turtle.up()
- if not turtle.detect() then
- print("Tree hasen't grown, sleeping.")
- print("Every day I'm shufflin'")
- turtle.down()
- sleep(3)
- turtle.select(14)
- turtle.place()
- checkTree()
- end
- turtle.down()
- turtle.select(5)
- turtle.dig()
- turtle.forward()
- turtle.turnLeft()
- while turtle.detectUp() do
- turtle.dig()
- turtle.digUp()
- turtle.up()
- h = h + 1
- end
- turtle.turnRight()
- turtle.dig()
- turtle.forward()
- turtle.turnLeft()
- turtle.select(5)
- for i = 1,h do
- turtle.digDown()
- turtle.down()
- turtle.dig()
- end
- turtle.turnRight()
- for i=1,9 do turtle.back() turtle.attack() end
- turtle.turnLeft()
- for i=1,8 do turtle.back() turtle.attack() end
- turtle.turnRight()
- turtle.select(6)
- if turtle.getFuelLevel() < 500 then
- turtle.transferTo(16, 64)
- print("Kept some fuel. Eating it.")
- turtle.select(16)
- turtle.refuel()
- end
- for i=5,9 do
- turtle.select(i)
- turtle.drop()
- end
- turtle.turnLeft()
- print("Yay!")
- os.reboot()
- end
- if redstone.getInput("bottom") then
- print("Stopped.")
- print("Checking turtle in 10 seconds.")
- sleep(10)
- os.reboot()
- end
- while true do
- if turtle.getFuelLevel() < 100 then
- newFuel()
- end
- checkBonemeal()
- checkSapling()
- moveToPosition()
- placeSapling()
- checkTree()
- h = 0
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement