Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- os.loadAPI("inv")
- os.loadAPI("t")
- local LOG = "log"
- local SAP = "sapling"
- local COAL = "coal"
- local CHAR = "char"
- local x = 0
- local y = 0
- function chestyStuff()
- -- We can't see what's on the chest
- -- so we just grab everything
- for i=1, 16 do
- turtle.select(i)
- data = turtle.getItemDetail()
- if data ~= nil then
- if string.find(data.name, "log") then
- turtle.drop()
- end
- end
- end
- turtle.turnRight()
- if inv.getItemCount(COAL) < 64 then
- while turtle.suck() do end
- inv.stackItems()
- -- and we drop back all the logs
- while inv.selectItem("log") do
- turtle.drop()
- end
- -- Drop all but one stack of coal
- while inv.getItemCount(COAL) > 128 do
- inv.selectItem(COAL)
- turtle.drop()
- end
- end
- inv.stackItems()
- if inv.getItemCount(SAP) < 64 then
- turtle.turnLeft()
- turtle.turnLeft()
- while turtle.suck() do end
- while inv.getItemCount(SAP) > 128 do
- inv.selectItem(SAP)
- turtle.drop()
- end
- for i=1, 16 do
- turtle.select(i)
- data = turtle.getItemDetail()
- if data ~= nil then
- if not string.find(data.name, COAL) and not string.find(data.name, CHAR) and not string.find(data.name, SAP) then
- turtle.drop()
- end
- end
- end
- turtle.turnLeft()
- turtle.turnLeft()
- end
- for i=1, 16 do
- turtle.select(i)
- data = turtle.getItemDetail()
- if data ~= nil then
- if not string.find(data.name, COAL) and not string.find(data.name, CHAR) and not string.find(data.name, SAP) then
- turtle.drop()
- end
- end
- end
- inv.stackItems()
- end
- function refuelIfNeeded()
- local fuelLevel = turtle.getFuelLevel()
- if fuelLevel < 70 then
- print("Fuel level is " .. fuelLevel .. ", refueling...")
- if inv.selectItem(COAL) then
- turtle.refuel(1)
- print("Refueled! new level is " .. turtle.getFuelLevel())
- return true
- end
- printError("No fuel in inventory!")
- end
- return false
- end
- function placeSapling()
- for i=1, 16 do
- turtle.select(i)
- local data = turtle.getItemDetail()
- if (data and string.find(data.name, "sapling")) then
- turtle.place()
- break
- end
- end
- while turtle.suck() do end
- end
- function chop()
- turtle.dig()
- t.fw()
- local success = true
- local data
- local count = 0
- while success do
- success, data = turtle.inspectUp()
- if success then
- if string.find(data.name, "log") then
- t.digUp()
- t.up()
- count = count + 1
- else
- success = false
- end
- end
- end
- t.down(count)
- turtle.turnLeft()
- turtle.turnLeft()
- t.fw()
- turtle.turnLeft()
- turtle.turnLeft()
- placeSapling()
- end
- function columns(colCount)
- turtle.turnRight()
- local success, data = turtle.inspect()
- while turtle.suck() do end
- if success then
- if string.find(data.name, "log") then
- chop()
- end
- else
- placeSapling()
- end
- turtle.turnLeft()
- for i=1, 4 do
- t.fw()
- end
- turtle.turnRight()
- t.fw()
- turtle.turnLeft()
- t.fw()
- for corners=0, 2 do
- refuelIfNeeded()
- turtle.turnLeft()
- success, data = turtle.inspect()
- while turtle.suck() do end
- if success then
- if string.find(data.name, "log") then
- chop()
- end
- else
- placeSapling()
- end
- turtle.turnRight()
- for i=1, 5 do
- t.fw()
- end
- success, data = turtle.inspect()
- while turtle.suck() do end
- if success then
- if string.find(data.name, "log") then
- chop()
- end
- else
- placeSapling()
- end
- turtle.turnRight()
- t.fw()
- turtle.turnLeft()
- t.fw()
- turtle.turnRight()
- for i=1, 4 do
- t.fw()
- end
- end
- refuelIfNeeded()
- turtle.turnLeft()
- success, data = turtle.inspect()
- while turtle.suck() do end
- if success then
- if string.find(data.name, "log") then
- chop()
- end
- else
- placeSapling()
- end
- turtle.turnRight()
- turtle.turnRight()
- for i=1, 3 do
- t.fw()
- end
- turtle.turnRight()
- t.fw()
- success, data = turtle.inspect()
- while turtle.suck() do end
- if success then
- if string.find(data.name, LOG) then
- chop()
- end
- else
- placeSapling()
- end
- turtle.turnLeft()
- for i=1, 5 do
- t.fw()
- end
- for inner=0, 2 do
- refuelIfNeeded()
- turtle.turnRight()
- success, data = turtle.inspect()
- while turtle.suck() do end
- if success then
- if string.find(data.name, LOG) then
- chop()
- end
- else
- placeSapling()
- end
- if inner < 2 then
- turtle.turnRight()
- t.fw()
- turtle.turnRight()
- for i=1, 4 do
- t.fw()
- end
- end
- end
- turtle.turnLeft()
- end
- function goToChest()
- refuelIfNeeded()
- for i=1, 5 do
- t.fw()
- end
- turtle.turnRight()
- for i=1, 5 do
- t.fw()
- end
- turtle.turnLeft()
- for i=1, 3 do
- t.fw()
- end
- for i=1, 2 do
- t.down()
- end
- t.back()
- t.down()
- end
- function returnToStart()
- refuelIfNeeded()
- turtle.turnRight()
- t.up()
- t.back()
- t.up(2)
- t.fw(5)
- end
- while true do
- refuelIfNeeded()
- columns(16)
- goToChest()
- chestyStuff()
- returnToStart()
- sleep(120)
- end
Advertisement
Add Comment
Please, Sign In to add comment