Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- trees = 12
- reqFuel = trees * 150 + 100
- local main
- function clearInventory()
- slot = 1
- while slot < 16 do
- slot = slot + 1
- turtle.select(slot)
- turtle.drop()
- end
- end
- function plantSaplings()
- turtle.select(1)
- turtle.forward()
- turtle.place()
- turtle.turnRight()
- turtle.forward()
- turtle.turnLeft()
- turtle.place()
- turtle.turnLeft()
- turtle.forward()
- turtle.turnLeft()
- turtle.turnLeft()
- turtle.place()
- turtle.turnRight()
- turtle.forward()
- turtle.turnRight()
- turtle.turnRight()
- turtle.place()
- end
- function dropAndLoot()
- print("Drop and loot")
- --Saplings should be in the first slot
- --and logs in the rest (but always in the last)
- --Drop all logs and take back one stack
- turtle.turnLeft()
- clearInventory()
- turtle.select(16)
- turtle.suck()
- --rotate to the other chest
- turtle.turnLeft()
- turtle.turnLeft()
- --Loot one stack saplings..
- turtle.select(1)
- turtle.suck()
- --and drop the rest..
- turtle.select(2)
- turtle.drop()
- --Rotate to its orginal position
- turtle.turnLeft()
- end
- function checkFuel()
- print("Checking fuel..")
- while turtle.getFuelLevel() < reqFuel do
- turtle.select(16)
- if turtle.refuel(1) then
- if turtle.getFuelLevel() < reqFuel then
- print("Fuel level (waiting for " .. reqFuel .. "): " .. turtle.getFuelLevel())
- end
- else
- --Fuel level too low and no logs left.
- dropAndLoot()
- end
- end
- end
- function cutTree()
- --Get inside of the tree
- turtle.dig()
- turtle.forward()
- treeHeight = 0
- --Climb the tree up
- while turtle.dig() do
- turtle.digUp()
- turtle.up()
- treeHeight = treeHeight + 1
- end
- --At the top, get to the second half of the tree
- turtle.turnRight()
- turtle.dig()
- turtle.forward()
- turtle.turnLeft()
- turtle.digDown()
- turtle.down()
- turtle.dig()
- --Get down again
- level = treeHeight - 1
- while level > 0 do
- level = level - 1
- turtle.digDown()
- turtle.down()
- turtle.dig()
- end
- --Get back to the starting position
- turtle.turnLeft()
- turtle.forward()
- turtle.turnLeft()
- turtle.forward()
- turtle.turnLeft()
- turtle.turnLeft()
- print("Tree cut.")
- print("Replanting saplings")
- plantSaplings()
- print("Planted saplings.")
- end
- function goForward(steps)
- for step = 1, steps, 1 do
- turtle.forward()
- end
- end
- function waitForNext()
- --for i = 3, 1, -1 do
- -- print("Waiting " .. i .. " minutes..")
- -- sleep(60)
- -- end
- end
- function nextTree()
- tree = tree + 1
- if tree > trees then
- print("Returning to base..")
- turtle.turnRight()
- goForward(4 * (trees - 1) + 3)
- turtle.turnLeft()
- turtle.forward()
- turtle.turnRight()
- turtle.forward()
- turtle.turnLeft()
- turtle.turnLeft()
- turtle.down()
- waitForNext()
- else
- --Go to next tree
- turtle.turnLeft()
- goForward(4)
- turtle.turnRight()
- checkTree()
- end
- end
- function checkTree()
- turtle.select(1)
- if turtle.compare() then
- --It's still a sapling, go to next tree.
- print("Still saplings")
- nextTree()
- else
- print("Tree is fully grown. Cutting.")
- cutTree()
- nextTree()
- end
- end
- function goToFirstTree()
- --Move from the starting position to the cutting position of the first tree.
- turtle.up()
- turtle.forward()
- turtle.forward()
- turtle.turnLeft()
- turtle.forward()
- turtle.turnRight()
- turtle.forward()
- turtle.forward()
- turtle.turnRight()
- tree = 1
- checkTree()
- end
- function main()
- dropAndLoot()
- checkFuel()
- goToFirstTree()
- end
- while true do
- --Main is run once for each "round"
- main()
- print("Done")
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement