Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Tree Farm Tending Turtle
- -- Cuts down and replants fir trees
- -- Variables
- turtle.select(1)
- local tArgs = { ... }
- local togo = tonumber(tArgs[1])
- togo = togo or 1
- local sapling = 0
- term.clear()
- term.setCursorPos(1,1)
- print(os.getComputerLabel() .. " at your service!")
- print()
- print("Please place blocks as follows:")
- print("Slot 1 - Fuel (coal, lava, wood)")
- print("Slot 2 - Saplings (Fir is best)")
- print()
- print("Place turtle over chest at edge of farm.")
- print()
- print("Press [ENTER] when ready.")
- read(input)
- -- Starting Out
- if turtle.getItemCount(1) < 1 then
- print("No fuel! Abort!")
- os.quit()
- end
- sapling = 0
- if turtle.getItemCount(2) > 0 then
- sapling = 1
- end
- -- Functions
- local function tfuel(amount)
- if turtle.getFuelLevel() < 16 then
- turtle.select(1)
- turtle.refuel(amount)
- end
- end
- local function tforward(steps) -- turtle takes x steps forward
- if steps==nil or steps==0 then steps=1 end
- tfuel(1)
- for i=1,steps do
- while not turtle.forward() do
- turtle.dig()
- turtle.attack()
- end
- end
- end
- local function turnaround()
- turtle.turnRight()
- turtle.turnRight()
- end
- local function discard() -- drop off extra stuff into water
- if turtle.getItemCount(3)<1 then
- return
- end
- while not turtle.down() do
- turtle.digDown()
- end
- for i = 3,16 do
- if turtle.getItemCount(i)>0 then
- turtle.select(i)
- turtle.dropDown()
- end
- end
- while not turtle.up() do
- turtle.digUp()
- end
- turtle.select(1)
- end
- local function climb()
- if turtle.detect() then
- turtle.dig()
- tforward()
- local cnt=0
- repeat
- cnt = cnt + 1
- turtle.dig()
- sleep(0.5)
- turtle.digUp()
- tfuel(1)
- turtle.up()
- until not turtle.detect()
- turtle.turnRight()
- tforward()
- turtle.turnLeft()
- for i = 1,cnt do
- turtle.digDown()
- sleep(0.5)
- tfuel(1)
- turtle.down()
- turtle.dig()
- end
- turtle.digDown()
- turtle.select(2)
- turtle.placeDown()
- tforward()
- turtle.digDown()
- turtle.select(2)
- turtle.placeDown()
- turtle.turnLeft()
- tforward()
- turtle.digDown()
- turtle.select(2)
- turtle.placeDown()
- turtle.turnLeft()
- tforward()
- turtle.digDown()
- turtle.select(2)
- turtle.placeDown()
- turnaround()
- tforward(2)
- else
- tforward(3)
- end
- discard()
- end
- -- Main Loop
- tforward(2) -- move into first position
- for r = 1,4 do
- for i = 1,4 do
- climb() -- climb and cut tree
- if i<4 then
- tforward(2)
- end
- end
- if r<4 then
- if r%2>0 then
- turtle.turnRight()
- else
- turtle.turnLeft()
- end
- tforward(4+2*(r%2))
- if r%2>0 then
- turtle.turnRight()
- else
- turtle.turnLeft()
- end
- end
- end
- turtle.turnRight()
- tforward(16) -- move back to base
- turtle.turnLeft()
- tforward(2)
- turnaround()
- turtle.select(2) -- reload saplings
- turtle.suckDown()
- turtle.select(3)
- turtle.dropDown()
- turtle.select(1)
Add Comment
Please, Sign In to add comment