tommy2805

chopping tree v2 alberi grossi

Jun 10th, 2024 (edited)
577
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.59 KB | None | 0 0
  1. -- Soglia di carburante sotto la quale stampare un avviso
  2. local LOW_FUEL_THRESHOLD = 500
  3. local LAST_BONEMEAL_CHECK = 0
  4. local PLANTING_LOOP = 0
  5.  
  6. -- Funzione per controllare se il blocco davanti è lo stesso tipo di quello nello slot dato
  7. function isBlock(slot)
  8.     local success, data = turtle.inspect()
  9.     local Detail = turtle.getItemDetail(slot)
  10.     if success and Detail and data.name == Detail.name then
  11.         return true
  12.     end
  13.     return false
  14. end
  15.  
  16. function isSapling()
  17.     return isBlock(2)
  18. end
  19.  
  20. function isLog()
  21.     return isBlock(4)
  22. end
  23.  
  24. -- Funzione per controllare se il blocco davanti è acqua
  25. function isWater()
  26.     local success, data = turtle.inspect()
  27.     if success then
  28.         return data.name == "minecraft:water" or data.name == "minecraft:flowing_water"
  29.     end
  30.     return false
  31. end
  32.  
  33. function fillResource(direction, steps, slot, resource)
  34.     print("Filling Up " .. resource .. "...")
  35.     for i=1,3 do
  36.         turtle.back()
  37.     end
  38.     for i=1,steps do
  39.         if direction == "left" then
  40.             turtle.turnLeft()
  41.         else
  42.             turtle.turnRight()
  43.         end
  44.     end
  45.     turtle.select(slot)
  46.     turtle.suck(63)
  47.     if resource == "Sapling" then
  48.         while turtle.getItemCount(slot) == 0 do
  49.             print("Sapling...")
  50.             sleep(15)
  51.             turtle.suck(63)
  52.         end
  53.     elseif resource == "fuel" then
  54.         local maxfuel = turtle.getFuelLimit()
  55.         while turtle.getFuelLevel() < maxfuel do
  56.             print("Fuel: " .. turtle.getFuelLevel() .. "/" .. turtle.getFueleLimit())
  57.             while turtle.getItemCount(slot) == 0 do
  58.                 turtle.suck(64)
  59.                 if turtle.getItemCount(slot) == 0 then
  60.                     sleep(15)
  61.                 end
  62.             end
  63.             turtle.refuel(1)
  64.         end
  65.         turtle.suck(64)
  66.     else
  67.         if turtle.getItemCount(slot) == 0 then
  68.             LAST_BONEMEAL_CHECK = 100;
  69.         end
  70.     end
  71.     for i=1,steps do
  72.         if direction == "left" then
  73.             turtle.turnRight()
  74.         else
  75.             turtle.turnLeft()
  76.         end
  77.     end
  78.     for i=1,3 do
  79.         turtle.forward()
  80.     end
  81.     print("Filled")
  82. end
  83.  
  84. function useBoneMeal()
  85.     print("Fertilizing...")
  86.     while not isLog() do
  87.         if turtle.getItemCount(3) == 0 then
  88.             if LAST_BONEMEAL_CHECK == 0 then
  89.                 fillResource("left",1,3,"BoneMeal")
  90.             else
  91.                 sleep(3)
  92.                 LAST_BONEMEAL_CHECK = LAST_BONEMEAL_CHECK - 1
  93.                 if LAST_BONEMEAL_CHECK % 10 == 0 then
  94.                     print("No fertilizer. New try to fill in: " .. LAST_BONEMEAL_CHECK*3 .. " seconds")
  95.                 end
  96.             end
  97.         else
  98.             turtle.select(3)
  99.             turtle.place()
  100.             sleep(1)
  101.         end
  102.     end
  103.     print("Tree has grown!!")
  104. end
  105.  
  106. function dispenserToggler()
  107.     rs.setBundledOutput("bottom", colors.gray)
  108.     sleep(0.5)
  109.     rs.setBundledOutput("bottom", 0)
  110. end
  111.  
  112. function digAndPlant(place)
  113.     while turtle.detect() do
  114.         turtle.dig()
  115.     end
  116.     if place == true then
  117.         turtle.select(2)
  118.         turtle.place()
  119.     end
  120. end
  121.  
  122. function plantSapling()
  123.     if turtle.getItemCount(2) < 4 then
  124.         fillResource("right", 1, 2, "sapling")
  125.     end
  126.    
  127.     --Primo sapling
  128.     while not turtle.forward() do
  129.         digAndPlant(false)
  130.     end
  131.     turtle.turnLeft()
  132.     digAndPlant(true)
  133.     turtle.turnRight()
  134.  
  135.     --Secondo sapling
  136.     while not turtle.forward() do
  137.         digAndPlant(false)
  138.     end
  139.     turtle.turnLeft()
  140.     digAndPlant(true)
  141.     turtle.turnRight()
  142.  
  143.     --Terzo sapling
  144.     while not turtle.back() do
  145.         turtle.turnLeft()
  146.         turtle.turnLeft()
  147.         digAndPlant(false)
  148.         turtle.turnRight()
  149.         turtle.turnRight()
  150.     end
  151.     digAndPlant(true)
  152.  
  153.     --Quarto sapling
  154.     while not turtle.back() do
  155.         turtle.turnLeft()
  156.         turtle.turnLeft()
  157.         digAndPlant(false)
  158.         turtle.turnRight()
  159.         turtle.turnRight()
  160.     end
  161.     digAndPlant(true)
  162. end
  163.  
  164. --abbatto l'albero e ripianto
  165. function chopTreeAndReplant()
  166.     dispenserToggler()
  167.     print("Chopping tree.") -- Taglia l'albero
  168.     turtle.dig()
  169.     sleep(7) -- aspetto che l'acqua rimuova le foglie
  170.     dispenserToggler()
  171.     sleep(3) --aspetto che l'acqua vada via
  172.     print("Planting sapling.") -- Ripianto il sapling
  173.     plantSapling()
  174. end
  175.  
  176. -- controlla il livello di carburante
  177. function checkFuel()
  178.     if turtle.getFuelLevel() < LOW_FUEL_THRESHOLD  then
  179.         if turtle.getItemCount(1) == 0 then
  180.             fillResource("left", 2, 1, "fuel")
  181.         else
  182.             turtle.select(1)
  183.             turtle.refuel()
  184.         end
  185.         print("Refueled")
  186.     end
  187. end
  188.  
  189. while true do
  190.     checkFuel()
  191.     if colors.test(rs.getBundledInput("bottom"), colors.green) then
  192.         print("Logs storage full.")
  193.         sleep(50)
  194.     else
  195.         if isWater() then
  196.             print("Water detected...")
  197.             dispenserToggler()
  198.             sleep(5)
  199.         end
  200.         if isLog() then
  201.             print("Chopping tree.")
  202.             chopTreeAndReplant()
  203.         elseif not isSapling() then
  204.             PLANTING_LOOP = PLANTING_LOOP + 1
  205.             print("Planting sapling try:" .. PLANTING_LOOP .. "/10")
  206.             plantSapling()
  207.             if PLANTING_LOOP >= 10 then
  208.                 PLANTING_LOOP = 0
  209.                 chopTreeAndReplant()
  210.             end
  211.         elseif isSapling() then
  212.             PLANTING_LOOP = 0
  213.             useBoneMeal()
  214.             print("Waiting....")
  215.         end
  216.     end
  217.     sleep(3)
  218. end
Advertisement
Add Comment
Please, Sign In to add comment