Advertisement
Grifter

Turtle Automatic Tree Farm - Computercraft Lua

Jan 3rd, 2013
17,205
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.03 KB | None | 0 0
  1. --[[ Running this script on a turtle with saplings in slot 1, bone-meal in slot 2 and coal in slot 16 and a chest behind the turtle for the wood drop off point will create an automatic tree farm. combining this with a chest to the left of the turtle for sapling replenishment and chest to the right for coal replenishment will ensure a long running automated process.]]
  2.  
  3. -- This function lays saplings and applies bone-meal
  4. function plant()
  5.     turtle.select(1)                --selects sapling
  6.     turtle.place()                  --places sapling
  7.     turtle.select(2)                --selects bone-meal
  8.     turtle.place()                  --fertilizes sapling
  9.     turtle.suck()                   --picks up any saplings that have fallen
  10. end
  11.  
  12. -- This function checks fuel level and refuels
  13. function fuel()
  14.     if turtle.getFuelLevel() < 50 then      --checks fuel level and refuels
  15.         turtle.select(16)
  16.         turtle.refuel(5)            --picks up any saplings that have fallen
  17.     end
  18.     print( turtle.getFuelLevel() .. " fuel left.")  --displays fuel level to user
  19. end
  20.  
  21. -- This function cuts a column directly above the turtle and then returns to ground level
  22. function column()
  23.     while turtle.detectUp() == true do      --cut tree down
  24.         turtle.digUp()
  25.         turtle.up()
  26.         turtle.suck()               --picks up any saplings that have fallen
  27.     end
  28.     while turtle.detectDown() == false do       -- return to ground level
  29.         turtle.down()
  30.         turtle.suck()               --picks up any saplings that have fallen
  31.     end
  32. end
  33.  
  34. -- This function moves from start position, runs column and returns to start position
  35. function fell()
  36.     turtle.dig()                    --breaks bottom block of tree
  37.     turtle.forward()                --move into gap
  38.     column()                    --run column function
  39.     turtle.turnRight()              --return to start
  40.     turtle.turnRight()
  41.     turtle.forward()
  42. end
  43.  
  44. -- This function empties all collected wood into chest, checks sapling and fuel supplies and restocks
  45. function empty()
  46.     for j = 3, 15 do                -- empty slots 3 to 15 into chest
  47.         turtle.select(j)
  48.         turtle.drop()
  49.     end
  50.     turtle.turnLeft()
  51.     if turtle.getItemCount(16) < 5 then     -- replenish fuel stocks
  52.         turtle.select(16)
  53.         turtle.suck(10)
  54.     end
  55.     turtle.turnLeft()
  56.     if turtle.getItemCount(1) < 5 then      --replenish sapling stocks
  57.         turtle.turnLeft()
  58.         turtle.select(1)
  59.         turtle.suck()
  60.         turtle.turnRight()
  61.     end
  62. end
  63.  
  64. -- This function checks to see if the sapling has been fertilized into a full tree
  65. function compare()
  66.     turtle.select(1)
  67.     if turtle.compare() == true then
  68.         return true -- false could indicate that there is no bonemeal or saplings
  69.     else
  70.         return false  
  71.     end
  72. end
  73.  
  74. -- This block triggers the appropriate functions in the correct order.
  75. repeat                          --start loop
  76.     fuel()                      --check fuel
  77.     plant()                     --plant and fertilize tree
  78.     fuel()                      --check fuel again
  79.     if compare() == false then          --if tree has grown cut down tree
  80.         fell()
  81.     else                        --if tree hasn't grown display error
  82.         print("error")
  83.         repeat
  84.             sleep(1)
  85.             turtle.select(2)
  86.         until turtle.getItemCount() > 20    --this will terminate script
  87.     end
  88.     empty()                     --empty harvest and restock fuel and materials
  89. until 1 > 2                     -- always false creating infinite loop
Advertisement
Comments
Add Comment
Please, Sign In to add comment
Advertisement