Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- height = 0
- treeNum = 1
- function moveUp()
- if turtle.up() then
- height = height + 1
- end
- end
- function moveDown()
- if turtle.down() then
- height = height - 1
- end
- end
- function moveTo(h)
- while h < height do
- moveDown()
- end
- while h > height do
- moveUp()
- end
- end
- function checkGrow()
- turtle.select(1)
- return not turtle.compare()
- end
- function getSapling()
- print("Checking saplings.")
- if turtle.getItemCount(1) < 10 then
- print("Getting new saplings.")
- turtle.select(1)
- turtle.turnLeft()
- turtle.suck()
- turtle.turnRight()
- end
- end
- function dropOff()
- print("Dropping off items.")
- turtle.turnRight()
- num = 2
- while turtle.getItemCount(num) > 0 do
- turtle.select(num)
- turtle.drop()
- num = num + 1
- end
- turtle.select(1)
- turtle.turnLeft()
- end
- function checkFuel()
- print("Checking fuel ("..turtle.getFuelLevel()..").")
- while turtle.getFuelLevel() < 1000 do
- print("Refueling...")
- turtle.select(2)
- turtle.refuel(1)
- if turtle.getItemCount(2) == 0 then
- print("No wood to refuel with.")
- break
- end
- end
- if turtle.getFuelLevel() < 100 then
- print("Fuel at critical level, ended program.")
- return false
- end
- return true
- end
- function chopTree()
- print("Chopping tree down.")
- while turtle.detect() do
- turtle.dig()
- turtle.digUp()
- moveUp()
- end
- print("Detected no more tree at height "..height..".")
- moveTo(0)
- turtle.select(1)
- print("Placing sapling.")
- while not turtle.place() do
- os.sleep(1)
- end
- if not checkFuel() then
- return false
- end
- getSapling()
- dropOff()
- return true
- end
- while true do
- if checkGrow() then
- print("Detected tree number "..treeNum)
- if not chopTree() then
- break
- end
- treeNum = treeNum + 1
- else
- os.sleep(10)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment