Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --{program="Tunneler",version="1.1",date="19.10.2021"}
- ---------------------------------------
- -- 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()
- if not turtle.detect() then
- return true
- end
- end
- return not turtle.detect()
- end
- local function tryDigUp()
- while turtle.digUp() do
- collect()
- 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()
- for slot=2,16 do
- turtle.select(slot)
- turtle.dropDown(turtle.getItemCount(slot))
- end
- turtle.select(1)
- end
- local function previousState()
- turtle.turnLeft()
- turtle.turnLeft()
- turtle.forward()
- turtle.down()
- turtle.turnRight()
- end
- local function checkSpace()
- local space = 0
- for slot=2,16 do
- space = space + turtle.getItemSpace(slot)
- end
- if space == 0 then
- depositChest()
- previousState()
- return false
- else
- return true
- end
- end
- -- Main Program for digging the tunnel
- write( "Tunnelling 4 block high" )
- for n=1,length do
- write(".")
- turtle.select(2)
- turtle.placeDown()
- if not checkSpace() then break end
- tryDigUp()
- turtle.turnLeft()
- tryDig()
- turtle.up()
- tryDig()
- tryDigUp()
- turtle.up()
- tryDig()
- tryDigUp()
- turtle.up()
- tryDig()
- turtle.turnRight()
- turtle.turnRight()
- tryDig()
- turtle.down()
- tryDig()
- turtle.down()
- tryDig()
- turtle.down()
- tryDig()
- turtle.turnLeft()
- if n<length then
- tryDig()
- if not turtle.forward() then
- print( "Aborting Tunnel." )
- break
- end
- else
- print( "Tunnel complete." )
- end
- end
Add Comment
Please, Sign In to add comment