Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local tpos = require("TurtlePosition")
- local tctl = require("TurtleControl")
- function scanInventoryForTorches()
- local torchesPresent = false
- local previousSlot = turtle.getSelectedSlot()
- local torchesIndex = tctl.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
- tctl.turnLeft()
- local previousSlot = turtle.getSelectedSlot()
- turtle.select(16)
- local placeTorchSuccess = turtle.place()
- if placeTorchSuccess == false then
- tctl.forward()
- local cobblestoneIndex = searchInventoryForItem("minecraft:cobblestone")
- if cobblestoneIndex>-1 then
- turtle.select(cobblestoneIndex)
- turtle.place()
- end
- tctl.turnRight()
- tctl.turnRight()
- tctl.forward()
- tctl.turnLeft()
- tctl.turnLeft()
- turtle.select(16)
- turtle.place()
- end
- turtle.select(previousSlot)
- tctl.turnRight()
- end
- end
- end
- function level()
- tctl.turnRight()
- while turtle.detect() do
- turtle.dig()
- sleep(.5)
- end
- tctl.turnLeft()
- tctl.turnLeft()
- while turtle.detect() do
- turtle.dig()
- sleep(.5)
- end
- tctl.turnRight()
- end
- function slice( withTorch )
- tctl.forward()
- tctl.up()
- level()
- if withTorch==true then
- placeTorch()
- end
- tctl.down()
- level()
- tctl.down()
- level()
- tctl.up()
- end
- function inventoryFull( howFar, torches )
- local lastSlot = 16
- local excludeSlots = {}
- if torches then
- lastSlot = 15
- excludeSlots = {16}
- end
- if turtle.getItemCount(lastSlot) > 0 then
- tctl.print("Inventory full. Returning home to dump items.")
- tctl.turnRight()
- tctl.turnRight()
- for i=1,howFar do
- tctl.forward()
- end
- tctl.down()
- tctl.emptyInventory(excludeSlots)
- tctl.up()
- tctl.turnRight()
- tctl.turnRight()
- for i=1,howFar do
- tctl.forward()
- end
- tctl.print("Inventory dump complete. Resuming tunnel.")
- end
- end
- local arg = { ... }
- distance = arg[1]
- local tunnelDepth = 0
- local torches = scanInventoryForTorches()
- tctl.up()
- for i=1,distance do
- if (i%5)==0 or i==1 then
- slice(torches)
- else
- slice(false)
- end
- tunnelDepth = tunnelDepth + 1
- tctl.print("Depth "..i.." of "..distance)
- inventoryFull(tunnelDepth, torches)
- end
- -- End of tunnel. Turn around.
- tctl.turnRight()
- tctl.turnRight()
- -- Go back to start of tunnel
- for i=1,distance do
- tctl.forward()
- end
- -- drop remaining inventory [in chest?]
- tctl.down()
- 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
- tctl.turnRight()
- tctl.turnRight()
- tctl.print("Tunnel Complete!")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement