Advertisement
Vorakh

Coltivare v.2

May 18th, 2025 (edited)
487
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.16 KB | None | 0 0
  1.  
  2. local function farm_avanti()
  3.     --print('Avanti')
  4.     for i = 0, 9 do
  5.         turtle.forward()
  6.         local successo, data = turtle.inspectDown()
  7.         if successo then
  8.             if  data.state.age == 7 then
  9.                 turtle.digDown()
  10.                 turtle.placeDown()
  11.             end
  12.         elseif turtle.placeDown() then
  13.  
  14.         end
  15.     end
  16. end
  17.  
  18. local function gira_sx()
  19.     --print('Gira Sinistra')
  20.     turtle.turnLeft()
  21.     turtle.forward()
  22.     turtle.turnLeft()
  23. end
  24.  
  25. local function gira_dx()
  26.     --print('Gira Destra')
  27.     turtle.turnRight()
  28.     turtle.forward()
  29.     turtle.turnRight()
  30. end
  31.  
  32. local function torna_base()
  33.     --print('Torna alla base')
  34.     for i = 1, 10 do
  35.         turtle.forward()
  36.     end
  37.     turtle.turnLeft()
  38.     for i = 1, 9 do
  39.         turtle.forward()
  40.     end
  41.     turtle.turnLeft()
  42. end
  43.  
  44. -- Funzione che controlla se l'inventario della turtle è pieno
  45. function inventarioPieno()
  46.     for slot = 1, 16 do
  47.         if turtle.getItemCount(slot) == 0 then
  48.             return false -- C'è almeno uno slot vuoto
  49.         end
  50.     end
  51.     return true -- Tutti gli slot sono pieni
  52. end
  53.  
  54.  
  55. local function gestione_inventario()
  56.     -- Svuota e ricarica le patate
  57.     for slot = 1, 16 do
  58.         turtle.select(slot)
  59.         turtle.dropDown()
  60.        
  61.     end
  62.     turtle.select(1)
  63.     turtle.suckDown(64)
  64.    
  65. end
  66.  
  67. local function gestione_carburante()
  68.     -- Da implementrare
  69. end
  70.  
  71. ---------------------------------------
  72. -- Programma turtle coltivazione v.2 --
  73. ---------------------------------------
  74. print("Farm automatica Patate")
  75.  
  76. while true do
  77.     gestione_inventario()
  78.     if inventarioPieno() then
  79.         print('Sia la cassa che la Turtle sono piene, fare spazio per riprendere la raccolta')
  80.         print('Turtle in attesa...')
  81.     else
  82.         for i = 1, 9 do
  83.         --print('i:'..i)
  84.         if (i%2) == 1 then
  85.             farm_avanti()
  86.             gira_sx()
  87.         else
  88.             farm_avanti()
  89.             gira_dx()
  90.         end
  91.     end
  92.     torna_base()
  93.  
  94.     print('Finito un ciclo di Raccolta, in attesa di ricrescita prima di iniziare il successivo')
  95.     end
  96.     sleep(60)
  97. end
  98.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement