DYankee

Tree farm

Jun 24th, 2021 (edited)
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.44 KB | None | 0 0
  1. chests = {
  2.     "quark:oak_chest",
  3.     "charm:oak_chest",
  4. }
  5. fuel = {
  6.     "minecraft:coal_block",
  7.     "actuallyadditions:block_misc",
  8.     "quark:charcoal_block",
  9. }
  10.  
  11. droppedItems = {
  12.     "minecraft:stick",
  13.     "minecraft:apple"
  14. }
  15.  
  16. function dropTrash()
  17.     for slotNum = 1, 16, 1 do
  18.         local item = turtle.getItemDetail(slotNum)
  19.         if(item ~= nil) then
  20.             for FilterIndex = 1, #droppedItems, 1 do
  21.                 if(item.name == droppedItems[FilterIndex]) then
  22.                 print("Droppign - " .. item.name)
  23.                 turtle.select(slotNum)
  24.                 turtle.dropDown()
  25.                 end
  26.             end
  27.         end
  28.     end
  29. end
  30.  
  31. function getFuelIndex()
  32.     for slotNum = 1, 16, 1 do
  33.         local Item = turtle.getItemDetail(slotNum)
  34.         if(Item ~=nil) then
  35.             for fuelIndex =1, #fuel, 1 do
  36.                 if(Item.name == fuel[fuelIndex]) then
  37.                 return slotNum
  38.                 end
  39.             end
  40.         end
  41.     end
  42. end
  43.  
  44. function refuel()
  45.     if(turtle.getFuelLevel() < 400) then
  46.     local Index = getFuelIndex()
  47.       if(Index ~= nil) then
  48.       turtle.select(Index)
  49.       turtle.refuel(2)
  50.       end
  51.     end
  52. end
  53.  
  54. function checkGrowth()
  55.     grown = turtle.detect()
  56.     if grown ~= true then
  57.         isGrown = false
  58.     elseif grown == true then
  59.         isGrown = true
  60.     end
  61. end
  62.  
  63. function getSaplingIndex()
  64.     for slotNum = 1, 16,1 do
  65.        local item = turtle.getItemDetail(slotNum)
  66.        if(item ~= nil) then
  67.            if (item.name == "byg:fir_sapling") then
  68.                return slotNum
  69.            end
  70.        end
  71.     end
  72. end
  73.  
  74. function turtleRefill()
  75.  
  76.     isBlock, data = turtle.inspectDown()
  77.     if (data.name == "upgrade_aquatic:driftwood_chest") then
  78.         fuelSlot = getFuelIndex()
  79.         if fuelSlot ~= nil then
  80.             turtle.select(fuelSlot)
  81.             local coalBlocks = turtle.getItemCount()
  82.             if coalBlocks <= 30 then
  83.                 turtle.suckDown(20)
  84.             end
  85.         elseif fuelSlot == nil then
  86.             turtle.suckDown(30)
  87.         end
  88.     refuel()
  89.     end
  90.     turtle.forward()
  91.     isBlock, data = turtle.inspectDown()
  92.     if (data.name == "charm:oak_chest") then
  93.         sapSlot = getSaplingIndex()
  94.         if sapSlot ~= nil then
  95.             turtle.select(sapSlot)
  96.             local saplings = turtle.getItemCount()
  97.             if saplings <= 30 then
  98.                 turtle.suckDown(20)
  99.             end
  100.         elseif sapSlot == nil then
  101.             turtle.suckDown(30)
  102.         end
  103.     elseif (data.name ~= "upgrade_aqatic:driftwood_chest") then
  104.         print("error finding chest")
  105.     end
  106.     turtle.turnRight()
  107.     turtle.forward()
  108.     turtle.forward()
  109. end
  110.  
  111. function plantTree()
  112.     local index = getSaplingIndex()
  113.     if (index ~= nil) then
  114.         turtle.select(index)
  115.         turtle.placeDown()
  116.     elseif (index == nil) then
  117.         print("Need saplings")
  118.     end
  119. end
  120.  
  121. function cutTree()
  122.     turtle.dig()
  123.     turtle.forward()
  124.     local isBlock,isSap = turtle.inspectDown()
  125.     if isSap.name ~= "byg:fir_sapling" then
  126.         turtle.digDown()
  127.         local treeLeft = turtle.detectUp()
  128.         local hight = 0
  129.         while treeLeft == true do
  130.             turtle.digUp()
  131.             turtle.up()
  132.             hight = hight + 1
  133.             treeLeft = turtle.detectUp()
  134.         end
  135.         for i = 1, hight, 1 do
  136.             turtle.down()
  137.         end
  138.         plantTree()
  139.     end
  140. end
  141.  
  142. function depositWood()
  143.     for slotNum = 1, 16 ,1 do
  144.         local item = turtle.getItemDetail(slotNum)
  145.         if(item ~= nil) then
  146.             if(item.name == "byg:fir_log") then
  147.                 local itemCount = turtle.getItemCount(slotNum)
  148.                 turtle.select(slotNum)
  149.                 turtle.dropDown(itemCount)
  150.             end
  151.         end
  152.     end
  153. end
  154.  
  155. function goBackToStart()
  156.     turtle.forward()
  157.     turtle.turnRight()
  158.     atStart = false
  159.     while atStart == false do
  160.         local isBlock, data= turtle.inspectDown()
  161.         if (data.name == "byg:fir_fence" ) then
  162.             turtle.forward()
  163.         elseif (data.name == "snowrealmagic:fence") then
  164.             turtle.forward()
  165.         elseif (data.name == "byg:fir_fence_gate") then
  166.             turtle.turnRight()
  167.             turtle.forward()
  168.         elseif (data.name == "upgrade_aquatic:driftwood_chest") then
  169.             atStart = true
  170.         elseif (isBlock ~= true) then
  171.             turtle.forward()
  172.         end
  173.     end
  174. end
  175.  
  176. function cutRow()
  177.     checkGrowth()
  178.     maxwait = 1
  179.     while grown ~= true do
  180.         sleep(30)
  181.         checkGrowth()
  182.         maxwait = maxwait + 1
  183.         if maxwait >= 6 then
  184.             grown = true
  185.         end
  186.     end
  187.         cutTree()
  188.         cutTree()
  189.         cutTree()
  190.         cutTree()
  191. end
  192.  
  193. function nextRowRight()
  194.     turtle.forward()
  195.     turtle.turnRight()
  196.     turtle.forward()
  197.     turtle.forward()
  198.     turtle.turnRight()
  199. end
  200.  
  201. function nextRowLeft()
  202.     turtle.forward()
  203.     turtle.turnLeft()
  204.     turtle.forward()
  205.     turtle.forward()
  206.     turtle.turnLeft()
  207. end
  208.  
  209. function cutTrees()
  210.         cutRow()
  211.         nextRowRight()
  212.         cutRow()
  213.         nextRowLeft()
  214.         cutRow()
  215.         turtle.forward()
  216.         dropTrash()
  217.         turtle.forward()
  218.         turtle.forward()
  219.         depositWood()
  220.         turtle.turnRight()
  221.         turtle.forward()
  222.         goBackToStart()
  223.         turtleRefill()
  224. end
  225.  
  226. while true do
  227.     cutTrees()
  228. end
Add Comment
Please, Sign In to add comment