Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[Welcome to Jirons Tree Farming Turtle; in example the width = 5 and length = 6 ]]
- --[[
- x x x x x
- x x x x x
- x x x x x
- T R
- ]]
- -- --[[ T = Turtle, deposit chest placed under turtle,
- -- R = refuel chest ]]--
- -- Use Odd numbers for Width (just cus me life is a mirror)
- -- https://i.imgur.com/q2pOFTh.png (Basic setup)
- -- I use mainly oak for the farm.
- -- Place turtle on the chest facing away from the farm.
- -- feel free to make the farm 41 x 50 (free form)
- print("+-------------------------------------+")
- print("| TimberFarmer 1.0, by Jiron |")
- print("+-------------------------------------+")
- print("| Farm set-up: Place down 3 chests |")
- print("| place the felling turtle on the |")
- print("| chest to the right and facing away |")
- print("| from the farm. Put saplings in the |")
- print("| middle and fuel in the left chest. |")
- print("| |")
- print("| Put some fuel in the turtle and |")
- print("| lets define the size of the farm. |")
- print("+-------------------------------------+")
- print("Press enter to continue..")
- getready = io.read()
- print("+-------------------------------------+")
- print("+----------------Setup----------------+")
- print("| H = height, C = chest, T = turtle |")
- print("| |")
- print("| H = 1 T |")
- print("| H = 0 C C C |")
- print("| L M R |")
- print("| |")
- print("| Remember Turtle should be facing |")
- print("| away from intended farm area. |")
- print("+-------------------------------------+")
- print("Press enter to continue..")
- print("https://i.imgur.com/q2pOFTh.png")
- print("Shows the basic setup")
- getsett = io.read()
- print("Width of the farm in ODD numbers only!")
- re = io.read()
- width = tonumber(re)
- print("Length of farm?")
- rel = io.read()
- length = tonumber(rel)
- print("Farm size set to " .. width .. "x" .. length)
- print("Cycle time? in minutes")
- redir = io.read()
- --Farm
- waitTime = tonumber(redir * 60)
- tRight = false
- tLeft = true
- start = true
- spinLeft = true
- treeHeight = 0
- count = 0
- function noFaithInUser(number)
- if (number % 2 == 0) then
- print("Error: Width is not odd in size!")
- return true
- end
- start = false
- return flase
- end
- function turnLeft()
- -- print("left")
- turtle.turnLeft()
- block()
- turtleMove()
- turtleMove()
- turtle.turnLeft()
- tLeft = true
- tRight = false
- block()
- end
- function turnRight()
- --print("Right")
- turtle.turnRight()
- block()
- turtleMove()
- turtleMove()
- turtle.turnRight()
- tRight = true
- tLeft = false
- block()
- end
- function block()
- if turtle.detect() == true then
- turtle.dig()
- turtle.suck()
- turtle.suckDown()
- end
- end
- function detectSapling(s)
- res = string.find(s .. "", "sapling")
- if res ~= nil then
- return "yes";
- else
- return "no"
- end
- end
- function detectType(s, type)
- res = string.find(s .. "", type)
- if res ~= nil then
- return "yes";
- else
- return "no"
- end
- end
- function isSapling()
- local suc, det = turtle.detect()
- if suc then
- local suc2, insp = turtle.inspect()
- if suc2 then
- local name = insp.name
- return detectSapling(name)
- end
- else
- return "nothing"
- end
- end
- function evenOrOdd(number)
- if number % 2 == 0 then
- return true
- else
- return false
- end
- end
- function turtleMove()
- turtle.dig()
- turtle.suck()
- local m = turtle.forward()
- while m == false do
- turtle.dig()
- m = turtle.forward()
- end
- end
- function move(length, first)-- MOVE
- if length >= 0 then
- turtleMove()
- if first then
- turtleMove()
- turtleMove()
- turtleMove()
- length = length - 2
- end
- if length > 1 then
- turtle.turnLeft()
- spinLeft = true
- -- print("check L")
- if isSapling() == "no" then
- harvest()
- else
- planting()
- turtle.turnRight()
- end
- turtle.turnRight()
- spinLeft = false
- -- print("check R")
- if isSapling() == "no" then
- harvest()
- else
- planting()
- turtle.turnLeft()
- end
- end
- length = length - 1
- --print("move")
- move(length, false)
- end
- end
- function climDown(heightClimed, org)
- -- print("H: " .. heightClimed)
- if heightClimed > 0 then
- local isGrass = false
- local isLeaves = false
- local isDirt = false
- local isLog = false
- local suc, det = turtle.detectDown()
- if suc then
- local suc2, insp = turtle.inspectDown()
- if suc2 then
- isLeaves = detectType(insp.name, "leaves")
- isLog = detectType(insp.name, "log")
- end
- end
- if isLeaves == "yes" or isLog == "yes" then
- -- print("climDown: " .. treeHeight)
- turtle.digDown()
- turtle.suck()
- turtle.suckDown()
- end
- turtle.down()
- heightClimed = heightClimed - 1
- treeHeight = treeHeight - 1
- climDown(heightClimed)
- end
- end
- function climDownAgain(height, original)
- turtle.turnRight()
- turtle.turnRight()
- if turtle.detect() then
- turtle.dig()
- turtle.suck()
- turtleMove()
- end
- if treeHeight > 0 then
- climDown(height, org)
- end
- end
- function checkForTimber()
- local isLeaves = false
- local isLog = false
- local suc, det = turtle.detectUp()
- if suc then
- local suc2, insp = turtle.inspectUp()
- if suc2 then
- isLeaves = detectType(insp.name, "leaves")
- isLog = detectType(insp.name, "log")
- end
- end
- if isLeaves == "yes" or isLog == "yes" then
- -- print("climDown: " .. treeHeight)
- return true
- else
- return false
- end
- end
- function climUP()
- if checkForTimber() == true then
- turtle.digUp()
- turtle.suck()
- turtle.suckUp()
- turtle.up()
- spinHarvest(4, treeHeight)
- treeHeight = treeHeight + 1
- climUP()
- else
- climDownAgain(treeHeight, treeHeight)
- if treeHeight == 0 then
- turtleMove()
- if spinLeft == true then
- turtle.turnLeft()
- else
- turtle.turnRight()
- end
- end
- end
- end
- function standardCut(spin)
- if spin > 0 then
- turtle.turnLeft()
- if isSapling() == "no" then
- turtle.dig()
- end
- turtle.suck()
- spin = spin - 1
- standardCut(spin)
- else
- return spin
- end
- end
- function chop()
- turtle.dig()
- turtle.suck()
- end
- function chopSides()
- turtle.turnRight()
- chop()
- turtle.turnLeft()
- chop()
- turtle.turnLeft()
- chop()
- end
- function chopLeftTurn()
- turtle.turnLeft()
- chopMove()
- end
- function chopMove()
- turtleMove()
- end
- function chopRight()
- turtle.turnRight()
- chop()
- turtle.turnLeft()
- end
- function chopCorner()
- chopMove()
- chop()
- chopLeftTurn()
- chopSides()
- end
- function chopUntilCorner()
- chopMove()
- chopRight()
- end
- function extendedCut()
- chopCorner()
- chopUntilCorner()
- chopUntilCorner()
- chopLeftTurn()
- chopCorner()
- chopMove()
- turtle.turnRight()
- return 0
- end
- function spinHarvest(spinAround, h)
- if h < 3 and spinAround > 0 then
- spinAround = standardCut(spinAround)
- else if h > 0 and spinAround > 0 then
- spinAround = extendedCut()
- end
- end
- end
- function checkSlotForSapling()
- local suc, space = turtle.getItemSpace()
- if suc then
- local data = turtle.getItemDetail()
- if data then
- -- print(data.name)
- local name = data.name
- return detectSapling(name)
- end
- else return "no"
- end
- end
- function planting()
- if checkSlotForSapling() == "yes" then
- turtle.place()
- else
- for i = 1, 16 do -- loop through the slots
- turtle.select(i)-- change to the slot
- if checkSlotForSapling() == "yes" then -- if it's valid
- turtle.place()
- end
- end
- end
- end
- function harvest()
- turtle.dig()
- turtle.suck()
- turtle.suckDown()
- turtleMove()
- spinHarvest(4, 0)
- climUP()
- end
- function refuel(f)
- for i = f, 16 do -- loop through the slots
- turtle.select(i)-- change to the slot
- if turtle.refuel(0) then -- if it's valid fuel
- turtle.refuel()-- consume half the stack as fuel
- end
- end
- end
- function refuelTurtle()
- turtleMove()
- turtle.turnLeft()
- turtle.turnLeft()
- local fuelLevel = 0
- local suc, fuelLevel = turtle.getFuelLevel
- if turtle.getFuelLevel() ~= "unlimited" and turtle.getFuelLevel() > 10000 then
- turtle.suckDown()
- else
- for i = 2, 16 do -- loop through the slots
- turtle.select(i)-- change to the slot
- turtle.suckDown()
- end
- end
- refuel(2)
- storeUnusedFuel()
- turtleMove()
- turtleMove()
- turtle.turnLeft()
- end
- function storeUnusedFuel()
- for i = 2, 16 do -- loop through the slots
- turtle.select(i)-- change to the slot
- turtle.dropDown()
- end
- end
- function storeTimber()
- for i = 1, 16 do -- loop through the slots
- turtle.select(i)-- change to the slot
- if checkSlotForSapling() == "no" then
- turtle.dropDown()
- end
- end
- end
- function storeSapling()
- turtle.turnRight()
- turtleMove()
- for i = 1, 16 do -- loop through the slots
- turtle.select(i)-- change to the slot
- if checkSlotForSapling() == "yes" then
- turtle.dropDown()
- end
- end
- -- resupply
- turtle.select(1)
- turtle.suckDown()
- end
- function turtleRun()
- for newWidth = width, 1, -2 do
- if newWidth == width then
- move(length - 2, true)
- else if newWidth < width and newWidth > 1 then
- move(length - 2, false)
- else
- move(length - 1, false)-- set to -1 for mirror setup
- end
- end
- if newWidth > 1 then
- if tRight == false then
- turnRight()
- else
- turnLeft()
- end
- end
- if newWidth == 1 then
- return newWidth
- end
- end
- end
- function run()
- local state = turtleRun()
- if state == 1 then
- returnToStart()
- end
- end
- function returnToStart()
- turtle.turnLeft()
- turtle.turnLeft()
- turtleRun()
- end
- while true do
- if start == true then
- if noFaithInUser(width) == true then
- break
- end
- refuel(1)
- storeSapling()
- refuelTurtle()
- end
- count = count + 1
- print("Done " .. count .. " rounds ")
- run()
- storeTimber()
- storeSapling()
- refuelTurtle()
- sleep(waitTime)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement