deltreey

treefarm/spruce

Nov 28th, 2016
378
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.85 KB | None | 0 0
  1. os.loadAPI('/fuel')
  2.  
  3. function refreshInventory()
  4.     turtle.down()
  5.     turtle.down()
  6.     local current = 3
  7.     while (current < 16) do
  8.         turtle.select(current)
  9.         turtle.dropDown()
  10.         current = current + 1
  11.     end
  12.     turtle.select(1)
  13.     turtle.suckDown(4)  --Get new sapling
  14.     turtle.up()
  15.     turtle.up()
  16. end
  17.  
  18. function isTree()
  19.     turtle.select(2)
  20.     return turtle.compare()
  21. end
  22.  
  23. function chopTree()
  24.     local dist = 0
  25.     --get in the tree to make sure we do this efficiently
  26.     turtle.dig()
  27.     turtle.forward()
  28.     --clear most of the tree
  29.     while (turtle.detect() and dist < 60) do
  30.         turtle.dig()
  31.         turtle.turnRight()
  32.         turtle.dig()
  33.         if (turtle.detectUp()) then
  34.             turtle.digUp()
  35.         end
  36.         turtle.up()
  37.         turtle.turnLeft()
  38.         dist = dist + 1
  39.     end
  40.     --position for the last column on the way down
  41.     turtle.turnRight()
  42.     turtle.forward()
  43.     turtle.turnLeft()
  44.     --clear the last column as we go down the tree
  45.     while (dist > 0) do
  46.         dist = dist - 1
  47.         turtle.dig()
  48.         turtle.down()
  49.     end
  50.     turtle.dig()
  51.     --reset turtle to initial position
  52.     turtle.turnLeft()
  53.     turtle.turnLeft()
  54.     turtle.forward()
  55.     turtle.turnRight()
  56.     turtle.forward()
  57.     turtle.turnRight()
  58. end
  59.  
  60. function plantTree()
  61.     turtle.forward()
  62.     turtle.forward()
  63.     turtle.turnRight()
  64.     turtle.place()  --back right
  65.     turtle.turnRight()
  66.     turtle.forward()
  67.     turtle.turnLeft()
  68.     turtle.place()  --front right
  69.     turtle.turnLeft()
  70.     turtle.place()  --back left
  71.     turtle.turnLeft()
  72.     turtle.turnLeft()
  73.     turtle.forward()
  74.     turtle.turnRight()
  75.     turtle.turnRight()
  76.     turtle.place()  --front left
  77. end
  78.  
  79. local canRefuel = true
  80. while (true) do
  81.     while (turtle.getFuelLevel() < 400) then
  82.         if (fuel.canRefuel()) then
  83.             fuel.fuelUp()
  84.         else
  85.             print('Cannot refuel')
  86.             canRefuel = false
  87.             break
  88.         end
  89.     end
  90.     if (not canRefuel) then
  91.         break
  92.     end
  93.     if (isTree()) then
  94.         chopTree()
  95.         refreshInventory()
  96.         plantTree()
  97.     end
  98.     sleep(30)
  99. end
Add Comment
Please, Sign In to add comment