Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- treeFarm v2.1 by bigougit
- youtube.com/user/bigougit
- http://twitter.com/bigougit
- This program is for mining
- or felling turtles only.
- To install in-game, make sure
- that http = true in your
- computercraft config.
- To install, open your turtle
- and type:
- pastebin get w8GkTmYh treeFarm
- The turtle needs 2 sapplings
- and 1 log to start. This
- program only handles 1x1
- trees, so no redwoods or
- large oak trees.
- Place sapplings in slot 1
- and logs in slot 2. The
- turtle will use logs for
- fuel as needed.
- --]]
- local continue = true
- local treeCount = 0
- local moved = 0
- local fakeTrees = 0
- turtle.select(1)
- term.clear()
- term.setCursorPos(1,1)
- --return how many items in [slot]
- local function sCount(slot)
- return turtle.getItemCount(slot)
- end
- local function tryUp()
- while not turtle.up() do
- turtle.attackUp()
- turtle.digUp()
- end
- end
- local function tryDown()
- while not turtle.down() do
- turtle.attackDown()
- turtle.digDown()
- end
- end
- function stack(slot)
- local room = turtle.getItemSpace(slot)
- local s = 0
- while room > 0 do
- s = s + 1
- if s >= 16 then
- room = 0
- end
- if s ~= slot then
- turtle.select(s)
- if turtle.compareTo(slot) then
- if sCount(s) >= room then
- turtle.transferTo(slot, room)
- room = 0
- else
- local temp = sCount(s)
- turtle.transferTo(slot,temp)
- room = room - temp
- end
- end
- end
- end
- turtle.select(slot)
- end
- local function dispStats(message)
- term.clear()
- term.setCursorPos(1,1)
- print("Bigougit's tree farming program.")
- print("Trees farmed: "..treeCount)
- print("Fakes trees: "..fakeTrees)
- if message ~= nil then
- print(message)
- end
- end
- function fuel(slot, need)
- local iCount = sCount(slot)
- --stack(slot)
- local cont = true
- while cont do
- if turtle.getFuelLevel() < need then
- if iCount > 1 then
- turtle.select(slot)
- turtle.refuel(1)
- if iCount == sCount(slot) then
- cont = false
- else
- iCount = sCount(slot)
- end
- else
- cont = false
- end
- else
- return true
- end
- end
- if turtle.getFuelLevel() < need then
- return false
- else
- return true
- end
- end
- -- start of main program
- dispStats(nil)
- stack(1)
- while ( sCount(1) <= 1 ) do
- dispStats("Need at least 2 sapplings in first slot to start.")
- sleep(2)
- term.clear()
- term.setCursorPos(1,1)
- end
- dispStats(nil)
- if not turtle.detect() then
- turtle.select(1)
- turtle.place()
- end
- while continue do
- turtle.select(2)
- if turtle.compare() then
- if fuel(2, 18) then
- dispStats("Chopping Tree...")
- turtle.select(2)
- while turtle.compare() do
- turtle.dig()
- tryUp()
- moved = moved + 1
- end
- for i=1,moved do
- tryDown()
- end
- end
- -- stack(1)
- -- stack(2)
- turtle.select(1)
- if sCount(1) > 1 then
- turtle.place()
- end
- if moved > 0 then
- treeCount = treeCount + 1
- stack(1)
- stack(2)
- turtle.select(1)
- else
- --turtle.dig()
- fakeTrees = fakeTrees + 1
- end
- moved = 0
- end
- turtle.select(2)
- while not turtle.compare() do
- dispStats("Waiting for tree to grow.")
- redstone.setOutput("bottom",true)
- sleep(0.5)
- redstone.setOutput("bottom",false)
- sleep(5)
- end
- while sCount(1) <= 1 do
- dispStats("Need at least 2 sapplings in first slot to start.")
- sleep(2)
- term.clear()
- term.setCursorPos(1,1)
- end
- dispStats(nil)
- if not turtle.detect() then
- turtle.select(1)
- turtle.place()
- end
- sleep(.5)
- end
Advertisement
Add Comment
Please, Sign In to add comment