Advertisement
PhamKun

TurtleOakTreeArea

Aug 10th, 2022 (edited)
912
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.11 KB | None | 0 0
  1. local wide = 7
  2. local long = 9
  3. local sapling = "minecraft:oak_sapling"
  4. local log = "minecraft:oak_log"
  5. --function
  6. local function checkF()
  7.     if turtle.getFuelLevel() == 0 then
  8.         turtle.select(16)
  9.         turtle.refuel(1)
  10.     end
  11. end
  12.  
  13. local function placeSapling()
  14.     local b, data = turtle.inspectDown()
  15.     if b == false then
  16.         for i = 1, 15, 1 do
  17.             turtle.select(i)
  18.             if turtle.getItemCount() > 0 then
  19.                 if turtle.getItemDetail().name == sapling then
  20.                     turtle.placeDown()
  21.                     return
  22.                 elseif i == 15 then
  23.                     io.write("No More Sapling In Inventory \n")
  24.                 end
  25.             else
  26.                 io.write("No More Sapling at this slot \n")
  27.             end
  28.         end
  29.     end
  30. end
  31.  
  32. local function checkSapling()
  33.     local b, data = turtle.inspectDown()
  34.     if b and data.name == log then
  35.         return true
  36.     else
  37.         return false
  38.     end
  39. end
  40.  
  41. local function chopTree()
  42.     turtle.dig()
  43.     checkF()
  44.     turtle.digDown()
  45.     turtle.down()
  46.     checkF()
  47.     turtle.up()
  48.     checkF()
  49.     placeSapling()
  50.     while turtle.detectUp() do
  51.         local a, b = turtle.inspectUp()
  52.         if a == true and (b.name == log or b.name == "oak_leaves")then
  53.             turtle.digUp()
  54.             checkF()
  55.             turtle.up()
  56.         else
  57.             break
  58.         end
  59.     end
  60.     while turtle.detectDown() == false do
  61.         checkF()
  62.         turtle.down()
  63.         local c, d = turtle.inspectDown()
  64.         --in case the next tree grows, which blocked the path it went up
  65.         if c == true and d.name == "minecraft:dirt" then
  66.             checkF()
  67.             if turtle.up() == false then
  68.                 turtle.digUp()
  69.                 turtle.up()
  70.             end
  71.             break
  72.         end
  73.     end
  74. end
  75.  
  76. local function moveAround()
  77.     checkF()
  78.     if turtle.detect() then
  79.         turtle.dig()
  80.         turtle.forward()
  81.         placeSapling()
  82.         turtle.suckDown()
  83.     else
  84.         turtle.forward()
  85.         placeSapling()
  86.         turtle.suckDown()
  87.     end
  88. end
  89.  
  90. local function init()
  91.     for i = 1, long, 1 do
  92.         for j = 1, wide, 1 do
  93.             moveAround()
  94.             if checkSapling() then
  95.                 chopTree()
  96.                 placeSapling()
  97.             end
  98.             placeSapling()
  99.         end
  100.         if i % 2 == 1 then
  101.             turtle.turnRight()
  102.             moveAround()
  103.             if checkSapling() then
  104.                 chopTree()
  105.             end
  106.             turtle.turnRight()
  107.             placeSapling()
  108.         elseif i % 2 == 0 then
  109.             turtle.turnLeft()
  110.             moveAround()
  111.             if checkSapling() then
  112.                 chopTree()
  113.             end
  114.             turtle.turnLeft()
  115.             placeSapling()
  116.         end
  117.     end
  118. end
  119.  
  120. local function backToStart()
  121.     if long % 2 == 1 then
  122.         for i = 1,wide, 1 do
  123.             moveAround()
  124.         end
  125.         turtle.turnRight()
  126.         for i = 1, long, 1 do
  127.             moveAround()
  128.         end
  129.         turtle.turnRight()
  130.     end
  131.     if long % 2 == 0 then
  132.         turtle.turnLeft()
  133.         for i = 1, wide, 1 do
  134.             moveAround()
  135.         end
  136.         turtle.turnRight()
  137.     end
  138. end
  139.  
  140. local function dropoff()
  141.     for i = 2, 15, 1 do
  142.         turtle.select(i)
  143.         turtle.dropDown()
  144.     end
  145. end
  146.  
  147. local function getFuel()
  148.     turtle.select(16)
  149.     if 64-turtle.getItemCount() <= 64 then
  150.         turtle.select(16)
  151.         turtle.suckUp(64-turtle.getItemCount())
  152.     end
  153. end
  154.  
  155. local function getSapling()
  156.     turtle.select(1)
  157.     if turtle.getItemDetail() == nil then
  158.         turtle.turnLeft()
  159.         turtle.turnLeft()
  160.         turtle.suck()
  161.         turtle.turnLeft()
  162.         turtle.turnLeft()
  163.     elseif (turtle.getItemDetail().name == sapling) == false then
  164.         turtle.dropDown()
  165.         turtle.turnLeft()
  166.         turtle.turnLeft()
  167.         turtle.suck()
  168.         turtle.turnLeft()
  169.         turtle.turnLeft()
  170.     elseif turtle.getItemDetail().name == sapling then
  171.         local c = turtle.getItemCount()
  172.         turtle.turnLeft()
  173.         turtle.turnLeft()
  174.         turtle.suck(64 - c)
  175.         turtle.turnLeft()
  176.         turtle.turnLeft()
  177.     end
  178.    
  179. end
  180. --main
  181. getSapling()
  182. getFuel()
  183. init()
  184. backToStart()
  185. getFuel()
  186. getSapling()
  187. while true do
  188.     sleep(60)
  189.     for i = 1, long, 1 do
  190.         for j = 1, wide, 1 do
  191.             moveAround()
  192.             if checkSapling() then
  193.                 chopTree()
  194.                 placeSapling()
  195.             end
  196.         end
  197.         if i % 2 == 1 then
  198.             turtle.turnRight()
  199.             moveAround()
  200.             if checkSapling() then
  201.                 chopTree()
  202.                 placeSapling()
  203.             end
  204.             turtle.turnRight()
  205.         elseif i % 2 == 0 then
  206.             turtle.turnLeft()
  207.             moveAround()
  208.             if checkSapling() then
  209.                 chopTree()
  210.                 placeSapling()
  211.             end
  212.             turtle.turnLeft()
  213.         end
  214.     end
  215.     backToStart()
  216.     dropoff()
  217.     getFuel()
  218.     getSapling()
  219. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement