Advertisement
sasaa86

Treefarm turtle

Mar 5th, 2021 (edited)
1,029
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.62 KB | None | 0 0
  1. function isSaplingInSlot(slot)
  2.     sapling_list = {"minecraft:birch_sapling", "minecraft:oak_sapling", "minecraft:spruce_sapling", "minecraft:jungle_sapling", "minecraft:acacia_sapling", "minecraft:dark_oak_sapling"}
  3.     if (slot == nil) then
  4.         slot = turtle.getSelectedSlot()
  5.     end
  6.     item = turtle.getItemDetail(slot)
  7.     if succes then
  8.         for i=1, #sapling_list do
  9.             if (item.tags == sapling_list[i]) then
  10.                 return true
  11.             end
  12.         end
  13.     else
  14.         -- nothing found
  15.         return false
  16.     end
  17. end
  18.  
  19. -- is sapling
  20. function isSapling()
  21.     succes, item = turtle.inspect()
  22.     if succes and (item.tags == item.tags["minecraft:saplings"]) then
  23.         return true
  24.     else
  25.         -- nothing found
  26.         return false
  27.     end
  28. end
  29. function isSaplingUp()
  30.     succes, item = turtle.inspectUp()
  31.     if succes and (item.tags == item.tags["minecraft:saplings"]) then
  32.         return true
  33.     else
  34.         -- nothing found
  35.         return false
  36.     end
  37. end
  38. function isSaplingDown()
  39.     succes, item = turtle.inspectDown()
  40.     if succes and (item.tags == item.tags["minecraft:saplings"]) then
  41.         return true
  42.     else
  43.         -- nothing found
  44.         return false
  45.     end
  46. end
  47.  
  48. -- is tree
  49. function isTree()
  50.     succes, item = turtle.inspect()
  51.     if succes and (item.tags == item.tags["minecraft:logs"]) then
  52.         return true
  53.     else
  54.         -- nothing found
  55.         return false
  56.     end
  57. end
  58. function isTreeUp()
  59.     succes, item = turtle.inspectUp()
  60.     if succes and (item.tags == item.tags["minecraft:logs"]) then
  61.         return true
  62.     else
  63.         -- nothing found
  64.         return false
  65.     end
  66. end
  67. function isTreeDown()
  68.     succes, item = turtle.inspectDown()
  69.     if succes and (item.tags == item.tags["minecraft:logs"]) then
  70.         return true
  71.     else
  72.         -- nothing found
  73.         return false
  74.     end
  75. end
  76.  
  77. -- is leaves
  78. function isLeave()
  79.     succes, item = turtle.inspect()
  80.     if succes and (item.tags == item.tags["minecraft:leaves"]) then
  81.         return true
  82.     else
  83.         -- nothing found
  84.         return false
  85.     end
  86. end
  87. function isLeaveUp()
  88.     succes, item = turtle.inspectUp()
  89.     if succes and (item.tags == item.tags["minecraft:leaves"]) then
  90.         return true
  91.     else
  92.         -- nothing found
  93.         return false
  94.     end
  95. end
  96. function isLeaveDown()
  97.     succes, item = turtle.inspectDown()
  98.     if succes and (item.tags == item.tags["minecraft:leaves"]) then
  99.         return true
  100.     else
  101.         -- nothing found
  102.         return false
  103.     end
  104. end
  105.  
  106. -- checks for box to take saplings from or turns 360 and sucks in all aplings
  107. function getSaplings()
  108.     slot = 0
  109.     chest = peripheral.find("minecraft:chest")
  110.     chest.side = peripheral.getName(chest)
  111.     if chest ~= nil then
  112.         if (chest.side == "left") then
  113.             turtle.turnLeft()
  114.         elseif (chest.side == "right") then
  115.             turtle.turnRight()
  116.         elseif (chest.side == "back") then
  117.             turtle.turnRight()
  118.             turtle.turnRight()
  119.         end
  120.        
  121.         for i=1, chest.size do
  122.             item = chest.getItemDetail(i)
  123.             if (item.tags == item.tags["minecraft:saplings"]) then
  124.                 slot = i
  125.             end
  126.         end
  127.         if (slot ~= 0) and (slot <= 15) then
  128.             for p=1, 15 do
  129.                 if (chest.side == "top") then
  130.                     turtle.suckUp()
  131.                 elseif (chest.side == "bottom") then
  132.                     turtle.suckDown()
  133.                 else
  134.                     turtle.suck()
  135.                 end
  136.             end
  137.             for a=2, 16 do
  138.                 item = turtle.getItemDetail(a)
  139.                 if (item.tags == item.tags["minecraft:saplings"]) then
  140.                     turtle.select(a)
  141.                     turtle.transferTo(1)
  142.                 end
  143.             end
  144.             for a=2, 16 do
  145.                 if (chest.side == "top") then
  146.                     turtle.dropUp()
  147.                 elseif (chest.side == "bottom") then
  148.                     turtle.dropDown()
  149.                 else
  150.                     turtle.drop()
  151.                 end
  152.             end
  153.         end
  154.        
  155.         if (chest.side == "left") then
  156.             turtle.turnRight()
  157.         elseif (chest.side == "right") then
  158.             turtle.turnLeft()
  159.         elseif (chest.side == "back") then
  160.             turtle.turnRight()
  161.             turtle.turnRight()
  162.         end
  163.     else
  164.         turtle.turnRight()
  165.         turtle.suck()
  166.         turtle.turnRight()
  167.         turtle.suck()
  168.         turtle.turnRight()
  169.         turtle.suck()
  170.         turtle.turnRight()
  171.         turtle.suck()
  172.     end
  173. end
  174.  
  175. function getInventoryCount()
  176.     items = 0
  177.     for i=2, 16 do
  178.         item = turtle.getItemDetail(i)
  179.         if item ~= nil then
  180.             items = items + item.count
  181.         end
  182.     end
  183.     return items
  184. end
  185.  
  186.  
  187. -- ### LOOP ###
  188. while true do
  189.     if isSaplingInSlot(1) == 0 then
  190.         getSaplings()
  191.         if isSapling() then
  192.             --wait
  193.             os.sleep(1)
  194.         else
  195.             turtle.select(1)
  196.             turtle.place()
  197.         end
  198.     end
  199.     if isTree() then
  200.         turtle.dig()
  201.         turtle.forward()
  202.         while isTreeUp or isLeaveUp do
  203.             turtle.dig()
  204.             turtle.digUp()
  205.             turtle.up()
  206.         end
  207.         while turtle.down() do
  208.             -- nothing
  209.         end
  210.         turtle.back()
  211.     end
  212.    
  213.     -- ### blablabla get item to chest or hopper below ###
  214.     if getInventoryCount() > 900 then
  215.         while getInventoryCount() < 32 do
  216.             turtle.turnRight()
  217.             turtle.turnRight()
  218.             turtle.turnRight()
  219.             turtle.turnRight()
  220.         end
  221.         print("Inventory cleared")
  222.     end
  223. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement