Advertisement
Houshalter

ComputerCraft Simple Tree Farm Script

Dec 17th, 2015
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.85 KB | None | 0 0
  1. a = ...
  2. local size = a or 10
  3. local timer = 0
  4. local blocks = {
  5.     'log',
  6.     'blockRubWood'
  7. }
  8. local saplings = {
  9.     'sapling',
  10.     'chest',
  11.     'torch'
  12. }
  13.  
  14. function checkSapling(s)
  15.     s = s:lower()
  16.     local a = false
  17.     for i, p in ipairs(saplings) do
  18.         a = a or string.find(s, p:lower())
  19.     end
  20.     return a
  21. end
  22.  
  23. function digForward()
  24.     while not turtle.forward() do
  25.         turtle.dig()
  26.     end
  27. end
  28.  
  29. function match(s)
  30.     s = s:lower()
  31.     local a = false
  32.     for i, p in ipairs(blocks) do
  33.         a = a or string.find(s, p:lower())
  34.     end
  35.     return a
  36. end
  37.  
  38. function harvestTree()
  39.     local height = 0
  40.     turtle.digDown()
  41.     while turtle.detectUp() do
  42.         turtle.digUp()
  43.         if turtle.up() then
  44.             height = height + 1
  45.         end
  46.     end
  47.     for i = 1, height do
  48.         while not turtle.down() do turtle.digDown() end
  49.     end
  50. end
  51.  
  52. turtle.select(1)
  53. while true do
  54.     local right = true
  55.     for x = 1, size do
  56.         for y = 1, size do
  57.             turtle.suckDown()
  58.             if ((not turtle.detectDown()) and (turtle.getItemCount(1) > 1)) then
  59.                 turtle.placeDown()
  60.             end
  61.             local a, data = turtle.inspectUp()
  62.             if a and match(data.name) then
  63.                 harvestTree()
  64.             else
  65.                 local b, data2 = turtle.inspectDown()
  66.                 if b and not checkSapling(data2.name) then
  67.                     turtle.digDown()
  68.                 end
  69.                 if a then turtle.digUp() end
  70.             end
  71.            
  72.             digForward()
  73.         end
  74.         if right then
  75.             turtle.turnRight()
  76.             digForward()
  77.             turtle.turnRight()
  78.         else
  79.             turtle.turnLeft()
  80.             digForward()
  81.             turtle.turnLeft()
  82.         end
  83.         right = not right
  84.         digForward()
  85.     end
  86.     if right then
  87.         turtle.turnLeft()
  88.     else
  89.         turtle.turnRight()
  90.     end
  91.     for i = 1, size do
  92.       digForward()
  93.     end
  94.     if right then
  95.         turtle.turnRight()
  96.     else
  97.         turtle.turnLeft()
  98.     end
  99.     local a, data = turtle.inspectDown()
  100.     if a and string.find(data.name:lower(), 'chest') then
  101.         for i = 2, 16 do
  102.             turtle.select(i)
  103.             turtle.dropDown(64)
  104.         end
  105.     end
  106.     sleep(timer)
  107. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement