Advertisement
ironman2745

funtun_v3

Apr 2nd, 2024 (edited)
727
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.75 KB | None | 0 0
  1. require("turtleLib")
  2.  
  3. function scanInventoryForTorches()
  4.     local torchesPresent = false
  5.     local previousSlot = turtle.getSelectedSlot()
  6.     local torchesIndex = searchInventoryForItem("minecraft:torch")
  7.     if torchesIndex > -1 then
  8.         torchesPresent = true
  9.         turtle.select(torchesIndex)
  10.         turtle.transferTo(16)
  11.         turtle.select(previousSlot)
  12.     end
  13.     return torchesPresent
  14. end
  15.  
  16. function placeTorch()
  17.     if turtle.getItemDetail(16) ~= nil then
  18.         if turtle.getItemDetail(16).name == "minecraft:torch" then
  19.             turtle.turnLeft()
  20.             local previousSlot = turtle.getSelectedSlot()
  21.             turtle.select(16)
  22.             local placeTorchSuccess = turtle.place()
  23.             if placeTorchSuccess == false then
  24.                 goForward()
  25.                 local cobblestoneIndex = searchInventoryForItem("minecraft:cobblestone")
  26.                 if cobblestoneIndex>-1 then
  27.                     turtle.select(cobblestoneIndex)
  28.                     turtle.place()
  29.                 end
  30.                 turtle.turnRight()
  31.                 turtle.turnRight()
  32.                 goForward()
  33.                 turtle.turnLeft()
  34.                 turtle.turnLeft()
  35.                 turtle.select(16)
  36.                 turtle.place()
  37.             end
  38.             turtle.select(previousSlot)
  39.             turtle.turnRight()
  40.         end
  41.     end
  42. end
  43.  
  44. function level()
  45.     turtle.turnRight()
  46.     while turtle.detect() do
  47.         turtle.dig()
  48.         sleep(.5)
  49.     end
  50.     turtle.turnLeft()
  51.     turtle.turnLeft()
  52.     while turtle.detect() do
  53.         turtle.dig()
  54.         sleep(.5)
  55.     end
  56.     turtle.turnRight()
  57. end
  58.  
  59. function slice( withTorch )
  60.     goForward()
  61.     goUp()
  62.     level()
  63.     if withTorch==true then
  64.         placeTorch()
  65.     end
  66.     goDown()
  67.     level()
  68.     goDown()
  69.     level()
  70.     goUp()
  71. end
  72.  
  73. function inventoryFull( howFar, torches )
  74.     local lastSlot = 16
  75.     if torches then
  76.         lastSlot = 15
  77.     end
  78.  
  79.     if turtle.getItemCount(lastSlot) > 0 then
  80.         print("Inventory full. Returning home to dump items.")
  81.         turtle.turnRight()
  82.         turtle.turnRight()
  83.         for i=1,howFar do
  84.             goForward()
  85.         end
  86.         goDown()
  87.         for i=1,lastSlot do
  88.             turtle.select(i)
  89.             turtle.drop()
  90.         end
  91.         turtle.select(1)
  92.         goUp()
  93.         turtle.turnRight()
  94.         turtle.turnRight()
  95.         for i=1,howFar do
  96.             goForward()
  97.         end
  98.         print("Inventory dump complete. Resuming tunnel.")
  99.     end
  100. end
  101.  
  102. local arg = { ... }
  103. distance = arg[1]
  104. local tunnelDepth = 0
  105. local torches = scanInventoryForTorches()
  106. goUp()
  107. for i=1,distance do
  108.     if (i%5)==0 or i==1 then
  109.         slice(torches)
  110.     else
  111.         slice(false)
  112.     end
  113.     tunnelDepth = tunnelDepth + 1
  114.     print("Depth "..i.." of "..distance)
  115.     inventoryFull(tunnelDepth, torches)
  116. end
  117. -- End of tunnel. Turn around.
  118. turtle.turnRight()
  119. turtle.turnRight()
  120. -- Go back to start of tunnel
  121. for i=1,distance do
  122.     goForward()
  123. end
  124. -- drop remaining inventory [in chest?]
  125. goDown()
  126. for i=1,15 do
  127.     turtle.select(i)
  128.     turtle.drop()
  129. end
  130. turtle.select(1)
  131. -- Home position. Ideally in the exact same position the user started the program
  132. turtle.turnRight()
  133. turtle.turnRight()
  134. print("Tunnel Complete!")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement