Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- IDS
- sapplingId = "environmental:willow_sapling"
- logId = "environmental:willow_log"
- bonemealId = "minecraft:bone_meal"
- -- other settings
- count = 10 --max height turtle will go
- fuelBuffer = 50
- idleTime = 0.2
- maxSlotsFull = 15
- sappingSlot = 1
- logSlot = 2
- bonemealSlot = 12
- ---
- print("Make sure to put sappings in slot "..tostring(sappingSlot).." and logs in slot " .. tostring(logSlot) .. " and bonemal in slot "..tostring(bonemealSlot))
- function isCorrectItem(slot,name)
- turtle.select(slot)
- local id = turtle.getItemDetail() or "nothing"
- if id == "nothing" then
- return "nothing"
- end
- i1 = id.name
- if i1 == name then
- return true
- else
- return false
- end
- end
- function ensureCorrectItem(slot,name,isOptional)
- local isCorrect = isCorrectItem(slot,name)
- function repond(itemName, slot)
- print("Incorrect items")
- print("Please insert"..itemName.." into "..tostring(slot) )
- end
- if isCorrect == true then
- return true -- tell caller all went well
- end
- if isOptional == true then
- -- check if slot has nothing
- if isCorrect == "nothing" then
- return true --- tell caller all went well!
- end
- -- if it has something , check that it has bonemeal
- if isCorrect == false then
- repond(name,slot)
- write(" or empty it")
- --- wait until something is in slot
- while isCorrectItem(slot,name) == false do
- sleep(2)
- write(".")
- end
- return false -- tell caller to retry check
- end
- error("Something weird happened @ensureCorrectItem")
- else
- --check if slot has nothing
- if isCorrect == "nothing" then
- respond(name,slot)
- while isCorrectItem(slot,name) == false do
- sleep(2)
- write(".")
- end
- return false
- end
- --check if slot has the wrong item
- if isCorrect == false then
- respond(name,slot)
- while isCorrectItem(slot,name) == false do
- sleep(2)
- write(".")
- end
- return false
- end
- --return
- error("this should not have happened")
- return
- end
- error("Uknown error @ensureCorrectItem")
- end
- -- 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
- turtle.select(1)
- --- 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,force)
- isFullCounter = isFullCounter + 1
- if isFullCounter < isFullCounterMax and not force 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
- --make sure slots have correct items
- ensureCorrectItem(1,sapplingId,false)
- ensureCorrectItem(2,logId,false)
- ensureCorrectItem(bonemealSlot,bonemealId,true)
- -- 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)
- if turtle.getItemCount() > 0 then
- turtle.place()
- else
- end
- --Stop if full
- if isFull(maxSlotsFull) then
- print("Overfilled - please empty turtle to continue")
- while isFull(maxSlotsFull,true) do
- sleep(2)
- write(".")
- end
- print("resuming")
- end
- end
Add Comment
Please, Sign In to add comment