GeoffAlexander

timber

Jan 17th, 2021 (edited)
443
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. -- pastebin.com/nNgb6mcy
  2.  
  3. local WAIT_TIME = 5 -- time to wait to check if tree has grown
  4. local SAPLING_SLOT = 16
  5. local FUEL_SLOT = 1
  6. local DUMP_INTO_CHEST = true
  7. local WAITING_MESSAGE = "Waiting for tree to grow..."
  8.  
  9. term.clear()
  10. term.setCursorPos(1,1)
  11.  
  12. print(WAITING_MESSAGE)
  13.  
  14. function fuelCheck()
  15.     local fuelLevel = turtle.getFuelLevel()
  16.     if fuelLevel < 80 then
  17.         turtle.select(FUEL_SLOT)
  18.         turtle.refuel(1)
  19.         print("Refueled!")
  20.     end
  21. end
  22.  
  23. function chopUp()
  24.     turtle.digUp()
  25.     turtle.dig()
  26.     turtle.up()
  27.     turtle.dig()
  28. end
  29.  
  30. function chopDown()
  31.     turtle.digDown()
  32.     turtle.dig()
  33.     turtle.down()
  34. end
  35.  
  36. function changeSide()
  37.     turtle.turnLeft()
  38.     turtle.dig()
  39.     turtle.forward()
  40.     turtle.turnRight()
  41. end
  42.  
  43. function plantSaplings()
  44.     turtle.select(SAPLING_SLOT)
  45.     turtle.place()
  46.     turtle.turnLeft()
  47.     turtle.back()
  48.     turtle.place()
  49.     turtle.turnRight()
  50.     turtle.place()
  51.     turtle.back()
  52.     turtle.place()
  53. end
  54.  
  55. function dump()
  56.     print("Dumping in chest below!")
  57.     for i = 2, 15 do
  58.         turtle.select(i)
  59.         turtle.dropDown()
  60.     end
  61.     turtle.select(SAPLING_SLOT)
  62. end
  63.  
  64. function checkTree()
  65.     local success, data = turtle.inspect()
  66.     if success and data.tags["minecraft:logs"] == true then
  67.         print("Tree has grown!")
  68.         fuelCheck()
  69.         chopTree()
  70.     else
  71.         os.sleep(WAIT_TIME)
  72.     end
  73. end
  74.  
  75. function chopTree()
  76.     turtle.select(SAPLING_SLOT)
  77.     turtle.dig()
  78.     turtle.forward()
  79.     local success, dataUp = turtle.inspectUp()
  80.     if not success then
  81.         turtle.back()
  82.         error("\n****\nNo Tree to fell!\n****\n")
  83.     end
  84.     while dataUp.tags["minecraft:logs"] == true do
  85.         chopUp()
  86.         success, dataUp = turtle.inspectUp()
  87.         if not success then
  88.             chopUp()
  89.             break
  90.         end
  91.     end
  92.     chopUp()
  93.     changeSide()
  94.     chopUp()
  95.     while turtle.detectDown() == false do
  96.         turtle.down()
  97.     end
  98.     local success, dataDown = turtle.inspectDown()
  99.     if not success then
  100.         error()
  101.     end
  102.     while dataDown.tags["minecraft:logs"] == true do
  103.         chopDown()
  104.         success, dataDown = turtle.inspectDown()
  105.         if not success then
  106.             break
  107.         end
  108.     end
  109.     turtle.dig()
  110.     plantSaplings()
  111.     if DUMP_INTO_CHEST == true then
  112.         dump()
  113.         print("Dumped items!")
  114.     end
  115.     print(WAITING_MESSAGE)
  116. end
  117.  
  118.  
  119. while true do
  120.     checkTree()
  121. end
RAW Paste Data