tommy2805

programma turtle tree chopper

Jun 5th, 2024 (edited)
492
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.70 KB | None | 0 0
  1. -- Soglia di carburante sotto la quale stampare un avviso
  2. local LOW_FUEL_THRESHOLD = 100
  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. function fillResource(direction, steps, slot, resource)
  25.     print("Filling UP " .. resource .. "...")
  26.     for i=1,3 do
  27.         turtle.back()
  28.     end
  29.     for i=1,steps do
  30.         if direction == "left" then
  31.             turtle.turnLeft()
  32.         else
  33.             turtle.turnRight()
  34.         end
  35.     end
  36.     turtle.select(slot)
  37.     turtle.suck(63)
  38.     if resource == "Sapling" or resource == "fuel" then
  39.         while turtle.getItemCount(slot) == 0 do
  40.             print("...")
  41.             sleep(15)
  42.             turtle.suck(63)
  43.         end
  44.     else
  45.         if turtle.getItemCount(slot) == 0 then
  46.             LAST_BONEMEAL_CHECK = 100;
  47.         end
  48.     end
  49.     for i=1,steps do
  50.         if direction == "left" then
  51.             turtle.turnRight()
  52.         else
  53.             turtle.turnLeft()
  54.         end
  55.     end
  56.     for i=1,3 do
  57.         turtle.forward()
  58.     end
  59.     print("Filled")
  60. end
  61.  
  62. function useBoneMeal()
  63.     print("Using bone meal...")
  64.     while not isLog() do
  65.         if turtle.getItemCount(3) == 0 then
  66.             if LAST_BONEMEAL_CHECK == 0 then
  67.                 fillResource("left",1,3,"BoneMeal")
  68.             else
  69.                 sleep(3)
  70.                 LAST_BONEMEAL_CHECK = LAST_BONEMEAL_CHECK - 1
  71.                 if LAST_BONEMEAL_CHECK % 10 == 0 then
  72.                     print("No bone meal new try " .. LAST_BONEMEAL_CHECK .. "/100")
  73.                 end
  74.             end
  75.         else
  76.             turtle.select(3)
  77.             turtle.place()
  78.             sleep(1)
  79.         end
  80.     end
  81.  
  82.     print("Tree has grown.")
  83. end
  84.  
  85. function dispenserToggler()
  86.     rs.setOutput("bottom",true)
  87.     sleep(0.5)
  88.     rs.setOutput("bottom",false)
  89. end
  90.  
  91. --abbatto l'albero e ripianto
  92. function chopTreeAndReplant()
  93.     dispenserToggler()
  94.     print("Chopping tree.") -- Taglia l'albero
  95.     turtle.dig()
  96.     sleep(5) -- aspetto che l'acqua rimuova le foglie
  97.     dispenserToggler()
  98.     sleep(3) --aspetto che l'acqua vada via
  99.     print("Planting sapling.") -- Ripianto il sapling
  100.     turtle.dig() --rimuove se ci sono delle foglie ritardate della immersive wheatering(mannaggia a chi l'ha programmata male)
  101.     turtle.dig()
  102.     turtle.select(2)
  103.     turtle.place()
  104. end
  105.  
  106. -- controlla il livello di carburante
  107. function checkFuel()
  108.     if turtle.getFuelLevel() < LOW_FUEL_THRESHOLD  then
  109.         if turtle.getItemCount(1) == 0 then
  110.             fillResource("left", 2, 1, "fuel")
  111.         end
  112.         turtle.select(1)
  113.         turtle.refuel()
  114.         print("Refueled")
  115.     end
  116. end
  117.  
  118. while true do
  119.     checkFuel()
  120.     if isLog() then
  121.         print("Chopping tree.")
  122.         chopTreeAndReplant()
  123.     elseif not isSapling() then
  124.         PLANTING_LOOP = PLANTING_LOOP + 1
  125.         print("Planting sapling try:" .. PLANTING_LOOP .. "/10")
  126.         if turtle.getItemCount(2) == 0 then
  127.             fillResource("right", 1, 2, "sapling")
  128.         end
  129.         turtle.select(2)
  130.         turtle.place()
  131.         if PLANTING_LOOP >= 10 then
  132.             PLANTING_LOOP = 0
  133.             chopTreeAndReplant()
  134.         end
  135.     elseif isSapling() then
  136.         PLANTING_LOOP = 0
  137.         useBoneMeal()
  138.         print("Waiting....")
  139.     end
  140.     sleep(3)
  141. end
Advertisement
Add Comment
Please, Sign In to add comment