Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local setX = tonumber(arg[1])
- local setY = tonumber(arg[2])
- local setZ = tonumber(arg[3])
- --util function
- local function checkF()
- if turtle.getFuelLevel() == 0 then
- turtle.select(16)
- turtle.refuel(1)
- end
- end
- --chop tree function
- local function chopUp()
- local high = 1
- while turtle.up() == false do
- turtle.dig()
- turtle.digUp()
- checkF()
- turtle.up()
- high = high + 1
- end
- return high
- end
- local function chopDown(a)
- for i = 1, a, 1 do
- turtle.dig()
- turtle.digDown()
- checkF()
- turtle.down()
- end
- turtle.dig()
- end
- --plant sapling
- --at the end of this function, the turtle should return to original position a.k.a setX, setY, setZ
- --spaling slot will be the 15th slot
- local function placeSapling()
- turtle.select(15)
- turtle.place()
- turtle.turnLeft()
- checkF()
- turtle.back()
- turtle.place()
- turtle.turnRight()
- turtle.place()
- checkF()
- turtle.back()
- turtle.place()
- end
- --functions use for init()
- --clean up older log if there is any
- local function chopUpInit()
- local high = 1
- while high <= 32 do
- turtle.dig()
- turtle.digUp()
- checkF()
- turtle.up()
- high = high + 1
- end
- return high
- end
- --go to init position
- local function initLococaltion()
- --make sure the turtle is always facing south at the end of this function
- local x1, y1, z1 = gps.locate()
- if turtle.forward() == false then
- turtle.refuel()
- if not turtle.forward() then
- turtle.dig()
- end
- turtle.forward()
- end
- local x2, y2, z2 = gps.locate()
- if x1 - x2 == 0 then
- turtle.turnRight()
- if z2 - z1 > 0 then
- turtle.turnRight()
- turtle.turnRight()
- end
- end
- --go to y coordinate
- local x, y, z = gps.locate()
- while not (y == setY) do
- if setY - y > 0 then
- if turtle.up() == false then
- turtle.refuel()
- if turtle.detectUp() then
- turtle.digUp()
- end
- turtle.up()
- end
- elseif setY - y < 0 then
- if turtle.down() == false then
- turtle.refuel()
- if turtle.detectDown() then
- turtle.digDown()
- turtle.down()
- end
- end
- end
- x, y, z = gps.locate()
- end
- --go to x coordinate
- while not (x == setX) do
- if setX - x > 0 then
- if turtle.forward() == false then
- turtle.refuel()
- if turtle.detect() then
- turtle.dig()
- end
- turtle.forward()
- end
- elseif setX - x < 0 then
- if turtle.back() == false then
- turtle.refuel()
- if not turtle.back() then
- turtle.turnRight()
- turtle.turnRight()
- turtle.dig()
- turtle.turnRight()
- turtle.turnRight()
- end
- turtle.back()
- end
- end
- x, y, z = gps.locate()
- end
- --go to z coordinate
- turtle.turnRight()
- while not (z == setZ) do
- if setZ - z > 0 then
- if turtle.forward() == false then
- turtle.refuel()
- if turtle.detect() then
- turtle.dig()
- end
- turtle.forward()
- end
- elseif setZ - z < 0 then
- if turtle.back() == false then
- turtle.refuel()
- if not turtle.back() then
- turtle.turnRight()
- turtle.turnRight()
- turtle.dig()
- turtle.turnRight()
- turtle.turnRight()
- end
- turtle.back()
- end
- end
- x, y, z = gps.locate()
- end
- end
- --main
- initLococaltion()
- checkF()
- turtle.dig()
- turtle.forward()
- local a = chopUpInit()
- turtle.turnLeft()
- checkF()
- turtle.forward()
- turtle.turnLeft()
- chopDown(a)
- placeSapling()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement