Advertisement
sasaa86

treefarm

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