Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- TreeFarmerSingle
- by Severino
- Version 1.5
- Harvests a single tree and transfers wood to a chest, getting saplings and fuel from other chests.
- Create a square of fences with 10 on each side. Leave the center fence out on one side. Put a source water block in each corner.
- + - - - - - - - - - +
- | W W |
- | |
- | |
- | |
- | S |
- | |
- | |
- | |
- | W W |
- + - - - - - - - - +
- HH T BB
- C P
- S = Sapling. Plant the first sapling.
- W = Source Water Block
- HH = Stack of double chests for harvested wood starting at ground level.
- BB = Double chest for bone meal at ground level.
- P = Single chest to store planks used for fuel at ground level
- T = Single chest below ground level to store saplings. Felling or Mining turtle is placed above this chest.
- C = Crafting turtle at ground level
- Load Crafting turtle with PlankCrafter program and setup "startup" program to run this program. Leave turtle slots empty. Run the startup program.
- Load Felling Turtle with TreeFarmerSingle program and setup "startup" program to run this program.
- Prepare the Felling Turtle by placing the following items in it's slots.
- Slot 1 - Stack of planks to use for fuel
- Slot 2 - 2 Saplings
- Slot 3 = Stack of Bone meal for fertilizer
- Slot 4 = 1 Fence
- Slot 5 = 1 Chest
- Slot 6 = 1 wood block
- The saplings, wood block and planks for fuel must all be the same type of tree.
- Run the startup program. The first time the program runs it will ask for the computer ID of the computer that the MinerMonitor program is running on. Enter 0 if you don't have one.
- Use the MinerMonitor computer to monitor the status of the turtles running the TreeFarmerSingle, TreeFarmer and Miner8 programs.
- If you later want to start using a MinerMonitor program, delete the file ConsoleID from the turtle and restart the program. It will ask for the computer ID again.
- ]]--
- version = "1.5 - NO FUEL"
- slotFuel = 1
- slotSapling = 2
- slotFertilizer = 3
- slotFence = 4
- slotChest = 5
- slotWood = 6
- minerID = os.getComputerID()
- consoleID = 0
- harvestWide = false
- turtleName = nil
- function updateStatus(msg, silent)
- if not rednet.isOpen("right") then rednet.open("right") end
- if rednet.isOpen("right") then
- if turtleName == nil then return end
- networkmsg = "MM:"..turtleName..": "..msg
- if consoleID == 0 then
- rednet.broadcast(networkmsg)
- else
- rednet.send(consoleID,networkmsg)
- end
- end
- if not silent then print(msg) end
- end
- function getTurtleName()
- local fname = "TurtleName"
- if fs.exists(fname) then
- file = fs.open(fname, "r")
- turtleName = file.readAll()
- file.close()
- else
- term.write("Turtle Name: ")
- turtleName = io.read()
- file = fs.open(fname, "w")
- file.write(turtleName)
- file.close()
- end
- end
- function loadFuel()
- turtle.turnRight()
- turtle.turnRight()
- turtle.select(slotFuel)
- if turtle.suck() then
- for d=1,16 do
- if d ~= slotFuel then
- turtle.select(d)
- if turtle.compareTo(slotFuel) then turtle.drop() end
- end
- end
- else
- updateStatus("No Fuel Required.")
- end
- turtle.turnRight()
- turtle.turnRight()
- end
- function loadSaplings()
- if turtle.getItemCount(slotSapling) < 2 then
- turtle.select(slotSapling)
- if turtle.suckDown(2) then
- for d=1,16 do
- if d ~= slotSapling then
- turtle.select(d)
- if turtle.compareTo(slotSapling) then turtle.dropDown() end
- end
- end
- return true
- else
- updateStatus("Sapling chest is empty.")
- return false
- end
- end
- end
- function loadFertilizer()
- turtle.turnRight()
- turtle.select(slotFertilizer)
- if turtle.suck() then
- for d=1,16 do
- if d ~= slotFertilizer then
- turtle.select(d)
- if turtle.compareTo(slotFertilizer) then turtle.drop() end
- end
- end
- else
- updateStatus("Fertilizer chest is empty.")
- end
- turtle.turnLeft()
- end
- function unloadWood()
- turtle.turnLeft()
- for d = 1,16 do
- turtle.select(d)
- if d ~= slotFuel and d ~= slotSapling and d ~= slotFertilizer and d ~= slotFence and d ~= slotChest and d ~= slotWood then
- if turtle.getItemCount(d) > 0 then
- if not turtle.drop() then
- updateStatus("Wood chest is full.")
- break
- end
- end
- end
- end
- if turtle.getItemCount(slotWood) > 1 then
- turtle.select(slotWood)
- turtle.drop(turtle.getItemCount(slotWood)-1)
- end
- --
- turtle.turnRight()
- end
- function unloadSaplings()
- for d=1,16 do
- if d ~= slotSapling then
- turtle.select(d)
- if turtle.compareTo(slotSapling) then turtle.dropDown() end
- end
- end
- if turtle.getItemCount(slotSapling)>2 then
- turtle.select(slotSapling)
- turtle.dropDown(turtle.getItemCount(slotSapling)-2)
- end
- 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 locateStartingPosition()
- turtle.select(slotChest)
- if not turtle.compareDown() then
- -- Not above a chest.
- while turtle.back() do
- if turtle.compareDown() then break end
- end
- if not turtle.compareDown() then
- while true do
- updateStatus("Can't find starting position. Need help.")
- sleep(60)
- end
- end
- end
- for d=1,4 do
- if not turtle.detect() then break end
- turtle.turnLeft()
- end
- if turtle.detect() then
- while true do
- updateStatus("Can't find starting position. Need help.")
- sleep(60)
- end
- end
- end
- function checkSetup()
- while turtle.getItemCount(slotFuel) < 2 do
- updateStatus("Fuel needed in slot "..slotFuel)
- sleep(20)
- end
- while turtle.getItemCount(slotSapling) < 2 do
- if not loadSaplings() then
- updateStatus("Saplings needed in slot "..slotSapling)
- sleep(20)
- end
- end
- if turtle.getItemCount(slotFertilizer) < 1 then
- updateStatus("Fertilizer needed in slot "..slotFertilizer)
- end
- while turtle.getItemCount(slotFence) < 1 do
- updateStatus("Fence needed in slot "..slotFence)
- sleep(20)
- end
- while turtle.getItemCount(slotChest) < 1 do
- updateStatus("Chest needed in slot "..slotChest)
- sleep(20)
- end
- while turtle.getItemCount(slotWood) < 1 do
- updateStatus("Wood needed in slot "..slotWood)
- sleep(20)
- 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()
- 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()
- updateStatus("Chopping Tree Down")
- if turtle.up() then h = h + 1 else break end
- end
- end
- local d = 1
- while d <= h do
- if turtle.detectDown() then
- turtle.digDown()
- end
- if turtle.down() then
- d = d + 1
- end
- end
- turtle.back()
- end
- 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 selectFertilizer()
- -- 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 ~= slotFertilizer then
- if turtle.getItemCount(slot) > 1 then
- turtle.select(slot)
- if turtle.compareTo(slotFertilizer) then return true end
- end
- end
- end
- if turtle.getItemCount(slotFertilizer) > 1 then
- turtle.select(slotFertilizer)
- return true
- end
- return false
- 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 applyFertilizer()
- updateStatus("Applying Fertilizer.")
- -- Apply fertilizer and report if there is a problem.
- if turtle.detect() then
- if selectFertilizer() then
- local cnt = 0
- local applied = false
- while not isWood() and cnt < 10 do
- if selectFertilizer() 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
- else
- updateStatus("Nothing to fertilizer.")
- return false
- end
- end
- -- Main program
- updateStatus("Starting")
- term.clear()
- term.setCursorPos(1,1)
- print("Sev's Tree Farmer Single "..version)
- print("Turtle ID: "..minerID)
- getTurtleName()
- getConsoleID()
- checkSetup()
- locateStartingPosition()
- -- Now start planting and harvensting trees.
- while true do
- -- Check for enouhg fuel.
- if turtle.getItemCount(slotFuel) < 64 then loadFuel() end
- if turtle.getItemCount(slotSapling) < 2 then loadSaplings() end
- if turtle.getItemCount(slotFertilizer) < 30 then loadFertilizer() end
- for l=1,5 do
- while not turtle.forward() do
- updateStatus("Blocked.")
- sleep(20)
- end
- end
- turtle.select(slotSapling)
- turtle.suck()
- turtle.select(slotWood)
- if not turtle.compare() then applyFertilizer() end
- turtle.select(slotWood)
- if turtle.compare() then harvestTrunk() end
- if not turtle.detect() then
- if selectSapling() then
- turtle.suck()
- turtle.place()
- end
- end
- for l=1,5 do
- while not turtle.back() do
- updateStatus("Blocked.")
- sleep(20)
- end
- end
- unloadWood()
- unloadSaplings()
- updateStatus("Waiting for Sapling to Grow.")
- sleep(140)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement