Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- Forestry Turtle 1.0
- By Sayomie555
- --]]
- local tree = 0
- local wood = 0
- function data()
- local sapling = turtle.getItemCount(1)
- local lumber = turtle.getItemCount(2) + turtle.getItemCount(3) + turtle.getItemCount(4) + turtle.getItemCount(5) + turtle.getItemCount(6) + turtle.getItemCount(7) + turtle.getItemCount(8) + turtle.getItemCount(9)
- term.clear()
- term.setCursorPos(1,1)
- print("Number Of Trees Choped: "..tree)
- print("Ammount Of Wood Harvested: "..wood)
- print("Number Of saplings In Stock: "..sapling)
- print("Ammount of Lumber In Stock: "..lumber)
- print("------------------------------------")
- end
- function treelocated() -- Function to print that a tree has been found
- tree = tree + 1 -- Adds one to the tree counter
- data()
- print("Tree Detected Starting Logging")
- sleep(0.2)
- end
- function choplant() -- function to chop down a tree and then replant it
- data()
- print("Logging")
- turtle.dig() -- Chops the base of the tree
- turtle.forward() -- Moves the turtle under the tree
- wood = wood + 1
- while turtle.detectUp() do -- Mines upward so long as there is a block above the turtle
- turtle.digUp()
- turtle.up()
- data()
- print("Logging")
- wood = wood + 1
- end
- wood = wood - 1
- data()
- print("Returning to Ground")
- while not turtle.detectUp() and not turtle.detectDown() do -- Moves the turtle back down until there is a block below the turtle
- turtle.down()
- end
- data()
- print("Backing Up")
- sleep(0.2)
- turtle.back() -- Moves the turtle back
- data()
- print("Replanting Sapling")
- sleep(0.2)
- turtle.select(1) -- The turtle selects the first slot in its inventory (The sapling)
- turtle.place(1) -- Places the item from the first slot in its inventory
- data()
- print("Patroling For Trees")
- end
- function treeleft() -- Function to detect if there is a tree to the left of the turtle
- if redstone.getInput("left",true) then -- Checks to see if there is a positive redstone input to the left of the turtle (This is to check if there is a tree vs a sapling)
- treelocated() -- Runs the treelocated function
- turtle.turnLeft() -- Turns the turtle left to face the tree
- choplant() -- Runs the Choplant Function
- turtle.turnRight() -- Turns the turtle to the right
- end
- end
- function treeright() -- Same as treeleft but check for trees on the right
- if redstone.getInput("right",true) then
- treelocated()
- turtle.turnRight()
- choplant()
- turtle.turnLeft()
- end
- end
- function treefront() -- Same as tree left but checks for trees infront
- if redstone.getInput("front",true) then
- treelocated()
- choplant()
- end
- end
- function stock()
- if not turtle.detectDown() then
- local slot = 2
- while turtle.getItemSpace(1) ~= 0 do
- data()
- print("Stocking Up On Saplings")
- redstone.setOutput("left",true)
- sleep(0.2)
- redstone.setOutput("left",false)
- sleep(0.2)
- end
- while slot ~= 10 do
- data()
- print("Dropping off Lumber")
- while turtle.getItemSpace(slot) ~= 64 do
- redstone.setOutput("back",true)
- sleep(0.2)
- redstone.setOutput("back",false)
- sleep(0.2)
- end
- slot = slot + 1
- end
- end
- end
- while true do -- Creates a loop to keep the turtle running (Will be replaced later to allow for a on off switch)
- if not turtle.detect() then -- Checks to see if there is a block infront of the turtle and moves the turtle forward if there is not
- turtle.forward()
- end
- treeleft() -- Runs the treeleft function
- treeright() -- Runs the treeright function
- treefront() -- Runs the treefront function
- if turtle.detect() then -- Checks to see if there is a block infront of the turtle and if there is turns the turtle left
- turtle.turnRight()
- end
- treeleft()
- treeright()
- treefront()
- stock()
- end
Advertisement
Add Comment
Please, Sign In to add comment