Sayomie550

Untitled

Aug 21st, 2012
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.24 KB | None | 0 0
  1. --[[
  2. Forestry Turtle 1.0
  3. By Sayomie555
  4. --]]
  5. local tree = 0
  6. local wood = 0
  7.  
  8. function data()
  9.     term.clear()
  10.     term.setCursorPos(1,1)
  11.     print("Number Of Trees Choped: "..tree)
  12.     print("Ammount Of Wood Harvested: "..wood)
  13.     print("------------------------------------")
  14. end
  15.  
  16. function treelocated() -- Function to print that a tree has been found
  17.     tree = tree + 1 -- Adds one to the tree counter
  18.     data()
  19.     print("Tree Detected Starting Logging")
  20.     sleep(0.2)
  21. end
  22.  
  23. function choplant() -- function to chop down a tree and then replant it
  24.     data()
  25.     print("Logging")
  26.     turtle.dig() -- Chops the base of the tree
  27.     turtle.forward() -- Moves the turtle under the tree
  28.     wood = wood + 1
  29.  
  30.     while turtle.detectUp() do -- Mines upward so long as there is a block above the turtle
  31.         turtle.digUp()
  32.         turtle.up()
  33.         data()
  34.         print("Logging")
  35.         wood = wood + 1
  36.     end
  37.     wood = wood - 1
  38.    
  39.     data()
  40.     print("Returning to Ground")
  41.     while not turtle.detectUp() and not turtle.detectDown() do -- Moves the turtle back down until there is a block below the turtle
  42.         turtle.down()
  43.     end
  44.    
  45.     data()
  46.     print("Backing Up")
  47.     sleep(0.2)
  48.     turtle.back() -- Moves the turtle back
  49.    
  50.    
  51.     data()
  52.     print("Replanting Sapling")
  53.     sleep(0.2)
  54.     turtle.select(1) -- The turtle selects the first slot in its inventory (The sapling)
  55.     turtle.place(1) -- Places the item from the first slot in its inventory
  56.    
  57.     data()
  58.     print("Patroling For Trees")
  59. end
  60.  
  61. function treeleft() -- Function to detect if there is a tree to the left of the turtle
  62.     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)
  63.         treelocated() -- Runs the treelocated function
  64.         turtle.turnLeft() -- Turns the turtle left to face the tree
  65.         choplant() -- Runs the Choplant Function
  66.         turtle.turnRight() -- Turns the turtle to the right
  67.     end
  68. end
  69.  
  70. function treeright() -- Same as treeleft but check for trees on the right
  71.     if redstone.getInput("right",true) then
  72.         treelocated()
  73.         turtle.turnRight()
  74.         choplant()
  75.         turtle.turnLeft()
  76.     end
  77. end
  78.  
  79. function treefront() -- Same as tree left but checks for trees infront
  80.     if redstone.getInput("front",true) then
  81.         treelocated()
  82.         choplant()
  83.     end
  84. end
  85.  
  86. function stock()
  87.     if not turtle.detectDown() then
  88.         local slot = 2
  89.    
  90.         redstone.setOutput("left",true)
  91.         sleep(0.2)
  92.         redstone.setOutput("left",false)
  93.         sleep(0.2)
  94.        
  95.         while slot ~= 10 do
  96.             while turtle.getItemSpace(slot) ~= 64 do
  97.                 redstone.setOutput("back",true)
  98.                 sleep(0.2)
  99.                 redstone.setOutput("back",false)
  100.                 sleep(0.2)
  101.             end
  102.            
  103.             slot = slot + 1
  104.         end
  105.     end
  106. end
  107.  
  108. while true do -- Creates a loop to keep the turtle running (Will be replaced later to allow for a on off switch)
  109.  
  110.     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
  111.         turtle.forward()
  112.     end
  113.    
  114.     treeleft() -- Runs the treeleft function
  115.     treeright() -- Runs the treeright function
  116.     treefront() -- Runs the treefront function
  117.    
  118.     if turtle.detect() then -- Checks to see if there is a block infront of the turtle and if there is turns the turtle left
  119.         turtle.turnRight()
  120.     end
  121.    
  122.     treeleft()
  123.     treeright()
  124.     treefront()
  125.     stock()
  126. end
Advertisement
Add Comment
Please, Sign In to add comment