Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --pastebin:YSfqfygc
- local wood, sapling = 1, 2
- local treeHeight = 0
- local treeCount = 0
- local plantCount = 6
- local rowCount = 1
- local pauseLength = 60
- function tRefuel()
- while turtle.getFuelLevel() < 200 do
- turtle.select(wood) --charcol in this slot
- turtle.refuel(1)
- print("Refueled")
- end
- print( "Fuel Level: ", turtle.getFuelLevel() )
- end
- function tF()
- while not turtle.forward() do
- -- turtle blocked from moving forward
- print( "Turtle blocked from moving forward" )
- sleep(3) -- wait 3 seconds to let mob move away
- end
- end
- function tVacume()
- for i = 1, 4 do
- turtle.turnLeft()
- turtle.suck()
- end
- turtle.suckUp() -- in case a sapling fell on turtle's head:D
- end
- local function harvestTree()
- treeCount = treeCount + 1
- while turtle.compare() do
- turtle.dig()
- if turtle.detectUp() then
- turtle.digUp()
- end
- turtle.up()
- treeHeight = treeHeight + 1
- end
- -- return to the ground
- -- if blocked, dig
- while treeHeight > 0 do
- if turtle.down() then
- treeHeight = treeHeight - 1
- else
- turtle.digDown()
- end
- end
- end
- local function moveNextTree()
- for i=1,4 do
- tVacume()
- tF()
- end
- end
- function harvestRow()
- tF()
- -- check all trees for any that have grown
- for i = 1, plantCount do
- turtle.turnRight()
- turtle.select(wood)
- -- if the tree has grown
- if turtle.compare() then
- -- harvest the tree
- harvestTree()
- -- plant a new sapling
- turtle.select(sapling)
- turtle.place()
- else
- turtle.select(sapling)
- if not turtle.compare() then
- turtle.place()
- end
- end
- -- move to next tree location
- turtle.turnLeft()
- if i < plantCount then
- moveNextTree()
- end
- end
- -- round the corner
- tF()
- turtle.turnRight()
- tF()
- tF()
- turtle.turnRight()
- tRefuel()
- end
- local function returnRow()
- tF()
- for i = 1, plantCount-1 do
- moveNextTree()
- end
- tF()
- turtle.turnRight()
- tF()
- tF()
- turtle.turnRight()
- end
- local function dumpExcess()
- turtle.turnRight()
- turtle.turnRight()
- -- dump excess items into chest if a chest is present
- if turtle.detect() then
- for i = 3, 16 do
- turtle.select(i)
- turtle.drop()
- end
- print( "Dropped off Excess Items")
- end
- turtle.turnRight()
- turtle.turnRight()
- end
- local function moveNextRow()
- turtle.turnRight()
- for i=1,4 do
- tF()
- end
- turtle.turnLeft()
- end
- local function returnToStart()
- turtle.turnLeft()
- for row = 1,rowCount-1 do
- for i=1,4 do
- tF()
- end
- end
- turtle.turnRight()
- end
- -- main loop
- print( "Tree Area (plants x rows): ", plantCount, " x ", rowCount )
- while true do
- tRefuel()
- for row = 1,rowCount do
- harvestRow()
- returnRow()
- if (row < rowCount) then
- moveNextRow()
- end
- end
- returnToStart()
- print( "Tree Count: ", treeCount )
- dumpExcess()
- sleep(pauseLength) -- wait for trees to grow and saplings to fall
- end
Advertisement
Add Comment
Please, Sign In to add comment