dealingwith

ComputerCraft TreeFarm

Oct 25th, 2014
242
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.76 KB | None | 0 0
  1. -- tree farmer
  2. -- requires a very specific tree farm setup
  3. --   which I will document somewhere and
  4. --   put a link to when that's done
  5. -- put fuel in first slot
  6. -- put 1 block of wood type in second slot
  7. -- put saplings of wood type in third slot
  8.  
  9. function fuel()
  10.   if turtle.getFuelLevel() < 30 then
  11.     turtle.select(1)
  12.     if turtle.refuel(1) then
  13.       return true
  14.     end
  15.     print("Refuelling failed.")
  16.     return false
  17.   end
  18. end
  19.  
  20. function chop ()
  21.   local blocksMovedUp = 0
  22.   while turtle.detect() do
  23.     turtle.dig()
  24.     if turtle.detectUp() then
  25.       turtle.digUp()
  26.     end
  27.     turtle.up()
  28.     blocksMovedUp = blocksMovedUp + 1
  29.   end
  30.   while blocksMovedUp > 0 do
  31.     turtle.down()
  32.     blocksMovedUp = blocksMovedUp - 1
  33.   end
  34.   -- plant new tree
  35.   turtle.select(3)
  36.   turtle.place()
  37.   return true
  38. end
  39.  
  40. function goNext()
  41.   i = 1
  42.   for i=1,4,1 do
  43.     turtle.forward()
  44.   end
  45.   turtle.turnLeft()
  46.   -- has the tree grown?
  47.   ret = false
  48.   while ret == false do
  49.     ret = detectTree()
  50.   end
  51. end
  52.  
  53. function detectTree()
  54.   turtle.select(2)
  55.   if turtle.compare() then
  56.     return true
  57.   else
  58.     return false
  59.   end
  60. end
  61.  
  62. function farmTree()
  63.   goNext()
  64.   chop()
  65. end
  66.  
  67. -- farms the entire treefarm
  68. function treeFarm()
  69.   side = 0
  70.   for side=1,4,1 do
  71.     for tree=1,2,1 do
  72.       farmTree()
  73.       turtle.turnRight()
  74.     end
  75.     turtle.turnRight()
  76.   end
  77. end
  78.  
  79. function dump()
  80.   for i=4,16,1 do
  81.     turtle.select(i)
  82.     turtle.drop()
  83.   end
  84. end
  85.  
  86. -- keep farming trees until...
  87. while true do
  88.   if fuel() == false then
  89.     print('Ran out of fuel')
  90.     break
  91.   end
  92.   treeFarm()
  93.   dump()
  94.   -- if there are no more saplings
  95.   if turtle.getItemCount(3) < 8 then
  96.     print('Ran out of saplings')
  97.     break
  98.   end
  99. end
Advertisement
Add Comment
Please, Sign In to add comment