Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local sapling = "minecraft:sapling"
- local wood = "minecraft:log"
- local sleepTime = 35
- local beneath = {"minecraft:stone", 1} -- blockname, damage
- local function isHome()
- local isBlock, block = turtle.inspectDown()
- if isBlock then
- if block.name == beneath[1] and block.metadata == beneath[2] then
- return true
- end
- end
- return false
- end
- local function moveSaplings()
- local slot1 = turtle.getItemDetail(1)
- if slot1 and slot1.name ~= sapling then
- turtle.select(1)
- for i = 2, 16 do
- if turtle.transferTo(i) then
- break
- end
- end
- end
- for i = 2, 16 do
- local sloti = turtle.getItemDetail(i)
- if sloti and sloti.name == sapling then
- turtle.transferTo(1)
- end
- end
- end
- local function emptyInv()
- turtle.turnRight()
- for i = 2, 16 do
- turtle.select(i)
- turtle.drop()
- end
- turtle.turnLeft()
- end
- local function digTree()
- local up = 0
- while turtle.detectUp() do
- for i = 1, 4 do
- turtle.dig()
- turtle.turnRight()
- end
- turtle.digUp()
- turtle.up()
- up = up + 1
- end
- for i = 1, up do
- turtle.down()
- end
- turtle.back()
- end
- local function refuel()
- local function dropInGoodOrder()
- for i = 1, 16 do
- local item = turtle.getItemDetail(i)
- if item and item.name == wood then
- turtle.select(i)
- turtle.drop()
- end
- end
- for i = 1, 16 do
- turtle.select(i)
- turtle.drop()
- end
- end
- local function pullWood()
- print("Pulling wood")
- for i = 1, 16 do
- turtle.select(i)
- turtle.suck()
- local item = turtle.getItemDetail(i)
- if item and item.name ~= wood then
- turtle.drop()
- break
- elseif not item then
- break
- end
- end
- end
- local function grab()
- turtle.select(1)
- for i = 1, 16 do
- turtle.suck()
- end
- end
- local function plankRefuel()
- pullWood()
- local h = 0
- print("Checking # stacks of logs")
- for i = 1, 16 do
- if turtle.getItemCount(i) > 0 then
- h = h + 1
- end
- end
- if h == 0 then
- print("No items to refuel with.")
- grab()
- return
- end
- print("dropping extra wood")
- for i = 2, 16 do
- turtle.select(i)
- turtle.drop()
- end
- print("Crafting.")
- turtle.craft()
- print("refuelling using planks recieved.")
- for i = 1, 16 do
- turtle.select(i)
- turtle.refuel()
- end
- if h > 1 then return plankRefuel() end
- grab()
- end
- local max = turtle.getFuelLimit()
- local cur = turtle.getFuelLevel()
- print("fuel:", cur, '/', max)
- if cur < max * 0.05 then
- print("Doing a refuelly boi")
- turtle.turnLeft()
- dropInGoodOrder()
- -- drop all items in inventory into chest, wood first.
- plankRefuel()
- turtle.turnRight()
- end
- end
- local function checkLog()
- local isBlock, block = turtle.inspect()
- if isBlock then
- if block.name == wood then
- return true, true -- there is a log, place sapling after op.
- end
- if block.name ~= sapling then
- return true, true -- there isn't a log, but dig and replace what is there.
- end
- return false, false -- there is no log, but likely sapling, do not place sapling.
- end
- return false, true -- there is no block at all, place sapling.
- end
- ----------------------------------------------------------
- local function main()
- while true do
- print("==================================")
- assert(isHome(), "Please return me to homebase.")
- print("At home. Run.")
- local doDig, doSapling = checkLog()
- if doDig then
- print("Digging.")
- turtle.dig()
- turtle.forward()
- digTree()
- end
- moveSaplings()
- if doSapling then
- print("Placing a sapling.")
- turtle.select(1)
- assert(turtle.place())
- end
- print("Do Refuel.")
- refuel()
- moveSaplings()
- print("Empty inventory")
- emptyInv()
- print("Waiting " .. tostring(sleepTime) .. " seconds.")
- os.sleep(sleepTime)
- end
- end
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement