Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Arguements and Arg Checking
- local tArgs = { ... }
- if #tArgs ~= 1 then
- print( "Usage: tunnel <length>" )
- return
- end
- local length = tonumber( tArgs[1] )
- if length < 1 then
- print( "Tunnel length must be positive" )
- return
- end
- -- Collected block number / Increaser
- local collected = 0
- local function collect()
- collected = collected + 1
- if math.fmod(collected, 25) == 0 then
- print( "Mined "..collected.." blocks." )
- end
- end
- -- Digging functions
- local function tryDig()
- while turtle.dig() do
- collect()
- sleep(0.5)
- if not turtle.detect() then
- return true
- end
- end
- return not turtle.detect()
- end
- local function tryDigUp()
- while turtle.digUp() do
- collect()
- sleep(0.5)
- if not turtle.detectUp() then
- return true
- end
- end
- return not turtle.detectUp()
- end
- -- Functions for dropping off items into a chest from slot 1.
- local function depositChest()
- turtle.up()
- turtle.turnRight()
- turtle.forward()
- turtle.select(1)
- turtle.placeDown()
- sleep(0.5)
- for slot=4,16 do
- turtle.select(slot)
- turtle.dropDown(turtle.getItemCount(slot))
- sleep(0.5)
- end
- turtle.select(1)
- end
- local function previousState()
- turtle.turnLeft()
- sleep(0.5)
- turtle.turnLeft()
- sleep(0.5)
- turtle.forward()
- sleep(0.5)
- turtle.down()
- sleep(0.5)
- turtle.turnRight()
- end
- local function checkSpace()
- local space = 0
- for slot=3,16 do
- if turtle.getItemCount(slot) == 0 then
- space = space + 1
- end
- --space = space + (turtle.getItemCount(slot)>0)
- end
- if space == 0 then
- depositChest()
- previousState()
- return false
- else
- return true
- end
- end
- -- Main Program for digging the tunnel
- print( "Tunnelling..." )
- for n=1,length do
- tryDig()
- if not turtle.forward() then
- print( "Aborting Tunnel." )
- break
- end
- turtle.select(2)
- turtle.placeDown()
- --if not checkSpace() then break end
- tryDigUp()
- turtle.turnLeft()
- tryDig()
- turtle.up()
- tryDig()
- tryDigUp()
- turtle.up()
- tryDig()
- turtle.turnRight()
- turtle.turnRight()
- tryDig()
- turtle.down()
- tryDig()
- if (n%7 == 6) then
- turtle.select(3)
- if (turtle.getItemDetail().name == "minecraft:torch") then
- turtle.place()
- end
- turtle.select(2)
- end
- turtle.down()
- tryDig()
- turtle.turnLeft()
- checkSpace()
- if (n == length) then
- print( "Tunnel complete!")
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement