itsmartin

Treefarm

Dec 27th, 2012
781
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.53 KB | None | 0 0
  1. -- Treefarm by itsmartin
  2. --
  3. -- Place fuel in slot 14, saplings in slot 15 and 1 dirt in slot 16.
  4. -- See http://youtu.be/nJYxL_sg96U for setup
  5.  
  6. function forwardBy(n)
  7.     for i=1,n do
  8.         turtle.forward()
  9.     end
  10. end
  11.  
  12. function moveHomeFarm()
  13.     forwardBy(5)
  14.     turtle.turnLeft()
  15.     forwardBy(5)
  16.     turtle.turnLeft()
  17. end
  18.  
  19.  
  20. function plantSapling()
  21.     turtle.select(16)
  22.     turtle.place()
  23.     turtle.up()
  24.     turtle.select(15)
  25.     turtle.place()
  26. end
  27.  
  28. function waitForSaplings()
  29.     turtle.select(15)
  30.     while turtle.getItemCount(15) < 2 do
  31.         os.sleep(5)
  32.         turtle.suckDown()
  33.     end
  34. end
  35.  
  36. function waitForTree()
  37.     turtle.select(15)
  38.     while turtle.compare() do
  39.         os.sleep(10)
  40.     end
  41.     turtle.select(16)
  42.     turtle.down()
  43.     turtle.dig()
  44.     turtle.forward()
  45. end
  46.  
  47. function cutTree()
  48.     turtle.select(1)
  49.     turtle.digUp()
  50.     turtle.up()
  51.     local count = 1
  52.     while turtle.compareUp() do
  53.         turtle.digUp()
  54.         turtle.up()
  55.         count = count + 1
  56.     end
  57.     for i=1,count do
  58.         turtle.down()
  59.     end
  60. end
  61.  
  62. function moveFarmDeposit()
  63.     turtle.turnRight()
  64.     forwardBy(4)
  65.     turtle.turnLeft()
  66.     forwardBy(4)
  67.     turtle.select(1)
  68.     turtle.dropDown()
  69.     turtle.turnLeft()
  70.     forwardBy(9)
  71.     turtle.turnLeft()
  72. end
  73.  
  74. while true do
  75.  
  76.     if turtle.getFuelLevel() < 50 then
  77.         turtle.select(14)
  78.         turtle.refuel()
  79.         if turtle.getFuelLevel() < 50 then
  80.             write("Not enough fuel\n")
  81.             return
  82.         end
  83.     end
  84.  
  85.     if turtle.getItemCount(16) < 1 then
  86.         write("Dirt goes in slot 16\n")
  87.         return
  88.     end
  89.  
  90.     waitForSaplings()
  91.     moveHomeFarm()
  92.     plantSapling()
  93.     waitForTree()
  94.     cutTree()
  95.     moveFarmDeposit()
  96. end
Advertisement
Add Comment
Please, Sign In to add comment