Advertisement
RobinJut

mina25.lua

Apr 10th, 2025
348
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.47 KB | None | 0 0
  1. -- Tamaño del área a minar
  2. local width = 25
  3. local length = 25
  4. local height = 3
  5.  
  6. local progressFile = "progress.txt"
  7.  
  8. -- Obtener progreso guardado
  9. function loadProgress()
  10.     if fs.exists(progressFile) then
  11.         local file = fs.open(progressFile, "r")
  12.         local data = textutils.unserialize(file.readAll())
  13.         file.close()
  14.         return data.x, data.z
  15.     end
  16.     return 1, 1
  17. end
  18.  
  19. -- Guardar progreso actual
  20. function saveProgress(x, z)
  21.     local file = fs.open(progressFile, "w")
  22.     file.write(textutils.serialize({x = x, z = z}))
  23.     file.close()
  24. end
  25.  
  26. -- Verificar y recargar combustible si es necesario
  27. function checkFuel()
  28.     while turtle.getFuelLevel() < 100 do
  29.         for i = 1, 16 do
  30.             turtle.select(i)
  31.             if turtle.refuel(0) then
  32.                 turtle.refuel()
  33.             end
  34.         end
  35.  
  36.         if turtle.getFuelLevel() < 100 then
  37.             print("Pon carburante crack")
  38.             os.sleep(10)
  39.         end
  40.     end
  41. end
  42.  
  43. -- Minar la columna 3x1 (frente, arriba y abajo)
  44. function mineColumn()
  45.     turtle.digDown()
  46.     turtle.dig()
  47.     turtle.digUp()
  48. end
  49.  
  50. -- Mover hacia adelante asegurando cavado
  51. function smartForward()
  52.     while not turtle.forward() do
  53.         turtle.dig()
  54.     end
  55. end
  56.  
  57. -- Volver al inicio de la fila siguiente (zigzag)
  58. function turnToNextRow(z)
  59.     if z % 2 == 1 then
  60.         turtle.turnRight()
  61.         smartForward()
  62.         turtle.turnRight()
  63.     else
  64.         turtle.turnLeft()
  65.         smartForward()
  66.         turtle.turnLeft()
  67.     end
  68. end
  69.  
  70. -- Volver al inicio si se detuvo
  71. function returnToStart(x, z)
  72.     local facingEast = (z % 2 == 1)
  73.     if not facingEast then
  74.         turtle.turnLeft()
  75.         turtle.turnLeft()
  76.     end
  77.     for i = 1, x - 1 do
  78.         smartForward()
  79.     end
  80.     turtle.turnRight()
  81.     for i = 1, z - 1 do
  82.         smartForward()
  83.     end
  84.     turtle.turnLeft()
  85. end
  86.  
  87. -- Main loop
  88. function mineArea()
  89.     local startX, startZ = loadProgress()
  90.     returnToStart(startX, startZ)
  91.  
  92.     for z = startZ, length do
  93.         for x = startX, width do
  94.             checkFuel()
  95.             mineColumn()
  96.             if x < width then
  97.                 smartForward()
  98.             end
  99.             saveProgress(x, z)
  100.         end
  101.  
  102.         if z < length then
  103.             turnToNextRow(z)
  104.         end
  105.  
  106.         startX = 1 -- Para nuevas filas, empezar desde el inicio
  107.     end
  108.  
  109.     print("Minería completada.")
  110.     fs.delete(progressFile)
  111. end
  112.  
  113. mineArea()
  114.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement