Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local treeSapling = "minecraft:spruce_sapling"
- local logType = "minecraft:spruce_log"
- local rows = tonumber(arg[1])
- local currentRow = 1
- local storeItems = {}
- storeItems[logType] = true
- storeItems["minecraft:stick"] = true
- function selectItem(item)
- for i = 1, 16 do
- local data = turtle.getItemDetail(i)
- if data then
- if data.name == item then
- turtle.select(i)
- return true
- end
- end
- end
- return false
- end
- function dropItems()
- for i = 1, 16 do
- local data = turtle.getItemDetail(i)
- if data then
- if storeItems[data.name] then
- turtle.select(i)
- turtle.dropDown()
- end
- end
- end
- end
- function move()
- if turtle.getFuelLevel() <= 10 then
- if not selectItem("minecraft:coal") then
- return false
- else
- turtle.refuel(1)
- end
- end
- return turtle.forward()
- end
- function moveUp()
- if turtle.getFuelLevel() <= 10 then
- if not selectItem("minecraft:coal") then
- return false
- else
- turtle.refuel(1)
- end
- end
- return turtle.up()
- end
- function moveDown()
- if turtle.getFuelLevel() <= 10 then
- if not selectItem("minecraft:coal") then
- return false
- else
- turtle.refuel(1)
- end
- end
- return turtle.down()
- end
- function turnAround()
- turtle.turnLeft()
- turtle.turnLeft()
- end
- function goAround()
- turtle.turnRight()
- move()
- turtle.turnLeft()
- move()
- move()
- turtle.turnLeft()
- move()
- turtle.turnRight()
- checkNext()
- end
- function returnHelper()
- turtle.turnRight()
- if turtle.inspect() and
- (select(2, turtle.inspect()).name == treeSapling or select(2, turtle.inspect()).name == logType) then
- turtle.turnLeft()
- move()
- move()
- move()
- move()
- returnHelper()
- else
- turtle.turnRight()
- move()
- move()
- move()
- turtle.turnLeft()
- move()
- for i = 1, (currentRow - 1) * 4 do
- if not move() then
- print("Can't move while returning to chest")
- return false
- end
- end
- turtle.turnLeft()
- move()
- if move() then
- dropItems()
- turnAround()
- currentRow = 1
- sleep(180)
- checkNext()
- end
- end
- end
- function changeRow()
- turnAround()
- local success, data = turtle.inspect()
- while not turtle.inspect() and
- (select(2, turtle.inspect()).name ~= treeSapling or select(2, turtle.inspect()).name ~= logType) do
- if not move() then
- print("Can't move while changing row!")
- return false
- end
- end
- if currentRow == rows then
- if currentRow % 2 == 1 then
- turtle.turnLeft()
- move()
- turtle.turnRight()
- move()
- returnHelper()
- elseif currentRow % 2 == 0 then
- turtle.turnLeft()
- for i = 1, (currentRow - 1) * 4 do
- if not move() then
- print("Can't move while returning to chest")
- return false
- end
- end
- turtle.turnLeft()
- move()
- if move() then
- dropItems()
- turnAround()
- currentRow = 1
- sleep(180)
- checkNext()
- end
- end
- elseif currentRow % 2 == 1 then
- turtle.turnLeft()
- for i = 1, 4 do
- if not move() then
- print("Can't move while changing row!")
- return false
- end
- end
- turtle.turnRight()
- currentRow = currentRow + 1
- checkNext()
- elseif currentRow % 2 == 0 then
- turtle.turnRight()
- for i = 1, 4 do
- if not move() then
- print("Can't move while changing row!")
- return false
- end
- end
- turtle.turnLeft()
- currentRow = currentRow + 1
- checkNext()
- end
- end
- function placeSapling()
- if selectItem(treeSapling) then
- return turtle.place()
- else
- return false
- end
- end
- function collectSapling()
- for i = 1, 4 do
- turtle.turnLeft()
- turtle.suck()
- end
- end
- function fallTree()
- local success, data = turtle.inspectUp()
- if success and data.name == logType then
- turtle.digUp()
- moveUp()
- fallTree()
- else
- while not turtle.inspectDown() do
- moveDown()
- end
- collectSapling()
- if move() then
- collectSapling()
- turnAround()
- if placeSapling() then
- turnAround()
- checkNext()
- else
- print("Need more saplings!")
- return
- end
- else
- print("Out of fuel")
- return flase
- end
- end
- end
- function checkNext()
- move()
- collectSapling()
- move()
- collectSapling()
- local success, data = turtle.inspect()
- if success then
- if data.name == treeSapling then
- goAround()
- elseif data.name == logType then
- turtle.dig()
- move()
- fallTree()
- else
- print("Error while checking next tree")
- return false
- end
- else
- changeRow()
- end
- end
- checkNext()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement