Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local x
- local y
- local z
- local r
- local minFuel = 150
- local mx = 9
- local mz = 5
- function readNumber(inputFile)
- local returnVal
- local nextLine = inputFile.readLine()
- if (nextLine ~= nil) then
- returnVal = tonumber(nextLine)
- end
- return returnVal
- end
- function updateCoords()
- local fl = fs.open("coords", "w")
- fl.write(x)
- fl.write("\n")
- fl.write(y)
- fl.write("\n")
- fl.write(z)
- fl.write("\n")
- fl.write(r)
- fl.close()
- end
- function turnRight()
- turtle.turnRight()
- r = r + 1
- if r == 4 then r = r - 4 end
- updateCoords()
- end
- function turnLeft()
- turtle.turnLeft()
- r = r - 1
- if r == -1 then r = r + 4 end
- updateCoords()
- end
- function updateForward()
- if r == 0 then
- z = z + 1
- elseif r == 1 then
- x = x - 1
- elseif r == 2 then
- z = z - 1
- elseif r == 3 then
- x = x + 1
- end
- updateCoords()
- end
- function treeFeller()
- if not turtle.forward() then
- turtle.select(1)
- if turtle.compare() then
- turtle.dig()
- turtle.forward()
- updateForward()
- turtle.digDown()
- while turtle.digUp() do
- turtle.up()
- y = y + 1
- updateCoords()
- end
- while y > 0 do
- turtle.digDown()
- turtle.down()
- y = y - 1
- updateCoords()
- end
- else
- turtle.dig()
- turtle.forward()
- updateForward()
- end
- else
- updateForward()
- end
- turtle.select(16)
- turtle.suckDown()
- turtle.placeDown()
- end
- function dropWood()
- for i = 2, 15, 1 do
- turtle.select(i)
- turtle.dropDown()
- end
- end
- function getCoords()
- local f = fs.open("coords", "r")
- if f ~= nil then
- x = readNumber(f)
- y = readNumber(f)
- z = readNumber(f)
- r = readNumber(f)
- fl.close()
- else
- x = 0
- y = 0
- z = 0
- r = 0
- updateCoords()
- end
- end
- function returnHome()
- while r ~= 1 do turnLeft() end
- while x > 0 do treeFeller() end
- while r ~= 2 do turnRight() end
- while z > 0 do treeFeller() end
- end
- -- main
- getCoords()
- returnHome()
- dropWood()
- while true do
- while turtle.getFuelLevel() < minFuel do
- print("Waiting for fuel in slot 1")
- turtle.select(1)
- turtle.refuel()
- end
- turnRight()
- while z < mz do
- while x < mx do
- treeFeller()
- end
- turnRight()
- treeFeller()
- turnRight()
- while x > 0 do
- treeFeller()
- end
- if z == mz then
- break
- else
- turnLeft()
- treeFeller()
- turnLeft()
- end
- end
- returnHome()
- dropWood()
- sleep(120)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement