Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- tree farmer
- -- requires a very specific tree farm setup
- -- which I will document somewhere and
- -- put a link to when that's done
- -- put fuel in first slot
- -- put 1 block of wood type in second slot
- -- put saplings of wood type in third slot
- function fuel()
- if turtle.getFuelLevel() < 30 then
- turtle.select(1)
- if turtle.refuel(1) then
- return true
- end
- print("Refuelling failed.")
- return false
- end
- end
- function chop ()
- local blocksMovedUp = 0
- while turtle.detect() do
- turtle.dig()
- if turtle.detectUp() then
- turtle.digUp()
- end
- turtle.up()
- blocksMovedUp = blocksMovedUp + 1
- end
- while blocksMovedUp > 0 do
- turtle.down()
- blocksMovedUp = blocksMovedUp - 1
- end
- -- plant new tree
- turtle.select(3)
- turtle.place()
- return true
- end
- function goNext()
- i = 1
- for i=1,4,1 do
- turtle.forward()
- end
- turtle.turnLeft()
- -- has the tree grown?
- ret = false
- while ret == false do
- ret = detectTree()
- end
- end
- function detectTree()
- turtle.select(2)
- if turtle.compare() then
- return true
- else
- return false
- end
- end
- function farmTree()
- goNext()
- chop()
- end
- -- farms the entire treefarm
- function treeFarm()
- side = 0
- for side=1,4,1 do
- for tree=1,2,1 do
- farmTree()
- turtle.turnRight()
- end
- turtle.turnRight()
- end
- end
- function dump()
- for i=4,16,1 do
- turtle.select(i)
- turtle.drop()
- end
- end
- -- keep farming trees until...
- while true do
- if fuel() == false then
- print('Ran out of fuel')
- break
- end
- treeFarm()
- dump()
- -- if there are no more saplings
- if turtle.getItemCount(3) < 8 then
- print('Ran out of saplings')
- break
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment