Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require("turtleLib")
- function scanInventoryForTorches()
- local torchesPresent = false
- local previousSlot = turtle.getSelectedSlot()
- local torchesIndex = searchInventoryForItem("minecraft:torch")
- if torchesIndex > -1 then
- torchesPresent = true
- turtle.select(torchesIndex)
- turtle.transferTo(16)
- turtle.select(previousSlot)
- end
- return torchesPresent
- end
- function placeTorch()
- if turtle.getItemDetail(16) ~= nil then
- if turtle.getItemDetail(16).name == "minecraft:torch" then
- turtle.turnLeft()
- local previousSlot = turtle.getSelectedSlot()
- turtle.select(16)
- local placeTorchSuccess = turtle.place()
- if placeTorchSuccess == false then
- goForward()
- local cobblestoneIndex = searchInventoryForItem("minecraft:cobblestone")
- if cobblestoneIndex>-1 then
- turtle.select(cobblestoneIndex)
- turtle.place()
- end
- turtle.turnRight()
- turtle.turnRight()
- goForward()
- turtle.turnLeft()
- turtle.turnLeft()
- turtle.select(16)
- turtle.place()
- end
- turtle.select(previousSlot)
- turtle.turnRight()
- end
- end
- end
- function level()
- turtle.turnRight()
- while turtle.detect() do
- turtle.dig()
- sleep(.5)
- end
- turtle.turnLeft()
- turtle.turnLeft()
- while turtle.detect() do
- turtle.dig()
- sleep(.5)
- end
- turtle.turnRight()
- end
- function slice( withTorch )
- goForward()
- goUp()
- level()
- if withTorch==true then
- placeTorch()
- end
- goDown()
- level()
- goDown()
- level()
- goUp()
- end
- function inventoryFull( howFar, torches )
- local lastSlot = 16
- if torches then
- lastSlot = 15
- end
- if turtle.getItemCount(lastSlot) > 0 then
- print("Inventory full. Returning home to dump items.")
- turtle.turnRight()
- turtle.turnRight()
- for i=1,howFar do
- goForward()
- end
- goDown()
- for i=1,lastSlot do
- turtle.select(i)
- turtle.drop()
- end
- turtle.select(1)
- goUp()
- turtle.turnRight()
- turtle.turnRight()
- for i=1,howFar do
- goForward()
- end
- print("Inventory dump complete. Resuming tunnel.")
- end
- end
- local arg = { ... }
- distance = arg[1]
- local tunnelDepth = 0
- local torches = scanInventoryForTorches()
- goUp()
- for i=1,distance do
- if (i%5)==0 or i==1 then
- slice(torches)
- else
- slice(false)
- end
- tunnelDepth = tunnelDepth + 1
- print("Depth "..i.." of "..distance)
- inventoryFull(tunnelDepth, torches)
- end
- -- End of tunnel. Turn around.
- turtle.turnRight()
- turtle.turnRight()
- -- Go back to start of tunnel
- for i=1,distance do
- goForward()
- end
- -- drop remaining inventory [in chest?]
- goDown()
- for i=1,15 do
- turtle.select(i)
- turtle.drop()
- end
- turtle.select(1)
- -- Home position. Ideally in the exact same position the user started the program
- turtle.turnRight()
- turtle.turnRight()
- print("Tunnel Complete!")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement