Advertisement
Ineentho

Ineentho's Cutter v2

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