MathisFlaw

turtle_querry

Nov 14th, 2025 (edited)
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 7.74 KB | None | 0 0
  1. --[[
  2. Script de Carrière 16x16 - V5 - "Blindé"
  3. MÉTHODE: Puits Verticaux (le plus fiable pour les serveurs)
  4.  
  5. *** MODIFIÉ : S'arrête à 16 blocs de profondeur ***
  6.  
  7. - Gère l'inventaire plein et retourne au coffre.
  8. - Placement: Coffre DERRIÈRE la tortue. Carburant en slot 16.
  9. ]]
  10.  
  11. -- ## CONFIGURATION ##
  12. local QUARRY_WIDTH = 16
  13. local QUARRY_LENGTH = 16
  14. local FUEL_SLOT = 16
  15. local MAX_DEPTH = 16   -- <<< TA VARIABLE GLOBALE EST ICI
  16. -------------------------
  17.  
  18. -- Variables d'état (où la tortue PENSE être)
  19. local state = {
  20.     x = 0,
  21.     z = 0,
  22.     y = 0,
  23.     dirZ = 1 -- 1 pour Z+, -1 pour Z-
  24. }
  25.  
  26. ---
  27. -- FONCTIONS "INSISTANTES" (Anti-Lag)
  28. ---
  29. function insistForward()
  30.     while not turtle.forward() do
  31.         print("Mouvement bloqué (lag?), nouvelle tentative...")
  32.         os.sleep(0.1)
  33.     end
  34. end
  35. function insistUp()
  36.     while not turtle.up() do
  37.         print("Montée bloquée (lag?), nouvelle tentative...")
  38.         os.sleep(0.1)
  39.     end
  40. end
  41. function insistDown()
  42.     while not turtle.down() do
  43.         print("Descente bloquée (lag?), nouvelle tentative...")
  44.         os.sleep(0.1)
  45.     end
  46. end
  47. function insistTurnRight()
  48.     while not turtle.turnRight() do os.sleep(0.1) end
  49. end
  50. function insistTurnLeft()
  51.     while not turtle.turnLeft() do os.sleep(0.1) end
  52. end
  53.  
  54. ---
  55. -- FONCTIONS "SÉCURISÉES" (Anti-Obstacles)
  56. ---
  57. function checkFuel()
  58.     turtle.select(FUEL_SLOT)
  59.     if turtle.getFuelLevel() < 10 then
  60.         if not turtle.refuel(1) then
  61.             if turtle.getFuelLevel() < 10 then
  62.                 print("!! ERREUR: Plus de carburant")
  63.                 return false
  64.             end
  65.         end
  66.         print("Ravitaillement.")
  67.     end
  68.     turtle.select(1)
  69.     return true
  70. end
  71.  
  72. function safeDigUp()
  73.     local hasBlock, data = turtle.inspectUp()
  74.     if hasBlock then
  75.         while not turtle.digUp() do
  76.             print("Bloc au-dessus bloqué (gravier?)...")
  77.             os.sleep(0.1)
  78.         end
  79.     end
  80. end
  81.  
  82. function safeDigDown()
  83.     local hasBlock, data = turtle.inspectDown()
  84.     if not hasBlock then return true end -- Air
  85.    
  86.     if data.name == "minecraft:bedrock" then
  87.         print("Bedrock atteinte.")
  88.         return false -- STOP
  89.     end
  90.    
  91.     while not turtle.digDown() do
  92.         print("Bloc en dessous bloqué...")
  93.         os.sleep(0.1)
  94.         local s, d = turtle.inspectDown()
  95.         if not s or d.name == "minecraft:bedrock" then
  96.             return false
  97.         end
  98.     end
  99.    
  100.     return true -- A réussi à creuser
  101. end
  102.  
  103. ---
  104. -- GESTION DE L'INVENTAIRE
  105. ---
  106. function isInventoryFull()
  107.     for i = 1, (FUEL_SLOT - 1) do
  108.         if turtle.getItemCount(i) == 0 then
  109.             return false
  110.         end
  111.     end
  112.     print("Inventaire plein.")
  113.     return true
  114. end
  115.  
  116. function dumpInventory()
  117.     print("Vidage de l'inventaire...")
  118.     insistTurnRight()
  119.     insistTurnRight() -- Face au coffre
  120.    
  121.     for i = 1, (FUEL_SLOT - 1) do
  122.         turtle.select(i)
  123.         turtle.drop()
  124.     end
  125.    
  126.     turtle.select(1)
  127.     insistTurnRight()
  128.     insistTurnRight() -- Face à la carrière
  129.     print("Vidage terminé.")
  130. end
  131.  
  132. function checkAndDump()
  133.     if not isInventoryFull() then
  134.         return true -- Pas plein, on continue
  135.     end
  136.    
  137.     print("Inventaire plein, retour à la base...")
  138.    
  139.     -- 1. Remonter à la surface (Y=0)
  140.     while state.y > 0 do
  141.         if not checkFuel() then return false end
  142.         safeDigUp()
  143.         insistUp()
  144.         state.y = state.y - 1
  145.     end
  146.    
  147.     -- 2. Revenir au début de la rangée (Z=0)
  148.     if state.dirZ == 1 then
  149.         insistTurnRight()
  150.         insistTurnRight()
  151.         for i = 1, state.z do
  152.             if not checkFuel() then return false end
  153.             insistForward()
  154.         end
  155.         insistTurnRight()
  156.     else
  157.         for i = 1, (QUARRY_LENGTH - 1) - state.z do
  158.             if not checkFuel() then return false end
  159.             insistForward()
  160.         end
  161.         insistTurnLeft()
  162.     end
  163.    
  164.     -- 3. Revenir au début de la carrière (X=0)
  165.     for i = 1, state.x do
  166.         if not checkFuel() then return false end
  167.         insistForward()
  168.     end
  169.    
  170.     -- 4. Se mettre en position de vidage (face Z-)
  171.     insistTurnLeft()
  172.     insistTurnLeft()
  173.     insistTurnLeft()
  174.    
  175.     -- 5. Vider
  176.     dumpInventory() -- Se remet face à Z+
  177.    
  178.     -- 6. Retourner à la bonne rangée (X)
  179.     insistTurnRight()
  180.     for i = 1, state.x do
  181.         if not checkFuel() then return false end
  182.         insistForward()
  183.     end
  184.    
  185.     -- 7. Se mettre dans la bonne direction (Z)
  186.     if state.dirZ == 1 then
  187.         insistTurnLeft()
  188.     else
  189.         insistTurnRight()
  190.     end
  191.    
  192.     -- 8. Revenir au bon Z
  193.     for i = 1, state.z do
  194.         if not checkFuel() then return false end
  195.         insistForward()
  196.     end
  197.    
  198.     -- 9. Redescendre
  199.     print("Retour au travail...")
  200.     for i = 1, state.y do
  201.         if not checkFuel() then return false end
  202.         insistDown()
  203.     end
  204.    
  205.     print("Reprise du minage.")
  206.     return true
  207. end
  208.  
  209. ---
  210. -- Logique de minage (MODIFIÉE ICI)
  211. ---
  212. function digShaft()
  213.     print(string.format("Minage du puits : (X=%d, Z=%d)", state.x, state.z))
  214.    
  215.     while true do -- Boucle de descente
  216.         if not checkFuel() then return false end
  217.        
  218.         if not checkAndDump() then return false end
  219.        
  220.         -- ### MODIFICATION ICI ###
  221.         -- Vérifie si la profondeur actuelle (state.y)
  222.         -- a atteint ou dépassé la limite
  223.         if state.y >= MAX_DEPTH then
  224.             print("Profondeur max (" .. MAX_DEPTH .. ") atteinte.")
  225.             break -- Arrête de creuser ce puits
  226.         end
  227.         -- ### FIN DE LA MODIFICATION ###
  228.        
  229.         -- Creuse
  230.         if not safeDigDown() then
  231.             break -- Bedrock atteinte
  232.         end
  233.        
  234.         -- Descend
  235.         insistDown()
  236.         state.y = state.y + 1
  237.     end
  238.    
  239.     -- Remonte à la surface (Y=0)
  240.     print("Puits terminé, remontée...")
  241.     while state.y > 0 do
  242.         if not checkFuel() then return false end
  243.         safeDigUp()
  244.         insistUp()
  245.         state.y = state.y - 1
  246.     end
  247.    
  248.     return true -- Puits terminé avec succès
  249. end
  250.  
  251. ---
  252. -- Logique principale
  253. ---
  254. function runQuarry()
  255.     for x = 0, (QUARRY_WIDTH - 1) do
  256.         state.x = x
  257.        
  258.         for z_iter = 0, (QUARRY_LENGTH - 1) do
  259.            
  260.             if not digShaft() then
  261.                 print("Arrêt dû au carburant ou erreur grave.")
  262.                 return
  263.             end
  264.            
  265.             if z_iter < (QUARRY_LENGTH - 1) then
  266.                 if not checkFuel() then return false end
  267.                 insistForward()
  268.                 state.z = state.z + state.dirZ
  269.             end
  270.         end
  271.        
  272.         if state.x < (QUARRY_WIDTH - 1) then
  273.             print("Changement de rangée...")
  274.             if state.dirZ == 1 then
  275.                 insistTurnRight()
  276.                 if not checkFuel() then return false end
  277.                 insistForward()
  278.                 insistTurnRight()
  279.             else
  280.                 insistTurnLeft()
  281.                 if not checkFuel() then return false end
  282.                 insistForward()
  283.                 insistTurnLeft()
  284.             end
  285.             state.dirZ = state.dirZ * -1
  286.             state.z = state.z + state.dirZ
  287.         end
  288.     end
  289.    
  290.     print("--- CARRIÈRE TERMINÉE (V5 - Prof 16) ---")
  291.     print("Retour au point de départ...")
  292.     if state.dirZ == -1 then
  293.         insistTurnRight()
  294.         insistTurnRight()
  295.     end
  296.     for i = 1, state.z do insistForward() end
  297.    
  298.     insistTurnLeft()
  299.     for i = 1, state.x do insistForward() end
  300.    
  301.     insistTurnLeft()
  302.     dumpInventory()
  303.     print("C'est fini !")
  304. end
  305.  
  306. -- Lancement du script
  307. runQuarry()
Advertisement
Add Comment
Please, Sign In to add comment