Advertisement
HappySunChild

Tunnel

Sep 11th, 2021 (edited)
216
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.38 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:torch" --  so it doesnt drop torches its supposed to place
  20. }
  21.  
  22. local function hasEnoughFuel()
  23.     local requiredFuel = MineDistance*2
  24.     local currentFuel = turtle.getFuelLevel()
  25.  
  26.     if currentFuel < requiredFuel then
  27.         term.write("Not enough fuel!")
  28.         shell.run("refuel","all")
  29.         return false
  30.     else
  31.         return true
  32.     end
  33. end
  34.  
  35. local function forward()
  36.     while turtle.forward() == false do
  37.         turtle.dig()
  38.     end
  39. end
  40.  
  41. local function inventoryCheck()
  42.     for i = 1,16 do
  43.         local item = turtle.getItemDetail(i)
  44.         if item then
  45.             local a = false
  46.             for x = 1,#ITEMS do
  47.                 if item.name == ITEMS[x] then
  48.                     a = true
  49.                     break
  50.                 end
  51.             end
  52.             if not a then
  53.                 turtle.select(i)
  54.                 turtle.drop()
  55.             end
  56.         end
  57.     end
  58. end
  59.  
  60. local function getTorchSlot()
  61.     for i = 1,16 do
  62.         local item = turtle.getItemDetail(i)
  63.         if item then
  64.             if item.name == "minecraft:torch" then
  65.                 return i
  66.             end
  67.         end
  68.     end
  69.     return false
  70. end
  71.  
  72. local function tunnel()
  73.     for i = 0,MineDistance-1 do
  74.         forward()
  75.         turtle.digDown()
  76.         turtle.digUp()
  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.     rednet.broadcast("loaded")
  98.     tunnel()
  99. else
  100.     rednet.broadcast(" 104; not enough fuel")
  101. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement