Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- count = 10 --max height turtle will go
- fuelBuffer = 50
- idleTime = 0.2
- maxSlotsFull = 16
- bonemealSlot = 12
- print("Make sure to put sappings in slot one and logs in slot two and bonemal in slot 16")
- -- make sure a slot is as full as possible
- function combine(slot)
- ---Make sure slot is not already full
- turtle.select(slot)
- if turtle.getItemCount() == 64 then return end
- if turtle.getItemCount() > 1 then
- for i=1,16 do
- turtle.select(i)
- if turtle.getItemCount() >0 then
- if turtle.compareTo(i) then
- turtle.transferTo(slot)
- end
- end
- end
- else
- return "slot empty"
- end
- end
- -- see if there is tree left to dig up
- function isBlock()
- local fwd = turtle.detect()
- local up turtle.detectUp()
- if fwd == true then return true end
- if up == true then return true end
- return false
- end
- function main()
- --- do something repeatedly
- function rpt(func,count)
- for i=1, count do
- func()
- end
- end
- --- dig log then go up
- for i=1, count do
- turtle.dig()
- turtle.suck()
- turtle.digUp()
- turtle.suck()
- turtle.up()
- -- if no logs left, go back
- if not isBlock() then
- rpt(
- function()
- turtle.down()
- end, i
- )
- return
- end
- end
- -- go back down if haven't already
- rpt(
- turtle.down,
- count
- )
- end
- isFullCounterMax = 10
- isFullCounter = 0 -- allows running only every n-th call
- function isFull(maxFull)
- isFullCounter = isFullCounter + 1
- if isFullCounter < isFullCounterMax then return end
- isFullCounter = 0
- local c1 = combine(1)
- local c2 = combine(2)
- if c1=="slot empty" or c2 =="slot empty" then
- print("Please refill slots 1 and 2")
- while combine(1) == "slot empty" do
- sleep(2)
- write(".")
- end
- while combine(2) == "slot empty" do
- sleep(2)
- write(".")
- end
- end
- function returnIfEnough(slotsEmpty,slotsFull,maxEmpty,maxFull)
- --print("slots empty / max empty: "..tostring(slotsEmpty).."/"..tostring(maxEmpty))
- if slotsEmpty>=maxEmpty then
- return false
- elseif slotsFull>=maxFull then
- return true
- else
- return nil
- end
- end
- --- --maxFull = n
- local slotsEmpty = 0
- local slotsFull = 0
- local maxEmpty = 17-maxFull
- for slot=1,16 do
- turtle.select(slot)
- local qtyInSlot = turtle.getItemCount()
- local isEmpty = qtyInSlot < 1
- if isEmpty then
- slotsEmpty = slotsEmpty+1
- else
- slotsFull = slotsFull+1
- end
- local enough = returnIfEnough(slotsEmpty,slotsFull,maxEmpty,maxFull)
- if enough ~= nil then return enough end
- end
- local enough = returnIfEnough(slotsEmpty,slotsFull,maxEmpty,maxFull)
- if enough ~= nil then return enough end
- error("unknown error @isFull")
- end
- function isTree()
- --is there a tree?
- local i1,i2 = turtle.inspect()
- local block = i2.name or "nothing"
- local affix = string.sub(block,-3,-1)
- if turtle.detect() and affix == "log" then
- main()
- turtle.select(1)
- turtle.place()
- --organise slotss
- end
- end
- while true do
- -- if there's a tree, then dig it up
- isTree()
- --idle some
- sleep(idleTime )
- --refuel if neccesary and show fuel level
- local fuelSlot = 2
- local fuel = turtle.getFuelLevel()
- while turtle.getFuelLevel() < fuelBuffer do
- turtle.select(fuelSlot)
- turtle.refuel(1)
- if turtle.getItemCount() <1 then
- print("Please put more fuel into slot "..tostring(fuelSlot))
- sleep(2)
- while turtle.getItemCount() <1 do
- sleep(2)
- write(" .")
- end
- end
- end
- print(turtle.getFuelLevel())
- --Place a new sappling
- turtle.select(1)
- turtle.place()
- -- pickup left over items
- turtle.suck()
- turtle.suckUp()
- --Allow for bonemeal being used
- turtle.select(bonemealSlot)
- turtle.place()
- --Stop if full
- if isFull(maxSlotsFull) then
- print("Overfilled, please empty turtle to continue")
- while isFull(maxSlotsFull) do
- sleep(2)
- end
- print("resuming")
- end
- end
Add Comment
Please, Sign In to add comment