Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- TreeFarmer
- by Severino
- Version 4.1.1
- This program will plant a grove of trees, fertilizing as it goes, then will return to each tree and harvest it if it has grown and collect the saplings. The saplings and anything else dropped by the harvested trees will be collected. The saplings collected will be used to replant and extra will placed in the chest containing the sapling. Everything else that is collected will be placed in an inventory chest.
- If the turtle runs into something not expected, it will report that it was blocked then destroy it. If the supply of fuel in the turtle drops to 1 then it reports that it is out of fuel and wait to be refueled. If the supply of saplings drops to 1 it will contintreeue to harvest trees and collect more saplings. It will never use the last sapling so it has something to compare with.
- You can start the tree farm with two or more saplings or a single sapling and an existing tree. It will harvest the trees that it finds and collect saplings, and then continue to use those saplings to populate the tree farm.
- At the end of each transit through the tree farm the excess saplings will be placed in the sapling chest. If the sapling chest becomes full, it will report that problem and wait for the chest to be emptied. It will also deposit any wood and other items collected from harvesting and place them in the inventory chest. If this chest becomes full it will report the problem and wait for it to be emptied. If it runs out of bonemeal it will continue to plant and harvest but the trees will not be harvested until they have grown.
- Added the ability to automatically restart even stopped in the middle of harvesting. This is accomplished by placing a railing around the logging area, and placing a chest and railing in the turtle to he can determine the borders and the starting position.
- Added furnaces so that if the turtle runs out of fuel, or if the inventory chest becomes full, the he can make charcoal, until the fuel chest becomes full.
- Now doesn't use a set number of rows and column. Trees will be planted in all space available between the fences.
- Materials Required:
- 1 mining or felling turtle
- 4 chests
- a sapling for each tree location (numberOfRows * treesPerRow)
- 1 log same type as the sapling
- fuel (suggest coal or coalcoke)
- 1 railing (used to identify borders of grove on startup.)
- 1 chest (used to identify starting position and orientation.)
- bone meal (optional)
- Setup:
- Diagram:
- +-F-F-F----------------------------...-------------------------------------+
- | |
- : :
- | |
- |s |
- |a |
- |p |
- [inv]X |
- |b |
- |o |
- |n |
- | |
- : :
- | |
- +------------------------------------...-----------------------------------+
- [inv] = Inventory Chest
- sap = Sapling Chest
- bon = Bone meal Chest
- X = Fuel Chest below turtle will charcoal
- + - | = Fencing or Gates around area for grove of trees, any size.
- F = Furnace (0 or more, above the fence with 1 empty space between the fence and the furnace, and 1 empty space between each furnace)
- There are variables in the beginning of the program that set the number of trees that will be in each row and the number of rows to plant, as well as the space between the trees. These should be modified to suit your preferences.
- Place turtle over a chest in a level dirt field facing away. Place a chest to the left, right and behind the turtle. These can be single or double chests.
- Place fuel in the chest under the turtle. Place saplings in the chest to the left. Place bone meal in the chest to the right. The chest behind the turtle starts out empty and will be filled with the wood that is harvested and anything else dropped by the harvested trees.
- Put a fence around the level area that will contain the trees with the sapling and bone meal chest inside of the fence one block.
- Put fuel in slot 1, fertilizer in slot 2, a chest in slot 3, a fence in slot 4, a gate in slot 5, saplings in slot 6, and a block of wood of the same type that is to be harvested in slot 7.
- Setup
- Slot 1 = Fuel (charcoal)
- Slot 2 = Fertilizer
- Slot 3 = Chest
- Slot 4 = Fence
- Slot 5 = Gate
- Slot 6 = Saplings
- Slot 7 = Wood same type as sapling
- ]]--
- version = "4.1.1"
- treesPerRow = 6
- numberOfRows = 4
- spaceBetweenTrees = 4
- plantTrees = true -- Set to false to clear tree grove.
- harvestWide = false -- True means to harvest everything on each level of a tree, including leaves
- slotFuel = 1
- slotBonemeal = 2
- slotChest = 3
- slotFence = 4
- slotGate = 5
- slotSapling = 6
- -- You can use the wood it harvests as fuel if you want. If so then use slotWood = slotFuel
- slotWood = 7
- logfile = nil
- abortCircuit = false
- minerID = os.getComputerID()
- consoleID = 0
- furnaceCount = nil
- function checkSetup()
- updateStatus("Checking Setup")
- if turtle.getItemCount(slotFuel) < 2 then
- updateStatus("2+ Fuel needed in slot "..slotFuel)
- while turtle.getItemCount(slotFuel) < 2 do
- sleep(2)
- end
- else
- updateStatus(turtle.getItemCount(slotFuel).." fueld present in slot "..slotFuel)
- end
- if turtle.getItemCount(slotBonemeal) < 1 then
- updateStatus("Fertilizer recommended in slot "..slotBonemeal)
- else
- updateStatus("Fertilizer present in slot "..slotBonemeal)
- end
- if turtle.getItemCount(slotChest) < 1 then
- updateStatus("Chest needed in slot "..slotChest)
- while turtle.getItemCount(slotChest) < 1 do
- sleep(2)
- end
- else
- updateStatus("Chest present in slot "..slotChest)
- end
- if turtle.getItemCount(slotFence) < 1 then
- updateStatus("Fence needed in slot "..slotFence)
- while turtle.getItemCount(slotFence) < 1 do
- sleep(2)
- end
- else
- updateStatus("Fence present in slot "..slotFence)
- end
- if turtle.getItemCount(slotGate) < 1 then
- updateStatus("Gate may be needed in slot "..slotGate)
- else
- updateStatus("Gate present in slot "..slotGate)
- end
- if turtle.getItemCount(slotSapling) < 1 then
- updateStatus("Saplings needed in slot "..slotSapling)
- while turtle.getItemCount(slotSapling) < treesPerRow * numberOfRows do
- sleep(2)
- end
- else
- updateStatus(turtle.getItemCount(slotSapling) .. " Saplings present in slot "..slotSapling)
- end
- if turtle.getItemCount(slotWood) < 1 then
- updateStatus("Wood needed in slot "..slotWood)
- while turtle.getItemCount(slotWood) < 1 do
- sleep(2)
- end
- else
- updateStatus("Wood present in slot "..slotWood)
- end
- end
- function updateStatus(msg, silent)
- if not rednet.isOpen("right") then rednet.open("right") end
- if rednet.isOpen("right") then
- networkmsg = "Miner ".. minerID..": "..msg
- if consoleID == 0 then
- rednet.broadcast(networkmsg)
- else
- rednet.send(consoleID,networkmsg)
- end
- end
- if not silent then print(msg) end
- updateLog(msg)
- end
- function getConsoleID()
- local fname = "ConsoleID"
- if fs.exists(fname) then
- file = fs.open(fname, "r")
- consoleID = tonumber(file.readAll())
- file.close()
- print("Monitor Console ID: "..consoleID)
- else
- updateStatus("Waiting for Console ID...",true)
- term.write("Monitor Console ID: ")
- consoleID = io.read()
- file = fs.open(fname, "w")
- file.write(consoleID)
- file.close()
- consoleID = tonumber(consoleID)
- end
- end
- function updateLog(msg)
- local fname = 'log'
- if fs.exists(fname) then
- logfile = fs.open(fname, "a")
- else
- logfile = fs.open(fname, "w")
- end
- updateTime = textutils.formatTime(os.time())
- logfile.write(updateTime.." "..msg.."\n")
- logfile.close()
- end
- function selectSapling()
- -- Look at all of the slots and if a slot other than the default sapling slot contains saplings, then return this slot.
- local slot = 0
- for slot=1,16 do
- if slot ~= slotSapling then
- if turtle.getItemCount(slot) > 1 then
- turtle.select(slot)
- if turtle.compareTo(slotSapling) then return true end
- end
- end
- end
- if turtle.getItemCount(slotSapling) > 1 then
- turtle.select(slotSapling)
- return true
- end
- return false
- end
- function selectWood()
- local slot = 0
- for slot = slotWood + 1,16 do
- turtle.select(slot)
- if turtle.compareTo(slotWood) then return true end
- end
- return false
- end
- function selectBonemeal()
- -- Look at all of the slots and if a slot other than the default bone meal slot contains bone meal, then move them into the default bone meal slot.
- local slot = 0
- for slot=1,16 do
- if slot ~= slotBonemeal then
- if turtle.getItemCount(slot) > 1 then
- turtle.select(slot)
- if turtle.compareTo(slotBonemeal) then return true end
- end
- end
- end
- if turtle.getItemCount(slotBonemeal) > 1 then
- turtle.select(slotBonemeal)
- return true
- end
- return false
- end
- function plantSapling()
- -- Plant a sapling report if there is a problem.
- if plantTrees then
- if selectSapling() then
- if turtle.place() then
- return true
- else
- updateStatus("Unable to plant sapling.")
- return false
- end
- else
- updateStatus("Out of saplings.")
- return false
- end
- else
- return false
- end
- end
- function applyBonemeal()
- -- Apply fertilizer and report if there is a problem.
- if selectBonemeal() then
- local cnt = 0
- local applied = false
- while isSapling() and cnt < 10 do
- if selectBonemeal() then
- if turtle.place() then applied = true end
- cnt = cnt + 1
- end
- end
- if applied then
- return true
- else
- updateStatus("Unable to fertilize.")
- return false
- end
- else
- updateStatus("Out of fertilizer.")
- return false
- end
- end
- function refuel()
- -- Refuel from the slot specified if needed
- turtle.select(slotFuel)
- -- Check to see if any other slot has the same material
- local s = 0
- for s=1,16,1 do
- if s ~= slotFuel and s ~= slotWood then
- if turtle.compareTo(s) then
- turtle.select(s)
- turtle.transferTo(slotFuel)
- end
- end
- end
- -- Make sure there is enough fuel to harvest every tree and the distance between
- while turtle.getFuelLevel() <= (treesPerRow * numberOfRows) * 10 * 2
- + (treesPerRow * numberOfRows * spaceBetweenTrees)
- + (spaceBetweenTrees * 2) do
- turtle.select(slotFuel)
- if turtle.getItemCount(slotFuel) <= 1 then
- updateStatus("Out of fuel.")
- return false
- end
- local q = turtle.getItemCount(slotFuel) - 1
- if q > 5 then q = 5 else updateStatus("Low on fuel.") end
- turtle.refuel(q)
- updateStatus("Refueled to level: "..turtle.getFuelLevel())
- end
- turtle.select(slotWood)
- if turtle.getFuelLevel() < treesPerRow * numberOfRows * spaceBetweenTrees then
- abortCircuit = true
- return false
- else
- return true
- end
- end
- function moveForward()
- turtle.suck()
- if not turtle.forward() then
- updateStatus("Path blocked.")
- if turtle.detect() then
- -- Something is there so try destroy it!!!
- turtle.dig()
- end
- while not turtle.forward() do
- sleep(2)
- end
- end
- end
- function moveBack()
- turtle.suck()
- if not turtle.back() then
- updateStatus("Path blocked.")
- while not turtle.back() do
- sleep(2)
- end
- end
- end
- function goForward()
- turtle.suck()
- return turtle.forward()
- end
- function gatherSaplings()
- -- Should be facing sapling or where tree was. Move around the tree collecting anything that has dropped.
- turtle.select(slotWood)
- refuel()
- turtle.suck()
- turtle.turnLeft()
- moveForward()
- turtle.suck()
- turtle.turnRight()
- moveForward()
- turtle.suck()
- turtle.turnLeft()
- turtle.suck()
- turtle.turnRight()
- moveForward()
- turtle.suck()
- turtle.turnLeft()
- turtle.suck()
- turtle.turnRight()
- turtle.turnRight()
- moveForward()
- turtle.suck()
- turtle.turnLeft()
- turtle.suck()
- turtle.turnRight()
- moveForward()
- turtle.suck()
- turtle.turnLeft()
- turtle.suck()
- turtle.turnRight()
- turtle.turnRight()
- moveForward()
- turtle.suck()
- turtle.turnLeft()
- turtle.suck()
- turtle.turnRight()
- moveForward()
- turtle.suck()
- turtle.turnRight()
- turtle.suck()
- turtle.turnRight()
- turtle.suck()
- end
- function isWood()
- turtle.select(slotWood)
- local woodFound = turtle.compare()
- return woodFound
- end
- function isWoodUp()
- turtle.select(slotWood)
- local woodFound = turtle.compareUp()
- return woodFound
- end
- function isSapling()
- local saplingFound = false
- turtle.select(slotSapling)
- saplingFound = turtle.compare()
- if not saplingFound then print("Not a sapling.") end
- return saplingFound
- end
- function harvestLevel()
- -- Don't go too far so limit expansion to half the distance between the trees.
- local found = false
- for d=1,4 do
- if not refuel() then return false end
- local c = 0
- while turtle.detect() and c < spaceBetweenTrees-2 do
- c = c + 1
- found = true
- turtle.dig()
- turtle.forward()
- turtle.turnLeft()
- if turtle.detect() then
- turtle.dig()
- turtle.forward()
- turtle.dig()
- turtle.turnLeft()
- turtle.dig()
- turtle.turnLeft()
- turtle.turnLeft()
- turtle.dig()
- turtle.turnLeft()
- turtle.back()
- end
- turtle.turnLeft()
- turtle.turnLeft()
- if turtle.detect() then
- turtle.dig()
- turtle.forward()
- turtle.dig()
- turtle.turnLeft()
- turtle.dig()
- turtle.turnLeft()
- turtle.turnLeft()
- turtle.dig()
- turtle.turnLeft()
- turtle.back()
- end
- turtle.turnLeft()
- end
- for a=1,c do turtle.back() end
- turtle.turnLeft()
- end
- return found
- end
- function harvestWood()
- if isWood() then
- turtle.dig()
- return true
- else
- return false
- end
- end
- function harvestTrunk()
- -- Go up the trunk and clear each level spreading out up to half the distance between the trees.
- turtle.select(slotWood)
- if turtle.detect() then
- turtle.dig()
- turtle.forward()
- turtle.suck()
- local h = 0
- if harvestWide then
- while harvestLevel() or isWoodUp() do
- turtle.digUp()
- if turtle.up() then h = h + 1 end
- end
- else
- while isWoodUp() do
- turtle.digUp()
- if turtle.up() then h = h + 1 else break end
- end
- end
- local d = 1
- refuel()
- while d <= h do
- if turtle.detectDown() then
- turtle.digDown()
- end
- if turtle.down() then
- d = d + 1
- end
- end
- turtle.suck()
- turtle.back()
- end
- end
- function saplingsAvailable()
- local saplingCount = 0
- for slot=1,16 do
- if slot == slotSapling then
- saplingCount = saplingCount + turtle.getItemCount(slot)
- else
- turtle.select(slot)
- if turtle.compareTo(slotSapling) then
- saplingCount = saplingCount + turtle.getItemCount(slot)
- end
- end
- end
- return saplingCount
- end
- function facingAChest()
- turtle.select(slotChest)
- return turtle.compare()
- end
- function aboveAChest()
- turtle.select(slotChest)
- return turtle.compareDown()
- end
- function facingAFence()
- turtle.select(slotFence)
- if turtle.compare() then return true end
- turtle.select(slotGate)
- return turtle.compare()
- end
- function aboveAFence()
- turtle.select(slotFence)
- if turtle.compareDown() then return true end
- turtle.select(slotGate)
- return turtle.compareDown()
- end
- function serviceFurnaces()
- -- Load up on wood first.
- turtle.turnRight()
- turtle.turnRight()
- turtle.select(slotWood+1)
- while turtle.suck() do
- -- Keep taking wood until full.
- end
- -- Now unload the top 2 slots to get fuel
- for slot=15,16 do
- turtle.select(slot)
- if turtle.compareTo(slotWood) then turtle.drop() end
- end
- turtle.turnRight()
- turtle.turnRight()
- updateStatus("Checking furnaces")
- local distanceToFence = 0
- moveForward()
- turtle.turnLeft()
- while not facingAFence() do
- moveForward()
- distanceToFence = distanceToFence + 1
- end
- turtle.up()
- moveForward()
- -- Should now be above the fence below the furnace.
- if furnaceCount == nil then
- if turtle.detectUp() then furnaceCount = 1 else furnaceCount = 0 end
- end
- furnaceIdx = 1
- anotherFurnace = true
- while turtle.detectUp() and anotherFurnace do
- updateStatus("Loading furnace "..furnaceIdx)
- while selectWood() and turtle.dropUp() do
- -- Keep adding wood to furnace as fuel until out of wood or furnace is full.
- end
- -- Now move to the top to add material to smelt
- if turtle.back() then
- if turtle.up() then
- if turtle.up() then
- if turtle.forward() then
- if turtle.detectDown() then
- while selectWood() and turtle.dropDown() do
- -- Keep adding wood to furnace to smelt until out of wood or furnace is full.
- end
- -- Now move to the right of the furnace to remove fuel
- turtle.turnLeft()
- if turtle.back() then
- if turtle.down() then
- updateStatus("Unloading furnace "..furnaceIdx)
- turtle.select(slotFuel)
- while turtle.suck() do
- -- Remove all fuel in furnace
- end
- turtle.turnRight()
- turtle.turnRight()
- if not turtle.detect() then anotherFurnace = false end
- turtle.turnLeft()
- turtle.turnLeft()
- turtle.up()
- end
- turtle.forward()
- end
- turtle.turnRight()
- end
- moveBack()
- end
- turtle.down()
- end
- turtle.down()
- end
- turtle.forward()
- end
- -- Now go to the next furnace if there is wood available
- if selectWood() and anotherFurnace then
- turtle.turnRight()
- if turtle.forward() then
- if turtle.forward() then
- furnaceIdx = furnaceIdx + 1
- if turtle.detectUp() then furnaceCount = furnaceCount + 1 end
- end
- end
- turtle.turnLeft()
- end
- end
- -- Now return the first furnace
- if furnaceIdx > 1 then
- turtle.turnLeft()
- for bi = 1,furnaceIdx-1 do
- turtle.forward()
- turtle.forward()
- end
- turtle.turnRight()
- end
- -- Now return to start and unload extra wood and fuel
- updateStatus("Returning to start.")
- turtle.turnLeft()
- turtle.turnLeft()
- moveForward()
- if not turtle.down() then
- turtle.digDown()
- while not turtle.down() do
- updateStatus("Down blocked.")
- sleep(10)
- end
- end
- for di = 1,distanceToFence do moveForward() end
- turtle.turnRight()
- moveForward()
- -- Should be back at the start. - make sure.
- turtle.select(slotChest)
- if not turtle.compareDown() then
- -- Lost so find home.
- updateStatus("Lost. Returning to start.")
- locateStartingPosition()
- turtle.turnRight()
- turtle.turnRight()
- end
- -- Unload extra fuel.
- for s = slotWood+1,16 do
- turtle.select(s)
- if turtle.getItemCount(s) > 0 then
- if not turtle.dropDown() then
- updateStatus("Fuel chest full. Waiting...")
- while not turtle.dropDown() do sleep(30) end
- end
- end
- end
- -- Unload extra wood
- for s = slotWood+1,16 do
- turtle.select(s)
- if turtle.compareTo(slotWood) then
- if not turtle.drop() then
- updateStatus("Inventory chest full. Waiting...")
- while not turtle.drop() do sleep(30) end
- end
- end
- end
- turtle.select(slotWood)
- turtle.drop(turtle.getItemCount(slotWood)-1)
- turtle.turnLeft()
- turtle.turnLeft()
- updateStatus("Finished servicing furnaces.")
- end
- function locateStartingPosition()
- -- Move down and forward until a chest or fence is located.
- local atHome = false
- -- In case stopped while servicing furnaces.
- if turtle.detectUp() or turtle.detectDown() then
- if not turtle.back() then
- turtle.turnRight()
- turtle.back()
- end
- end
- -- Now get down to the ground.
- while not turtle.detectDown() do turtle.down() end
- if aboveAChest() then
- print("Above a chest")
- while facingAChest() do
- turtle.turnRight()
- end
- print("At home")
- atHome = true
- end
- while not atHome do
- updateStatus("Looking for a chest")
- while not facingAChest() do
- refuel()
- while facingAFence() do
- turtle.turnRight()
- updateStatus("Found a fence")
- end
- if not goForward() then
- print("Can't go fwd")
- if isWood() then
- turtle.turnRight()
- elseif turtle.up() then
- if goForward() then
- if aboveAFence() then
- updateStatus("Found a fence")
- turtle.back()
- turtle.turnRight()
- end
- else
- turtle.turnRight()
- end
- else
- turtle.turnLeft()
- end
- end
- if aboveAFence() then
- updateStatus("Found a fence")
- turtle.back()
- turtle.turnRight()
- end
- while not turtle.detectDown() do turtle.down() end
- end
- updateStatus("Found a chest")
- -- Now we should be facing a Chest.
- if aboveAChest() then
- atHome = true
- else
- turtle.turnLeft()
- if facingAFence() then
- turtle.turnRight()
- break
- else
- turtle.turnRight()
- turtle.turnRight()
- if facingAFence() then
- turtle.turnLeft()
- break
- end
- end
- end
- end
- local overChests = true
- if not atHome then
- turtle.up()
- turtle.forward()
- sleep(.3)
- if not aboveAChest() then overChests = false end
- turtle.forward()
- sleep(.3)
- if not aboveAChest() then overChests = false end
- turtle.forward()
- turtle.down()
- sleep(.3)
- if not aboveAChest() then overChests = false end
- end
- if overChests then atHome = true else updateStatus("Lost a chest") end
- if atHome then
- -- Should now be in the home position.
- -- Now determine the correct orientation.
- local foundOpening = false
- for d=1,4 do
- if not facingAChest() then
- foundOpening = true
- updateStatus("In start position.")
- break
- end
- turtle.turnLeft()
- end
- if not foundOpening then
- while true do
- updateStatus("I'm lost and need help...")
- sleep(60)
- end
- end
- else
- while true do
- updateStatus("I'm lost and need help...")
- sleep(60)
- end
- end
- end
- function suckItUp(n)
- local d
- for d=1,4 do
- if n%2 == 0 then turtle.turnLeft() else turtle.turnRight() end
- turtle.suck()
- end
- end
- -- Program begins
- updateStatus("Starting")
- term.clear()
- term.setCursorPos(1,1)
- print("Velander's Tree Farmer "..version)
- print("Turtle ID: "..minerID)
- getConsoleID()
- checkSetup()
- local col = 0
- local row = 0
- local slot = 0
- local leftShift = 0
- fuelChestEmpty = false
- locateStartingPosition()
- abortCircuit = false
- while true do
- -- Before we start planting make sure the turtle is properly equiped
- print("Checking fuel")
- if turtle.getItemCount(slotFuel) < 64 then
- -- Load up on fuel.
- print("Getting fuel "..64-turtle.getItemCount(slotFuel))
- turtle.select(slotFuel)
- if not turtle.suckDown(64-turtle.getItemCount(slotFuel)) then fuelChestEmpty = true end
- end
- -- Put back any extra fuel
- for d=1,16 do
- turtle.select(d)
- if d ~= slotFuel and turtle.compareTo(slotFuel) then turtle.dropDown() end
- end
- if fuelChestEmpty then serviceFurnaces() end
- if not refuel() then
- updateStatus("Out of fuel. Waiting.")
- while not refuel() do sleep(30) end
- end
- print("Checking bone meal")
- if turtle.getItemCount(slotBonemeal) < (treesPerRow * numberOfRows) then
- -- Load up on bonemeal if available.
- turtle.turnRight()
- -- Get enough bonemeal to fertilize all trees if necessary
- turtle.select(slotBonemeal)
- turtle.suck((treesPerRow * numberOfRows)-turtle.getItemCount(slotBonemeal)+1)
- turtle.turnLeft()
- end
- print("Checking saplings")
- local saplingCount = saplingsAvailable()
- if saplingCount <= (treesPerRow * numberOfRows) then
- turtle.turnLeft()
- turtle.select(slotSapling)
- while turtle.suck((treesPerRow * numberOfRows)-saplingCount+1) do
- saplingCount = saplingsAvailable()
- if saplingCount > (treesPerRow * numberOfRows) then break end
- turtle.select(slotSapling)
- end
- turtle.turnRight()
- end
- if saplingsAvailable() <= 1 then
- -- Out of saplings so restock from chest
- updateStatus("Out of saplings.")
- end
- local reachedEndOfCol = false
- local reachedEndOfRows = false
- local rowLength = 0
- local row = 1
- while not reachedEndOfRows do
- -- Move to beginning of grove.
- if row == 1 then
- moveForward()
- turtle.turnLeft()
- while not facingAFence() do
- moveForward()
- leftShift = leftShift + 1
- end
- moveBack()
- leftShift = leftShift - 1
- moveBack()
- leftShift = leftShift - 1
- turtle.turnRight()
- else
- turtle.turnRight()
- updateStatus("Moving to row "..row)
- for p=1,spaceBetweenTrees do
- if facingAFence() then
- reachedEndOfRows = true
- for l=1,p-1 do moveBack() end
- row = row - 1
- break
- else
- moveForward()
- suckItUp(p)
- end
- end
- if not reachedEndOfRows then
- moveBack()
- moveBack()
- end
- turtle.turnLeft()
- end
- if not reachedEndOfRows then
- updateStatus("Starting row "..row)
- reachedEndOfCol = false
- treesPerRow = 0
- rowLength = 0
- while not reachedEndOfCol do
- refuel()
- if abortCircuit then break end
- -- Move between trees sucking as you go.
- for p=1,spaceBetweenTrees do
- if facingAFence() then
- updateStatus("Found a fence in row "..row)
- reachedEndOfCol = true
- else
- moveForward()
- suckItUp(p)
- rowLength = rowLength + 1
- end
- end
- if facingAFence() then
- reachedEndOfCol = true
- moveBack()
- suckItUp(row)
- rowLength = rowLength - 1
- end
- if not reachedEndOfCol then
- treesPerRow = treesPerRow + 1
- turtle.turnRight()
- local found = false
- if turtle.detect() then
- -- Check to see if it is the wood we are harvesting
- if isWood() then
- updateStatus("Harvesting at "..row..","..treesPerRow)
- if refuel() then harvestTrunk() else abortCircuit = true end
- elseif facingAChest() then
- abortCircuit = true
- elseif facingAFence() then
- abortCircuit = true
- elseif turtle.detect() then
- updateStatus("Sapling at "..row..","..treesPerRow)
- found = true
- applyBonemeal()
- if isWood() then
- updateStatus("Harvesting at "..row..","..treesPerRow)
- if refuel() then harvestTrunk() else abortCircuit = true end
- end
- end
- end
- if not abortCircuit then
- if not isWood() and not isSapling() then
- if plantSapling() then
- updateStatus("Sapling planted at "..row..","..treesPerRow)
- end
- end
- end
- turtle.turnLeft()
- end
- end
- if abortCircuit then
- updateStatus("Aborting circuit.")
- turtle.turnLeft()
- turtle.turnLeft()
- locateStartingPosition()
- turtle.turnLeft()
- turtle.turnLeft()
- break
- else
- updateStatus("Reached end of row "..row)
- moveForward()
- suckItUp(row)
- rowLength = rowLength + 1
- turtle.turnRight()
- turtle.turnRight()
- -- returing to bottom of grove.
- for p=1,rowLength do
- suckItUp(p)
- moveForward()
- end
- turtle.turnLeft()
- moveForward()
- moveForward()
- turtle.turnLeft()
- end
- row = row + 1
- end
- end
- if not abortCircuit then
- numberOfRows = row
- -- Should be back to the begging of the grove at the last column of trees.
- turtle.turnLeft()
- -- Return to start
- updateStatus("Returning to start.")
- local sr = (spaceBetweenTrees * (numberOfRows-1))+2 - leftShift
- for p=1,sr do
- turtle.suck()
- if facingAChest() or facingAFence() then
- updateStatus("Lost. Returning to start.")
- locateStartingPosition()
- abortCircuit = true
- turtle.turnLeft()
- turtle.turnLeft()
- else
- moveForward()
- end
- end
- -- Should be back in the start position.
- if not abortCircuit then
- turtle.turnLeft()
- turtle.forward()
- end
- end
- abortCircuit = false
- if not facingAChest() or not aboveAChest() then
- locateStartingPosition()
- turtle.turnLeft()
- turtle.turnLeft()
- end
- -- Now facing inventory chest.
- updateStatus("Storing wood.")
- for slot=slotWood+1,16 do
- turtle.select(slot)
- local dropped = true
- if turtle.compareTo(slotSapling) then
- -- Leave for now
- elseif turtle.getItemCount(slot) > 1 then
- if not turtle.drop() then dropped = false end
- end
- if dropped and turtle.getItemCount(slotWood) > 1 then
- turtle.select(slotWood)
- if not turtle.drop(turtle.getItemCount(slotWood)-1) then dropped = false end
- end
- if not dropped and (furnaceCount == nil or furnaceCount > 0) then
- -- Inventory must be full. Make sure that the furnaces are busy.
- updateStatus("Servicing furnaces...")
- turtle.turnRight()
- turtle.turnRight()
- refuel()
- serviceFurnaces()
- turtle.turnRight()
- turtle.turnRight()
- break
- end
- end
- turtle.turnRight()
- -- Now facing chest with saplings. Unload extra saplings
- updateStatus("Storing saplings.")
- for slot=1,16 do
- turtle.select(slot)
- -- Check to see if it is a sapling
- if slot ~= slotSapling and turtle.compareTo(slotSapling) then
- if not turtle.drop() then
- updateStatus("Sapling chest full.")
- turtle.up()
- turtle.drop()
- turtle.down()
- end
- end
- end
- turtle.turnRight()
- -- Back in start position.
- updateStatus("Pausing before next circuit...")
- sleep(30)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement