Advertisement
karelvysinka

Mining turtle 10x10x30 v2

Mar 14th, 2023 (edited)
723
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.12 KB | Gaming | 0 0
  1. local drahokamy = {
  2.     "minecraft:diamond",
  3.     "minecraft:emerald",
  4.     "minecraft:redstone",
  5.     "minecraft:lapis_lazuli",
  6.     "minecraft:gold_ore",
  7.     "minecraft:iron_ore"
  8. }
  9.  
  10. local function tableContains(table, element)
  11.     for _, value in pairs(table) do
  12.         if value == element then
  13.             return true
  14.         end
  15.     end
  16.     return false
  17. end
  18.  
  19. local function dig()
  20.     turtle.dig()
  21.     turtle.digUp()
  22.     turtle.digDown()
  23. end
  24.  
  25. local function moveDown()
  26.     while not turtle.down() do
  27.         turtle.digDown()
  28.     end
  29. end
  30.  
  31. local function moveUp()
  32.     while not turtle.up() do
  33.         turtle.digUp()
  34.     end
  35. end
  36.  
  37. local function emptyInventory()
  38.     for i = 1, 16 do
  39.         turtle.select(i)
  40.         local item = turtle.getItemDetail()
  41.         if item and not tableContains(drahokamy, item.name) then
  42.             turtle.drop()
  43.         end
  44.     end
  45. end
  46.  
  47. local function refuel()
  48.     for i = 1, 16 do
  49.         local fuelLevel = turtle.getFuelLevel()
  50.         if fuelLevel < 500 then
  51.             turtle.select(i)
  52.             turtle.refuel(1)
  53.         end
  54.     end
  55.     turtle.select(1)
  56. end
  57.  
  58. local function findChestAndEmptyInventory()
  59.     local chestFound = false
  60.     for y = 1, 10 do
  61.         if chestFound then
  62.             break
  63.         end
  64.         for x = 1, 10 do
  65.             local success, data = turtle.inspect()
  66.             if success and data.name == "minecraft:chest" then -- Opraveno: Opraven neukončený řetězec
  67.                 chestFound = true
  68.                 break
  69.             end
  70.             if x < 10 then
  71.                 turtle.forward()
  72.             end
  73.         end
  74.         if not chestFound and y % 2 == 0 then
  75.             turtle.turnRight()
  76.             turtle.forward()
  77.             turtle.turnRight()
  78.         elseif not chestFound and y % 2 == 1 then
  79.             turtle.turnLeft()
  80.             turtle.forward()
  81.             turtle.turnLeft()
  82.         end
  83.     end
  84.     if chestFound then
  85.         emptyInventory()
  86.         return true
  87.     else
  88.         turtle.turnRight()
  89.         turtle.turnRight()
  90.         for _ = 1, 10 do
  91.             turtle.forward()
  92.         end
  93.         turtle.turnLeft()
  94.         for _ = 1, 10 do
  95.             turtle.forward()
  96.         end
  97.         turtle.turnLeft()
  98.         return false
  99.     end
  100. end
  101.  
  102. local function mineTunnel()
  103.     for y = 1, 30 do
  104.         dig()
  105.         moveDown()
  106.         refuel()
  107.         if y % 10 == 0 then
  108.             local chestFound = findChestAndEmptyInventory()
  109.             if not chestFound then
  110.                 print("Nelze najít truhlu, ukončuji činnost.")
  111.                 return
  112.             end
  113.         end
  114.     end
  115.     for _ = 1, 30 do
  116.         moveUp()
  117.     end
  118. end
  119.  
  120. local function mineLayer()
  121.     for _ = 1, 10 do
  122.         mineTunnel()
  123.         if turtle.getFuelLevel() < 30 then
  124.             refuel()
  125.         end
  126.         if _ < 10 then
  127.             turtle.turnRight()
  128.             for _ = 1, 9 do
  129.                 turtle.forward()
  130.             end
  131.             turtle.turnRight()
  132.         end
  133.     end
  134. end
  135.  
  136. print("Zahajuji tezbu tunelu 10x10x30...")
  137. mineLayer()
  138. print("Tezba tunelu dokoncena.")
  139.  
  140.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement