Advertisement
HappySunChild

LowTunnel

Mar 8th, 2022
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.28 KB | None | 0 0
  1. local args = {...}
  2.  
  3. local MineDistance = args[1] or 1 --     How far the turtle will tunnel
  4. local TorchFrequency = args[2] or 10 --  How often the turtle will place torches
  5. local ICheckFrequency = args[3] or 10 -- How often the turtle will empty it's inventory
  6.  
  7. local ITEMS = { --   whitelist
  8.     "minecraft:coal",
  9.     "minecraft:iron_ore",
  10.     "minecraft:gold_ore",
  11.     "minecraft:diamond",
  12.     "minecraft:emerald",
  13.     "minecraft:lapis_lazuli",
  14.     "minecraft:redstone",
  15.     "create:copper_ore",
  16.     "create:zinc_ore",
  17.     "minecraft:ancient_debris",
  18.     "minecraft:quartz",
  19.     "minecraft:nether_bricks",
  20.     "minecraft:torch" --  so it doesnt drop torches its supposed to place
  21. }
  22.  
  23. function hasEnoughFuel()
  24.     local requiredFuel = MineDistance*2
  25.     local currentFuel = turtle.getFuelLevel()
  26.  
  27.     if currentFuel < requiredFuel then
  28.         term.write("Not enough fuel!")
  29.         shell.run("refuel","all")
  30.         return false
  31.     else
  32.         return true
  33.     end
  34. end
  35.  
  36. function forward()
  37.     while turtle.forward() == false do
  38.         turtle.dig()
  39.     end
  40. end
  41.  
  42. function inventoryCheck()
  43.     for i = 1,16 do
  44.         local item = turtle.getItemDetail(i)
  45.         if item then
  46.             local a = false
  47.             for x = 1,#ITEMS do
  48.                 if item.name == ITEMS[x] then
  49.                     a = true
  50.                     break
  51.                 end
  52.             end
  53.             if not a then
  54.                 turtle.select(i)
  55.                 turtle.drop()
  56.             end
  57.         end
  58.     end
  59. end
  60.  
  61. function getTorchSlot()
  62.     for i = 1,16 do
  63.         local item = turtle.getItemDetail(i)
  64.         if item then
  65.             if item.name == "minecraft:torch" then
  66.                 return i
  67.             end
  68.         end
  69.     end
  70.     return false
  71. end
  72.  
  73. function tunnel()
  74.     for i = 0,MineDistance-1 do
  75.         forward()
  76.         turtle.digDown()
  77.  
  78.         if i % TorchFrequency == 0 then
  79.             local s = getTorchSlot()
  80.             if s then
  81.                 turtle.select(s)
  82.                 turtle.placeDown()
  83.             end
  84.         end
  85.  
  86.         if i % ICheckFrequency == 0 then
  87.             inventoryCheck()
  88.         end
  89.     end
  90.  
  91.     for i = 0,MineDistance-1 do
  92.         turtle.back()
  93.     end
  94. end
  95.  
  96. if hasEnoughFuel() then
  97.     tunnel()
  98. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement