soee

tfeller2

Sep 15th, 2014
237
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. --pastebin:YSfqfygc
  2.  
  3. local wood, sapling = 1, 2
  4. local treeHeight = 0
  5. local treeCount = 0
  6. local plantCount = 6
  7. local rowCount = 1
  8. local pauseLength = 60
  9.  
  10. function tRefuel()
  11.     while turtle.getFuelLevel() < 200 do
  12.         turtle.select(wood) --charcol in this slot
  13.         turtle.refuel(1)
  14.         print("Refueled")
  15.     end
  16.     print( "Fuel Level: ", turtle.getFuelLevel() )
  17. end
  18.  
  19. function tF()
  20.     while not turtle.forward() do
  21.         -- turtle blocked from moving forward
  22.         print( "Turtle blocked from moving forward" )
  23.         sleep(3) -- wait 3 seconds to let mob move away
  24.     end
  25. end
  26.  
  27. function tVacume()
  28.     for i = 1, 4 do
  29.         turtle.turnLeft()
  30.         turtle.suck()
  31.     end
  32.     turtle.suckUp() -- in case a sapling fell on turtle's head:D
  33. end
  34.  
  35. local function harvestTree()
  36.     treeCount = treeCount + 1
  37.     while turtle.compare() do
  38.         turtle.dig()
  39.         if turtle.detectUp() then
  40.             turtle.digUp()
  41.         end
  42.         turtle.up()
  43.         treeHeight = treeHeight + 1
  44.     end
  45.     -- return to the ground
  46.     -- if blocked, dig
  47.     while treeHeight > 0 do
  48.         if turtle.down() then
  49.             treeHeight = treeHeight - 1
  50.         else
  51.             turtle.digDown()
  52.         end
  53.     end
  54.  
  55. end
  56.  
  57. local function moveNextTree()
  58.     for i=1,4 do
  59.         tVacume()
  60.         tF()
  61.     end
  62. end
  63.  
  64. function harvestRow()
  65.     tF()
  66.     -- check all trees for any that have grown
  67.     for i = 1, plantCount do
  68.         turtle.turnRight()
  69.         turtle.select(wood)
  70.         -- if the tree has grown
  71.         if turtle.compare() then
  72.             -- harvest the tree
  73.             harvestTree()
  74.  
  75.             -- plant a new sapling
  76.             turtle.select(sapling)
  77.             turtle.place()
  78.         else
  79.             turtle.select(sapling)
  80.             if not turtle.compare() then
  81.                 turtle.place()
  82.             end
  83.         end
  84.         -- move to next tree location
  85.         turtle.turnLeft()
  86.  
  87.         if i < plantCount then
  88.             moveNextTree()
  89.         end
  90.     end
  91.     -- round the corner
  92.     tF()
  93.     turtle.turnRight()
  94.     tF()
  95.     tF()
  96.     turtle.turnRight()
  97.     tRefuel()
  98. end
  99.  
  100. local function returnRow()
  101.     tF()
  102.     for i = 1, plantCount-1 do
  103.         moveNextTree()
  104.     end
  105.     tF()
  106.     turtle.turnRight()
  107.     tF()
  108.     tF()
  109.     turtle.turnRight()
  110. end
  111.  
  112.  
  113. local function dumpExcess()
  114.     turtle.turnRight()
  115.     turtle.turnRight()
  116.     -- dump excess items into chest if a chest is present
  117.     if turtle.detect() then
  118.         for i = 3, 16 do
  119.             turtle.select(i)
  120.             turtle.drop()
  121.         end
  122.         print( "Dropped off Excess Items")
  123.     end
  124.     turtle.turnRight()
  125.     turtle.turnRight()
  126. end
  127.  
  128. local function moveNextRow()
  129.     turtle.turnRight()
  130.     for i=1,4 do
  131.         tF()
  132.     end
  133.     turtle.turnLeft()
  134. end
  135.  
  136. local function returnToStart()
  137.     turtle.turnLeft()
  138.     for row = 1,rowCount-1 do
  139.         for i=1,4  do
  140.             tF()
  141.         end
  142.     end
  143.     turtle.turnRight()
  144. end
  145.  
  146.  
  147. -- main loop
  148. print( "Tree Area (plants x rows): ", plantCount, " x ", rowCount )
  149. while true do
  150.     tRefuel()
  151.     for row = 1,rowCount do
  152.         harvestRow()
  153.         returnRow()
  154.         if (row < rowCount) then
  155.             moveNextRow()
  156.         end
  157.     end
  158.     returnToStart()
  159.     print( "Tree Count: ", treeCount )
  160.     dumpExcess()
  161.     sleep(pauseLength) -- wait for trees to grow and saplings to fall
  162. end
Advertisement
Add Comment
Please, Sign In to add comment