Advertisement
dadragon84

Tree Logger

Sep 10th, 2014
316
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.45 KB | None | 0 0
  1. local paces = 0
  2. local facing = 0
  3.  
  4. function backTrack()
  5.    while (paces > -1) do
  6.        refuel()
  7.        turtle.back()
  8.        paces = paces - 1
  9.     end
  10. end
  11.  
  12. function goTree()
  13.     while (not turtle.detect()) do
  14.         refuel()
  15.         turtle.forward()
  16.         paces = paces + 1
  17.     end
  18. end
  19.  
  20. local function comeDown()
  21.   while (turtle.detectDown() == false)
  22.   do
  23.     turtle.down()
  24.   end
  25. end
  26.  
  27. function refuel()
  28.   if turtle.getFuelLevel() < 5 then
  29.     turtle.select(16)
  30.     while (turtle.getItemCount(16) == 0)
  31.     do
  32.       print("Waiting for fuel..")
  33.       sleep(2)
  34.     end
  35.     turtle.refuel(1)
  36.     turtle.select(1)
  37.   end
  38. end
  39.  
  40. local function checkTree()
  41.     turtle.dig()
  42.     turtle.forward()
  43.     if (turtle.detect()) then
  44.         log2x2()
  45.     else
  46.         log1x1()
  47.     end
  48. end
  49.  
  50. function log1x1()
  51.     turtle.select(1)
  52.     while (turtle.compareUp()) do
  53.         refuel()
  54.         turtle.digUp()
  55.         turtle.up()
  56.     end
  57. end
  58.  
  59. function log2x2()
  60.     turtle.select(1)
  61.     turtle.dig()
  62.     turtle.forward()
  63.     turtle.turnLeft()
  64.     if (turtle.detect()) then
  65.         for chop = 0, 2, 1 do
  66.             turtle.dig()
  67.             turtle.forward()
  68.             turtle.turnLeft()
  69.         end
  70.        
  71.         while (turtle.compareUp()) do
  72.             for chop = 0, 3, 1 do
  73.                 refuel()
  74.                 turtle.dig()
  75.                 turtle.forward()
  76.                 turtle.turnLeft()
  77.                 facing = facing + 1
  78.                 if (facing == 4) then
  79.                   facing = 0
  80.                 end
  81.             end
  82.             refuel()
  83.             turtle.digUp()
  84.             turtle.up()
  85.         end
  86.     else
  87.         turtle.turnRight()
  88.         turtle.turnRight()
  89.        
  90.         for chop = 0, 2, 1 do
  91.             turtle.dig()
  92.             turtle.forward()
  93.             turtle.turnRight()
  94.         end
  95.        
  96.         while (turtle.compareUp()) do
  97.             for chop = 0, 3, 1 do
  98.                 refuel()
  99.                 turtle.dig()
  100.                 turtle.forward()
  101.                 turtle.turnRight()
  102.                 facing = facing - 1
  103.                 if (facing == -1) then
  104.                   facing = 3
  105.                 end
  106.             end
  107.             refuel()
  108.             turtle.digUp()
  109.             turtle.up()
  110.         end
  111.     end
  112. end
  113.  
  114. --[[Main Function]]--
  115.  
  116. function main()
  117.     refuel()
  118.     goTree()
  119.     checkTree()
  120.     comeDown()
  121.     backTrack()  
  122. end
  123.  
  124. --[[Program entry]]--
  125.  
  126. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement