Thanateros

Chop

Dec 5th, 2020
446
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.26 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.  
  10.     turtle.select(3)
  11.     while not turtle.compare() do
  12.         turtle.select(2)                --selects bone-meal
  13.         turtle.place()                  --fertilizes sapling
  14.         turtle.select(3)
  15.     end
  16.  
  17.     turtle.suck()                   --picks up any saplings that have fallen
  18. end
  19.  
  20. -- This function checks fuel level and refuels
  21. function fuel()
  22.     if turtle.getFuelLevel() < 50 then      --checks fuel level and refuels
  23.         turtle.select(16)
  24.         turtle.refuel(5)            --picks up any saplings that have fallen
  25.     end
  26.     print( turtle.getFuelLevel() .. " fuel left.")  --displays fuel level to user
  27. end
  28.  
  29. -- This function cuts a column directly above the turtle and then returns to ground level
  30. function column()
  31.     if turtle.detectUp() then      --cut tree down
  32.         turtle.digUp()
  33.         turtle.up()
  34.         column()
  35.         turtle.down()
  36.     end
  37. end
  38.  
  39. -- This function moves from start position, runs column and returns to start position
  40. function fell()
  41.     turtle.dig()                    --breaks bottom block of tree
  42.     turtle.forward()                --move into gap
  43.  
  44.     turtle.suck()               --picks up any saplings that have fallen
  45.     column()                    --run column function
  46.     turtle.suck()               --picks up any saplings that have fallen
  47.  
  48.     turtle.turnRight()              --return to start
  49.     turtle.turnRight()
  50.     turtle.forward()
  51. end
  52.  
  53. -- This function empties all collected wood into chest, checks sapling and fuel supplies and restocks
  54. function empty()
  55.     for j = 4, 15 do                -- empty slots 3 to 15 into chest
  56.         turtle.select(j)
  57.         turtle.drop()
  58.     end
  59.     turtle.turnLeft()
  60.     if turtle.getItemCount(16) < 5 then     -- replenish fuel stocks
  61.         turtle.select(16)
  62.         turtle.suck(10)
  63.     end
  64.     turtle.turnLeft()
  65.     if turtle.getItemCount(1) < 5 then      --replenish sapling stocks
  66.         turtle.turnLeft()
  67.         turtle.select(1)
  68.         turtle.suck()
  69.         turtle.turnRight()
  70.     end
  71. end
  72.  
  73. -- This function checks to see if the sapling has been fertilized into a full tree
  74. function compare()
  75.     turtle.select(1)
  76.     return turtle.compare()
  77. end
  78.  
  79. -- This block triggers the appropriate functions in the correct order.
  80. repeat                          --start loop
  81.     fuel()                      --check fuel
  82.     plant()                     --plant and fertilize tree
  83.     fell()          --if tree has grown cut down tree
  84.     empty()                     --empty harvest and restock fuel and materials
  85. until 1 > 2                     -- always false creating infinite loop
Add Comment
Please, Sign In to add comment