Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Based on excavate from the original computercraft distribution
- -- written by hildenae
- rubberwood=1
- tool=2
- local depth = 0
- local xPos,zPos = 0,0
- local xDir,zDir = 0,1
- local function turnLeft()
- turtle.turnLeft()
- xDir, zDir = -zDir, xDir
- end
- local function turnRight()
- turtle.turnRight()
- xDir, zDir = zDir, -xDir
- end
- function goTo( x, y, z, xd, zd )
- while depth > y do
- if turtle.up() then
- depth = depth - 1
- else
- return false
- end
- end
- if xPos > x then
- while xDir ~= -1 do
- turnLeft()
- end
- while xPos > x do
- if turtle.forward() then
- xPos = xPos - 1
- else
- return false
- end
- end
- elseif xPos < x then
- while xDir ~= 1 do
- turnLeft()
- end
- while xPos < x do
- if turtle.forward() then
- xPos = xPos + 1
- else
- return false
- end
- end
- end
- if zPos > z then
- while zDir ~= -1 do
- turnLeft()
- end
- while zPos > z do
- if turtle.forward() then
- zPos = zPos - 1
- else
- return false
- end
- end
- elseif zPos < z then
- while zDir ~= 1 do
- turnLeft()
- end
- while zPos < z do
- if turtle.forward() then
- zPos = zPos + 1
- else
- return false
- end
- end
- end
- while depth < y do
- if turtle.down() then
- depth = depth + 1
- else
- return false
- end
- end
- while zDir ~= zd or xDir ~= xd do
- turnLeft()
- end
- return true
- end
- local function forward()
- turtle.forward()
- xPos = xPos + xDir
- zPos = zPos + zDir
- return true
- end
- local function down()
- if turtle.down() then
- depth = depth + 1
- return true
- else
- return false
- end
- end
- local function harvest()
- if turtle.compareTo(rubberwood) then
- turtle.select(tool)
- turtle.place()
- end
- end
- local function downTree()
- local x,y,z,xd,zd = xPos,depth,zPos,xDir,zDir
- while(down()) do
- harvest()
- end
- goTo( x,y,z,xd,zd )
- end
- local function moveRight()
- turnRight()
- forward()
- turnLeft()
- end
- local function moveLeft()
- turnLeft()
- forward()
- turnRight()
- end
- run = true
- while run do
- forward()
- downTree()
- moveRight()
- downTree()
- moveRight()
- downTree()
- -- go to charge station
- goTo(0,0,0,0,1)
- run = false
- end
Advertisement
Add Comment
Please, Sign In to add comment