Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local goUp = 0
- local right_movement = 0
- local last = "left"
- local level = 2
- function getTree()
- local success, t = turtle.inspect()
- if (string.find(t.name, "leaves") == nil) then
- turtle.dig()
- if turtle.forward() == false then
- turtle.dig()
- turtle.forward()
- else
- if turtle.detectUp() == true then
- while (turtle.detectUp()) do
- local success, t = turtle.inspectUp()
- if (string.find(t.name, "dirt") == nil) then
- turtle.digUp()
- turtle.up()
- goUp = goUp + 1
- else
- break
- end
- end
- repeat
- turtle.down()
- goUp = goUp - 1
- until goUp == 0
- else
- repeat
- turtle.down()
- goUp = goUp - 1
- until goUp == 0
- end
- turtle.digDown()
- turtle.select(1)
- if turtle.getItemCount(1) > 1 then
- if string.find(turtle.getItemDetail(1).name, "sapling") then
- turtle.placeDown()
- end
- end
- end
- else
- turtle.dig()
- if turtle.forward() == false then
- turtle.dig()
- turtle.forward()
- end
- end
- end
- function back(amount)
- local _back = 0
- repeat
- if turtle.back() then
- _back = _back + 1
- else
- turtle.turnleft()
- turtle.turnleft()
- turtle.dig()
- turtle.turnLeft()
- turtle.turnleft()
- end
- until _back == amount
- end
- function forward(amount)
- local _forward = 0
- repeat
- if turtle.forward() then
- _forward = _forward + 1
- else
- turtle.dig()
- end
- until _forward == amount
- end
- function up(amount)
- local _up = 0
- repeat
- if turtle.up() then
- _up = _up + 1
- else
- turtle.digUp()
- end
- until _up == amount
- end
- function down(amount)
- local _down = 0
- repeat
- if turtle.down() then
- _down = _down + 1
- else
- turtle.digDown()
- end
- until _down == amount
- end
- function empty()
- --from base
- turtle.turnLeft()
- turtle.forward()
- if turtle.getItemCount(1) > 1 then
- if string.find(turtle.getItemDetail(1).name, "sapling") then
- for q=2,16 do
- turtle.select(q)
- turtle.dropDown()
- end
- else
- for q=1,16 do
- turtle.select(q)
- turtle.dropDown()
- end
- end
- end
- turtle.select(1)
- turtle.back()
- turtle.turnRight()
- end
- function emptyAll()
- --from base
- turtle.turnLeft()
- turtle.forward()
- for q=1,16 do
- turtle.select(q)
- turtle.dropDown()
- end
- turtle.select(1)
- turtle.back()
- turtle.turnRight()
- end
- function start()
- emptyAll()
- goUp = 0
- right_movement = 0
- last = "left"
- local counter = 0
- --
- if level == 0 then
- turtle.turnRight()
- forward(10)
- turtle.suckDown(35)
- -- if turtle.getItemCount(1) >= 1 then
- -- if string.find(turtle.getItemDetail(1).name, "sapling") then
- -- print("Didn't have any sapplings, give some in slot 1")
- -- while (string.find(turtle.getItemDetail(1).name, "sapling")) == false or (string.find(turtle.getItemDetail(1).name, "sapling")) == nil do
- -- sleep(10)
- -- end
- -- end
- -- elseif turtle.getItemCount(1) == 0 then
- -- print("Didn't have any sapplings, give some in slot 1")
- -- while turtle.getItemCount(1) == 0 do
- -- sleep(10)
- -- end
- -- end
- back(10)
- turtle.turnLeft()
- turtle.forward()
- up(30)
- elseif level == 1 then
- turtle.turnRight()
- forward(7)
- turtle.suckDown(35)
- -- if turtle.getItemCount(1) >= 1 then
- -- if string.find(turtle.getItemDetail(1).name, "sapling") then
- -- print("Didn't have any sapplings, give some in slot 1")
- -- while (string.find(turtle.getItemDetail(1).name, "sapling")) == false or (string.find(turtle.getItemDetail(1).name, "sapling")) == nil do
- -- sleep(10)
- -- counter = counter + 1
- -- if counter == 10 then
- -- break
- -- end
- -- end
- -- end
- -- elseif turtle.getItemCount(1) == 0 then
- -- print("Didn't have any sapplings, give some in slot 1")
- -- while turtle.getItemCount(1) == 0 do
- -- sleep(10)
- -- counter = counter + 1
- -- if counter == 10 then
- -- break
- -- end
- -- end
- -- end
- back(7)
- turtle.turnLeft()
- turtle.forward()
- up(20)
- elseif level == 2 then
- turtle.turnRight()
- forward(4)
- turtle.suckDown(35)
- -- if turtle.getItemCount(1) >= 1 then
- -- if string.find(turtle.getItemDetail(1).name, "sapling") then
- -- print("Didn't have any sapplings, give some in slot 1")
- -- while (string.find(turtle.getItemDetail(1).name, "sapling")) == false or (string.find(turtle.getItemDetail(1).name, "sapling")) == nil do
- -- sleep(10)
- -- counter = counter + 1
- -- if counter == 10 then
- -- break
- -- end
- -- end
- -- end
- -- elseif turtle.getItemCount(1) == 0 then
- -- print("Didn't have any sapplings, give some in slot 1")
- -- while turtle.getItemCount(1) == 0 do
- -- sleep(10)
- -- counter = counter + 1
- -- if counter == 10 then
- -- break
- -- end
- -- end
- -- end
- back(4)
- turtle.turnLeft()
- turtle.forward()
- up(10)
- elseif level == 3 then
- turtle.turnRight()
- forward(1)
- turtle.suckDown(35)
- -- if turtle.getItemCount(1) >= 1 then
- -- if string.find(turtle.getItemDetail(1).name, "sapling") then
- -- print("Didn't have any sapplings, give some in slot 1")
- -- while (string.find(turtle.getItemDetail(1).name, "sapling")) == false or (string.find(turtle.getItemDetail(1).name, "sapling")) == nil do
- -- sleep(10)
- -- counter = counter + 1
- -- if counter == 10 then
- -- break
- -- end
- -- end
- -- end
- -- elseif turtle.getItemCount(1) == 0 then
- -- print("Didn't have any sapplings, give some in slot 1")
- -- while turtle.getItemCount(1) == 0 do
- -- sleep(10)
- -- counter = counter + 1
- -- if counter == 10 then
- -- break
- -- end
- -- end
- -- end
- back(1)
- turtle.turnLeft()
- turtle.forward()
- else
- turtle.forward()
- end
- turtle.select(1)
- print("Done with Start")
- end
- function walk(number)
- local forward = 0
- local tree_steps = 0;
- repeat
- if turtle.forward() == false then
- getTree()
- forward = forward + 1
- tree_steps = tree_steps + 1
- else
- forward = forward + 1
- tree_steps = tree_steps + 1
- end
- if tree_steps == 4 then
- tree_steps = 0
- checkSapling()
- end
- until forward == number
- end
- function moveRight()
- turtle.turnRight()
- forward(3)
- walk(1)
- --check
- checkSapling()
- --
- turtle.turnRight()
- right_movement = right_movement + 1
- last = "right"
- end
- function moveLeft()
- turtle.turnLeft()
- forward(3)
- walk(1)
- checkSapling()
- turtle.turnLeft()
- right_movement = right_movement + 1
- last = "left"
- end
- function goHome()
- if last == "left" then
- turtle.forward()
- turtle.turnRight()
- turtle.forward()
- turtle.turnRight()
- end
- forward(20)
- turtle.turnRight()
- forward(25)
- turtle.turnRight()
- if level == 0 then
- down(30)
- elseif level == 1 then
- down(20)
- elseif level == 2 then
- down(10)
- elseif level == 3 then
- print("last level");
- end
- turtle.down()
- turtle.back()
- if turtle.getItemCount(1) > 0 then
- if string.find(turtle.getItemDetail(1).name, "sapling") then
- turtle.turnRight()
- turtle.select(1)
- if level == 0 then
- forward(10)
- turtle.dropDown(64)
- back(10)
- elseif level == 1 then
- forward(7)
- turtle.dropDown(64)
- back(7)
- elseif level == 2 then
- forward(4)
- turtle.dropDown(64)
- back(4)
- elseif level == 3 then
- forward(1)
- turtle.dropDown(64)
- back(1)
- end
- turtle.turnLeft()
- end
- end
- print("done with Go Home function")
- end
- function checkSapling()
- local success, t = turtle.inspectDown()
- if success then
- if string.find(t.name, "sapling") then
- else
- turtle.select(4)
- turtle.digDown()
- turtle.select(1)
- if turtle.getItemCount(1) > 1 then
- if string.find(turtle.getItemDetail(1).name, "sapling") then
- turtle.placeDown()
- end
- end
- end
- else
- turtle.select(4)
- turtle.digDown()
- turtle.select(1)
- if turtle.getItemCount(1) > 1 then
- if string.find(turtle.getItemDetail(1).name, "sapling") then
- turtle.placeDown()
- end
- end
- end
- end
- function sleepFunction()
- print("Going to sleep")
- local slept = 0
- repeat
- sleep(10)
- slept = slept + 10
- print("Slept: " .. slept .. "/50")
- until slept >= 50
- print( "gotte work ")
- end
- while true do
- repeat
- start()
- turtle.up()
- forward(2)
- walk(1)
- checkSapling()
- repeat
- walk(16)
- if last == "left" then
- moveRight()
- elseif last == "right" then
- moveLeft()
- end
- until right_movement == 6
- walk(16)
- goHome()
- level = level + 1
- until level == 4
- --reset
- level = 0
- last = "left"
- right_movement = 0
- goUp = 0
- sleepFunction()
- end
Add Comment
Please, Sign In to add comment