Sayomie550

Untitled

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