Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local function getFuel()
- if turtle.getFuelLevel() < 16 then
- while true do
- if turtle.getItemCount(16) > 0 then
- break
- else
- turtle.select(16)
- print("Fuel needed in slot 16")
- local events = {os.pullEvent()}
- if events[1] == "key" and events[2] == 28 then
- turtle.refuel()
- getFuel()
- end
- end
- end
- end
- end
- local function forward(dist)
- if not dist then dist = 1 end
- for i = 1, dist do
- getFuel()
- if not turtle.forward() then
- turtle.dig()
- turtle.forward()
- end
- end
- end
- local function back(dist)
- if not dist then dist = 1 end
- for i = 1, dist do
- getFuel()
- if not turtle.back() then
- turtle.turnRight()
- turtle.turnRight()
- turtle.dig()
- turtle.turnRight()
- turtle.turnRight()
- end
- end
- end
- function down(dist)
- if not dist then dist = 1 end
- for i = 1, dist do
- getFuel()
- if not turtle.down() then
- turtle.digDown()
- turtle.down()
- end
- end
- end
- function up(dist)
- getFuel()
- if not dist then dist = 1 end
- for i = 1,dist do
- if not turtle.up() then
- turtle.digUp()
- turtle.up()
- end
- end
- end
- local function plant()
- if turtle.getItemCount(1) >= 1 then
- turtle.select(1)
- turtle.forward()
- turtle.placeDown()
- turtle.back()
- else
- while true do
- print("Out of Saplings")
- print("Please place desired saplings in slot 1")
- local events = {os.pullEvent()}
- if events[1] == "key" and events[2] == 28 then
- if turtle.getItemCount(1) > 0 then
- turtle.select(1)
- turtle.forward()
- turtle.placeDown()
- turtle.back()
- break
- end
- end
- end
- end
- end
- local function fell()
- local height = 0
- forward()
- turtle.digDown()
- while turtle.detectUp() do
- up()
- for i = 1,4 do
- local branch = 0
- local bBranch = 0
- while turtle.detect() do
- forward()
- turtle.turnLeft()
- while turtle.detect() do
- forward()
- bBranch = bBranch + 1
- end
- if bBranch ~= 0 then
- repeat
- back()
- bBranch = bBranch - 1
- until bBranch == 0
- end
- turtle.turnRight()
- branch = branch + 1
- end
- if branch ~= 0 then
- repeat
- back()
- branch = branch - 1
- until branch == 0
- end
- turtle.turnLeft()
- end
- height = height + 1
- end
- repeat
- down()
- height = height - 1
- until height == 0
- back()
- end
- local trees = 0
- while true do
- print("Fuel level: "..turtle.getFuelLevel())
- print("Planting")
- plant()
- print("Using redstone signal to grow sapling")
- turtle.turnRight()
- forward()
- down()
- rs.setOutput("back", true)
- sleep(1)
- rs.setOutput("back", false)
- up()
- back()
- turtle.turnLeft()
- print("Cutting down tree")
- fell()
- trees = trees + 1
- print("Cut down "..trees.." trees")
- end
Advertisement
Add Comment
Please, Sign In to add comment