Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[ Running this script on a turtle with saplings in slot 1, bone-meal in slot 2 and coal in slot 16 and a chest behind the turtle for the wood drop off point will create an automatic tree farm. combining this with a chest to the left of the turtle for sapling replenishment and chest to the right for coal replenishment will ensure a long running automated process.]]
- -- This function lays saplings and applies bone-meal
- function plant()
- turtle.select(1) --selects sapling
- turtle.place() --places sapling
- turtle.select(2) --selects bone-meal
- turtle.place() --fertilizes sapling
- turtle.suck() --picks up any saplings that have fallen
- end
- -- This function checks fuel level and refuels
- function fuel()
- if turtle.getFuelLevel() < 50 then --checks fuel level and refuels
- turtle.select(16)
- turtle.refuel(5) --picks up any saplings that have fallen
- end
- print( turtle.getFuelLevel() .. " fuel left.") --displays fuel level to user
- end
- -- This function cuts a column directly above the turtle and then returns to ground level
- function column()
- while turtle.detectUp() == true do --cut tree down
- turtle.digUp()
- turtle.up()
- turtle.suck() --picks up any saplings that have fallen
- end
- while turtle.detectDown() == false do -- return to ground level
- turtle.down()
- turtle.suck() --picks up any saplings that have fallen
- end
- end
- -- This function moves from start position, runs column and returns to start position
- function fell()
- turtle.dig() --breaks bottom block of tree
- turtle.forward() --move into gap
- column() --run column function
- turtle.turnRight() --return to start
- turtle.turnRight()
- turtle.forward()
- end
- -- This function empties all collected wood into chest, checks sapling and fuel supplies and restocks
- function empty()
- for j = 3, 15 do -- empty slots 3 to 15 into chest
- turtle.select(j)
- turtle.drop()
- end
- turtle.turnLeft()
- if turtle.getItemCount(16) < 5 then -- replenish fuel stocks
- turtle.select(16)
- turtle.suck(10)
- end
- turtle.turnLeft()
- if turtle.getItemCount(1) < 5 then --replenish sapling stocks
- turtle.turnLeft()
- turtle.select(1)
- turtle.suck()
- turtle.turnRight()
- end
- end
- -- This function checks to see if the sapling has been fertilized into a full tree
- function compare()
- turtle.select(1)
- if turtle.compare() == true then
- return true -- false could indicate that there is no bonemeal or saplings
- else
- return false
- end
- end
- -- This block triggers the appropriate functions in the correct order.
- repeat --start loop
- fuel() --check fuel
- plant() --plant and fertilize tree
- fuel() --check fuel again
- if compare() == false then --if tree has grown cut down tree
- fell()
- else --if tree hasn't grown display error
- print("error")
- repeat
- sleep(1)
- turtle.select(2)
- until turtle.getItemCount() > 20 --this will terminate script
- end
- empty() --empty harvest and restock fuel and materials
- until 1 > 2 -- always false creating infinite loop
Advertisement
Advertisement