Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- args = {...}
- -- Init variables
- local pos = {
- x = 0,
- y = 0,
- z = 0,
- f = 0
- }
- local xSize = args[1]
- local ySize = args[2]
- -- Functions
- local function moveForward()
- while turtle.detect() do turtle.dig() end
- turtle.forward()
- if pos.f == 0 then pos.x = pos.x + 1 end
- if pos.f == 2 then pos.x = pos.x - 1 end
- if pos.f == 1 then pos.y = pos.y + 1 end
- if pos.f == 3 then pos.y = pos.y - 1 end
- end
- local function moveUp()
- while turtle.detectUp() do turtle.digUp() end
- turtle.up()
- pos.z = pos.z + 1
- end
- local function moveDown()
- while turtle.detectDown() do turtle.digDown() end
- turtle.down()
- pos.z = pos.z - 1
- end
- local function turnLeft()
- turtle.turnLeft()
- pos.f = (pos.f - 1) % 4
- end
- local function turnRight()
- turtle.turnRight()
- pos.f = (pos.f + 1) % 4
- end
- local function refuel()
- if turtle.getFuelLevel() > turtle.getFuelLimit() * 0.01 then return end
- turtle.select(16)
- while turtle.refuel(0) and turtle.getFuelLevel() < turtle.getFuelLimit() * 0.01 do
- turtle.refuel(1)
- end
- turtle.select(1)
- end
- local function isItem(itemName, name)
- if string.find(itemName, name) then
- return true
- else
- return false
- end
- end
- local function goAround()
- turnRight()
- moveForward()
- turnLeft()
- moveForward()
- moveForward()
- turnLeft()
- moveForward()
- turnRight()
- end
- local function chopTheTree()
- moveForward()
- while not turtle.detectUp() do
- moveUp()
- for i = 1, 4 do
- turtle.dig()
- turnRight()
- end
- end
- for i = 1, math.abs(pos.z) do
- moveDown()
- end
- moveForward()
- turnRight()
- turnRight()
- turtle.select(15)
- turtle.place()
- turnLeft()
- turnLeft()
- end
- -- Main Code
- print("Insert saplings into slot 15")
- turtle.select(15)
- while turtle.getItemDetail() == nil do end
- while not isItem(turtle.getItemDetail().name, "sapling") do end
- print("Saplings detected")
- print("Please insert fuel into slot 16 (not wood)")
- turtle.select(16)
- while not turtle.refuel(0) do end
- print("Fuel detected, beginning the work")
- -- Main Loop
- while true do
- refuel()
- if turtle.getFuelLevel() > 20 then
- moveForward()
- if pos.f == 0 and pos.x == (3 * xSize) then
- if pos.y == (3 * ySize - 1) then
- turnLeft()
- moveForward()
- turnLeft()
- for i = 1, pos.x do
- moveForward()
- end
- turnRight()
- for i = 1, pos.y do
- moveForward()
- end
- turnLeft()
- for i = 1, 14 do
- turtle.select(i)
- turtle.drop()
- end
- turtle.select(1)
- turnRight()
- turnRight()
- else
- turnRight()
- for i = 1, 3 do
- moveForward()
- end
- turnRight()
- end
- elseif pos.f == 2 and pos.x == 1 then
- if pos.y == (3 * ySize - 1) then
- moveForward()
- turnRight()
- for i = 1, pos.y do
- moveForward()
- end
- turnLeft()
- for i = 1, 14 do
- turtle.select(i)
- turtle.drop()
- end
- turtle.select(1)
- turnRight()
- turnRight()
- else
- turnLeft()
- for i = 1, 3 do
- moveForward()
- end
- turnLeft()
- end
- end
- local b, data = turtle.inspect()
- if b ~= false then
- if isItem(data.name, "sapling") then
- goAround()
- elseif isItem(data.name, "log") then
- chopTheTree()
- end
- end
- else
- print("Waiting for fuel in slot 16")
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement