Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local dir = 0
- local f = 0
- local x = 0
- local y = 0
- local z = 0
- function digForward(count)
- for i = 1, count do
- while not turtle.forward() do
- turtle.dig()
- end
- while turtle.digUp() do
- os.sleep(0.5)
- end
- turtle.digDown()
- end
- if f == 0 then
- z = z + count
- end
- if f == 1 then
- x = x - count
- end
- if f == 2 then
- z = z - count
- end
- if f == 3 then
- x = x + count
- end
- end
- function forward(count)
- for i = 1, count do
- while not turtle.forward() do
- turtle.dig()
- end
- end
- if f == 0 then
- z = z + count
- end
- if f == 1 then
- x = x - count
- end
- if f == 2 then
- z = z - count
- end
- if f == 3 then
- x = x + count
- end
- end
- function up(count)
- for i = 1, count do
- while not turtle.up() do
- turtle.digUp()
- os.sleep(0.5)
- end
- y = y + 1
- end
- end
- function down(count)
- for i = 1, count do
- while not turtle.down() do
- turtle.digDown()
- os.sleep(0.5)
- end
- y = y - 1
- end
- end
- function left()
- turtle.turnLeft()
- f = f - 1
- if f < 0 then
- f = 3
- end
- end
- function right()
- turtle.turnRight()
- f = f + 1
- if f > 3 then
- f = 0
- end
- end
- function faceF(goF)
- if f == goF then
- return
- end
- if f == (goF - 1) then
- right()
- return
- end
- if f == (goF + 1) then
- left()
- return
- end
- if (f == 3) and (goF == 0) then
- right()
- return
- end
- if(f == 0) and (goF == 3) then
- left()
- return
- end
- right()
- right()
- end
- function goToX(goX)
- if x == goX then
- return
- end
- if x > goX then
- faceF(1)
- forward(x - goX)
- else
- faceF(3)
- forward(goX - x)
- end
- end
- function goToZ(goZ)
- if z == goZ then
- return
- end
- if z > goZ then
- faceF(2)
- forward(z - goZ)
- else
- faceF(0)
- forward(goZ - z)
- end
- end
- function goToY(goY)
- if y == goY then
- return
- end
- if y > goY then
- down(y - goY)
- else
- up(goY - y)
- end
- end
- function goTo(goX, goY, goZ, goF)
- goToX(goX)
- goToZ(goZ)
- goToY(goY)
- faceF(goF)
- end
- function panic()
- if turtle.getItemCount(16) > 0 then
- local holdX = x
- local holdY = y
- local holdZ = z
- local holdF = f
- goTo(0,y,0,0)
- goToY(0)
- turtle.back()
- turtle.turnLeft()
- for i = 1, 16 do
- turtle.select(i)
- data = turtle.getItemDetail(i)
- if data.name == "minecraft:cobblestone" then
- turtle.drop()
- elseif data.name == "minecraft:dirt" then
- while not turtle.dropUp() do
- os.sleep(5)
- end
- elseif data.name == "minecraft:gravel" then
- turtle.turnLeft()
- turtle.turnLeft()
- while not turtle.drop() do
- os.sleep()
- end
- turtle.turnLeft()
- turtle.turnLeft()
- else
- while not turtle.dropDown() do
- os.sleep(0.5)
- end
- end
- end
- turtle.select(1)
- turtle.turnRight()
- turtle.forward()
- goToY(holdY)
- goTo(holdX, y, holdZ, holdF)
- end
- end
- local lastTree
- function checkLog()
- local success, data = turtle.inspect()
- if success then
- if data.name == "minecraft:log" then
- return true
- else
- return false
- end
- else
- return false
- end
- end
- function checkTree()
- if checkLog() then
- local holdX = x
- local holdY = y
- local holdZ = z
- local holdF = f
- killTree()
- forward(1)
- findSaplings()
- goTo(holdX, holdY, holdZ, holdF)
- end
- end
- function killTree()
- local leftRight
- local treeHeight = 0
- forward(1)
- left()
- leftRight = checkLog()
- lastTree = leftRight
- right()
- turtle.dig()
- while turtle.detectUp() do
- up(1)
- turtle.dig()
- treeHeight = treeHeight + 1
- end
- if leftRight then
- left()
- forward(1)
- right()
- else
- right()
- forward(1)
- left()
- end
- for i = 1, treeHeight do
- down(1)
- turtle.dig()
- end
- if leftRight then
- turtle.digDown()
- forward(1)
- turtle.digDown()
- right()
- forward(1)
- turtle.digDown()
- right()
- forward(1)
- turtle.digDown()
- forward(1)
- left()
- left()
- else
- turtle.digDown()
- forward(1)
- turtle.digDown()
- left()
- forward(1)
- turtle.digDown()
- left()
- forward(1)
- turtle.digDown()
- forward(1)
- right()
- right()
- end
- end
- function findSaplings()
- if lastTree then
- for m = 1, 5 do
- local distance = (m * 2) - 1
- for n = 1, 4 do
- for i = 1, distance do
- checkTree()
- forward(1)
- turtle.suckDown()
- end
- left()
- end
- left()
- left()
- checkTree()
- forward(1)
- turtle.suckDown()
- left()
- left()
- right()
- checkTree()
- forward(1)
- turtle.suckDown()
- left()
- end
- else
- for m = 1, 5 do
- local distance = (m * 2) - 1
- for n = 1, 4 do
- for i = 1, distance do
- checkTree()
- forward(1)
- turtle.suckDown()
- end
- right()
- end
- left()
- left()
- checkTree()
- forward(1)
- turtle.suckDown()
- left()
- left()
- left()
- checkTree()
- forward(1)
- turtle.suckDown()
- right()
- end
- end
- end
- killTree()
- forward(1)
- findSaplings()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement