Luke_Arwolf

Untitled

Apr 12th, 2026
7
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.00 KB | None | 0 0
  1. -- Configuração dos Slots
  2. local slotPicareta = 1
  3. local slotCarvao = 2
  4. local slotInicialBlocos = 3
  5.  
  6. -- Tenta equipar a picareta no lado esquerdo da Turtle
  7. turtle.select(slotPicareta)
  8. turtle.equipLeft()
  9.  
  10. -- Função para checar e abastecer o combustível
  11. local function refuelIfNeeded()
  12. -- Se o nível de combustível for menor que 10, ele consome 1 carvão
  13. if turtle.getFuelLevel() < 10 then
  14. turtle.select(slotCarvao)
  15. if turtle.getItemCount(slotCarvao) > 0 then
  16. turtle.refuel(1)
  17. else
  18. print("Aviso: Sem carvão no slot 2!")
  19. return false
  20. end
  21. end
  22. return true
  23. end
  24.  
  25. -- Função para encontrar o próximo slot que contenha blocos
  26. local function getNextBlockSlot()
  27. for i = slotInicialBlocos, 16 do
  28. if turtle.getItemCount(i) > 0 then
  29. return i
  30. end
  31. end
  32. return nil
  33. end
  34.  
  35. print("Iniciando rotina de colocar e quebrar blocos...")
  36.  
  37. -- Loop principal
  38. while true do
  39. -- Checa combustível; se acabar, o programa para
  40. if not refuelIfNeeded() then
  41. break
  42. end
  43.  
  44. -- Procura blocos nos slots de 3 a 16
  45. local blockSlot = getNextBlockSlot()
  46. if not blockSlot then
  47. print("Fim da rotina: Sem blocos para colocar (slots 3 a 16 estão vazios).")
  48. break
  49. end
  50.  
  51. -- Seleciona o slot com o bloco
  52. turtle.select(blockSlot)
  53.  
  54. -- Prevenção: Se já tiver um bloco na frente por algum erro, ela quebra primeiro
  55. if turtle.detect() then
  56. turtle.dig()
  57. end
  58.  
  59. -- Coloca o bloco na frente
  60. if turtle.place() then
  61. -- Um pequeno delay ajuda o servidor (ATM10 pode ter lag de block update)
  62. sleep(0.1)
  63.  
  64. -- Quebra o bloco que acabou de colocar
  65. turtle.dig()
  66. else
  67. print("Aviso: Não foi possível colocar o bloco. Algo está bloqueando a frente?")
  68. sleep(1) -- Pausa para não causar lag no servidor em caso de falha repetitiva
  69. end
  70. end
  71.  
  72. print("Programa finalizado.")
Add Comment
Please, Sign In to add comment