Advertisement
Bibodui

turtle tunnel

Feb 12th, 2025
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.88 KB | Gaming | 0 0
  1. local dangerBlocks = {"minecraft:lava", "minecraft:flowing_lava", "minecraft:water", "minecraft:flowing_water"}
  2.  
  3. local function isDangerous()
  4.     local success, data = turtle.inspect()
  5.     if success then
  6.         for _, block in ipairs(dangerBlocks) do
  7.             if data.name == block then
  8.                 return true
  9.             end
  10.         end
  11.     end
  12.     return false
  13. end
  14.  
  15. local function dig()
  16.     while turtle.detect() do
  17.         if isDangerous() then
  18.             print("Обнаружен опасный блок! Остановка копания.")
  19.             return false
  20.         end
  21.         turtle.dig()
  22.     end
  23.     return true
  24. end
  25.  
  26. local function digUp()
  27.     while turtle.detectUp() do
  28.         turtle.digUp()
  29.     end
  30. end
  31.  
  32. local function digDown()
  33.     while turtle.detectDown() do
  34.         turtle.digDown()
  35.     end
  36. end
  37.  
  38. local function isInventoryFull()
  39.     for i = 1, 16 do
  40.         if turtle.getItemCount(i) == 0 then
  41.             return false
  42.         end
  43.     end
  44.     return true
  45. end
  46.  
  47. local function returnToChest(steps)
  48.     for i = 1, steps do
  49.         turtle.back()
  50.     end
  51.     turtle.turnLeft()
  52.     turtle.turnLeft()
  53.     for i = 1, 16 do
  54.         turtle.select(i)
  55.         turtle.drop()
  56.     end
  57.     turtle.turnLeft()
  58.     turtle.turnLeft()
  59.     turtle.select(1)
  60.     for i = 1, steps do
  61.         turtle.forward()
  62.     end
  63. end
  64.  
  65. local function tunnel(length)
  66.     for i = 1, length do
  67.         if not dig() then return end
  68.         turtle.forward()
  69.         digUp()
  70.         digDown()
  71.  
  72.         if isInventoryFull() then
  73.             print("Инвентарь полон, возвращение к сундуку.")
  74.             returnToChest(i)
  75.         end
  76.     end
  77. end
  78.  
  79. print("Введите длину туннеля:")
  80. local length = tonumber(read())
  81. if length then
  82.     tunnel(length)
  83. else
  84.     print("Ошибка ввода длины.")
  85. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement