Advertisement
ironman2745

funtun_v3

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