Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local sideLength = 7
- local inspectAttempts = 5
- local desiredFuelPercent = 0.5
- local move = {
- forward = function()
- while not turtle.forward() do
- turtle.dig()
- end
- end,
- up = function()
- while not turtle.up() do
- turtle.digUp()
- end
- end,
- down = function()
- while not turtle.down() do
- turtle.digDown()
- end
- end
- }
- local checkBlock = {
- forward = function(name)
- local i
- for i = 1, inspectAttempts do
- local success, blockData = turtle.inspect()
- if success then
- return blockData.name:find(name) ~= nil
- end
- end
- end,
- up = function(name)
- local i
- for i = 1, inspectAttempts do
- local success, blockData = turtle.inspectUp()
- if success then
- return blockData.name:find(name) ~= nil
- end
- end
- end,
- down = function(name)
- local i
- for i = 1, inspectAttempts do
- local success, blockData = turtle.inspectDown()
- if success then
- return blockData.name:find(name) ~= nil
- end
- end
- end
- }
- local function checkItem(name, slot)
- local item = turtle.getItemDetail(slot)
- return item and item.name:find(name)
- end
- local function selectItem(name)
- local i
- for i = 1, 16 do
- if checkItem(name, i) then
- turtle.select(i)
- return
- end
- end
- end
- local function chopTreeIfExists()
- if checkBlock.down('log') then
- turtle.digDown()
- selectItem('sapling')
- turtle.placeDown()
- end
- local height, i = 0
- while checkBlock.up('log') do
- move.up()
- height = height + 1
- end
- for i = 1, height do
- move.down()
- end
- end
- local function transferItem(name, slot)
- local i
- if not checkItem(name, slot) and turtle.getItemCount(slot) > 0 then
- turtle.select(slot)
- for i = 1, 16 do
- if i ~= slot and turtle.getItemCount(i) == 0 then
- turtle.transferTo(i)
- break
- end
- end
- end
- for i = 1, 16 do
- if checkItem(name, i) then
- turtle.select(i)
- turtle.transferTo(slot)
- end
- end
- end
- while true do
- move.forward()
- chopTreeIfExists()
- local i, j
- for i = 1, sideLength do
- for j = 1, sideLength - 1 do
- move.forward()
- chopTreeIfExists()
- end
- if i < sideLength then
- if i % 2 == 1 then
- turtle.turnRight()
- move.forward()
- chopTreeIfExists()
- turtle.turnRight()
- else
- turtle.turnLeft()
- move.forward()
- chopTreeIfExists()
- turtle.turnLeft()
- end
- end
- end
- move.forward()
- transferItem('sapling', 1)
- if checkBlock.down('barrel') then
- for i = 2, 16 do
- if turtle.getItemCount(i) > 0 then
- turtle.select(i)
- turtle.dropDown()
- end
- end
- end
- if checkBlock.forward('pedestal') then
- turtle.select(1)
- turtle.suck(turtle.getItemSpace(1))
- end
- turtle.turnRight()
- if
- turtle.getFuelLevel() ~= 'unlimited' and checkBlock.forward('pedestal') and
- turtle.getFuelLevel() < turtle.getFuelLimit() * desiredFuelPercent
- then
- turtle.select(16)
- turtle.suck()
- turtle.refuel()
- end
- turtle.turnRight()
- sleep(60)
- end
Advertisement
Add Comment
Please, Sign In to add comment