Advertisement
Ineentho

Ineentho's Cutter

May 1st, 2013
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.46 KB | None | 0 0
  1. trees = 3
  2.  
  3. local main
  4.  
  5. function clearInventory()
  6.     slot = 1
  7.     while slot < 16 do
  8.         slot = slot + 1
  9.         turtle.select(slot)
  10.         turtle.drop()
  11.     end
  12. end
  13.  
  14. function plantSaplings()
  15.     turtle.select(1)
  16.     turtle.forward()
  17.     turtle.place()
  18.     turtle.turnRight()
  19.     turtle.forward()
  20.     turtle.turnLeft()
  21.     turtle.place()
  22.     turtle.turnLeft()
  23.     turtle.forward()
  24.     turtle.turnLeft()
  25.     turtle.turnLeft()
  26.     turtle.place()
  27.     turtle.turnRight()
  28.     turtle.forward()
  29.     turtle.turnRight()
  30.     turtle.turnRight()
  31.     turtle.place()
  32. end
  33.  
  34. function dropAndLoot()
  35.     --Saplings should be in the first slot
  36.     --and logs in the rest (but always in the last)
  37.  
  38.     --Drop all logs and take back one stack
  39.     turtle.turnLeft()
  40.     clearInventory()
  41.     turtle.select(16)
  42.     turtle.suck()
  43.        
  44.     --rotate to the other chest
  45.     turtle.turnLeft()
  46.     turtle.turnLeft()
  47.        
  48.     --Loot one stack saplings..
  49.     turtle.select(1)
  50.     turtle.suck()
  51.        
  52.     --and drop the rest..
  53.     turtle.select(2)
  54.     turtle.drop()
  55.        
  56.     --Rotate to its orginal position
  57.     turtle.turnLeft()
  58. end
  59.  
  60. function checkFuel()
  61.     while turtle.getFuelLevel() < 500 do
  62.         turtle.select(16)
  63.         if turtle.refuel(1) then
  64.             if turtle.getFuelLevel() < 500 then
  65.                 print("Fuel level (waiting for 500): " .. turtle.getFuelLevel())
  66.             end
  67.         else
  68.             --Fuel level too low and no logs left.
  69.             dropAndLoot()
  70.         end
  71.     end
  72. end
  73.  
  74. function cutTree()
  75.  
  76.     --Get inside of the tree
  77.     turtle.dig()
  78.     turtle.forward()
  79.    
  80.     treeHeight = 0
  81.    
  82.     --Climb the tree up
  83.     while turtle.dig() do
  84.         turtle.digUp()
  85.         turtle.up()
  86.         treeHeight = treeHeight + 1
  87.     end
  88.    
  89.     --At the top, get to the second half of the tree
  90.     turtle.turnRight()
  91.     turtle.dig()
  92.     turtle.forward()
  93.     turtle.turnLeft()
  94.     turtle.digDown()
  95.     turtle.down()
  96.     turtle.dig()
  97.     --Get down again
  98.    
  99.     level = treeHeight - 1
  100.    
  101.     while level > 0 do
  102.         level = level - 1
  103.         turtle.digDown()
  104.         turtle.down()
  105.         turtle.dig()
  106.     end
  107.    
  108.     --Get back to the starting position
  109.     turtle.turnLeft()
  110.     turtle.forward()
  111.     turtle.turnLeft()
  112.     turtle.forward()
  113.     turtle.turnLeft()
  114.     turtle.turnLeft()
  115.    
  116.     print("Tree cut.")
  117.     print("Replanting saplings")
  118.     plantSaplings()
  119.     print("Planted saplings.")
  120.    
  121. end
  122.  
  123. function goForward(steps)
  124.     for step = 1, steps, 1 do
  125.         turtle.forward()
  126.     end
  127. end
  128.  
  129. function waitForNext()
  130.     for i = 3, 1, -1 do
  131.         print("Waiting " .. i .. " minutes..")
  132.         sleep(60)
  133.     end
  134. end
  135.  
  136. function nextTree()
  137.     tree = tree + 1
  138.     if tree > trees then
  139.         print("Returning to base..")
  140.         turtle.turnRight()
  141.         goForward(4 * (trees - 1) + 3)
  142.         turtle.turnLeft()
  143.         turtle.forward()
  144.         turtle.turnRight()
  145.         turtle.forward()
  146.         turtle.turnLeft()
  147.         turtle.turnLeft()
  148.         turtle.down()
  149.         waitForNext()
  150.     else
  151.         --Go to next tree
  152.         turtle.turnLeft()
  153.         goForward(4)
  154.         turtle.turnRight()
  155.         checkTree()
  156.     end
  157. end
  158.  
  159. function checkTree()
  160.     turtle.select(1)
  161.     if turtle.compare() then
  162.         --It's still a sapling, go to next tree.
  163.         print("Still saplings")
  164.         nextTree()
  165.     else
  166.         print("Tree is fully grown. Cutting.")
  167.         cutTree()
  168.         nextTree()
  169.     end
  170. end
  171.  
  172. function goToFirstTree()
  173.     --Move from the starting position to the cutting position of the first tree.
  174.     turtle.up()
  175.     turtle.forward()
  176.     turtle.forward()
  177.     turtle.turnLeft()
  178.     turtle.forward()
  179.     turtle.turnRight()
  180.     turtle.forward()
  181.     turtle.forward()
  182.     turtle.turnRight()
  183.        
  184.     tree = 1
  185.        
  186.     checkTree()
  187. end
  188.  
  189. function main()
  190.     dropAndLoot()
  191.     checkFuel()
  192.     goToFirstTree()
  193. end
  194.  
  195. while true do
  196.     --Main is run once for each "round"
  197.     main()
  198.     print("Done")
  199. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement