Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local tArgs = { ... }
- if #tArgs ~= 3 then
- print( "Usage: <program> <far> <dump> <stop>" )
- return
- end
- -- Mine in a one-wide pattern until we hit something we can't dig
- local size = tonumber( tArgs[1] )
- local gDump = tonumber( tArgs[2] )
- local tStop = tonumber( tArgs[3] )
- if size < 1 then
- print( "Excavate outward must be positive" )
- return
- end
- if tStop < 1 then
- tStop = 57
- end
- if gDump < 1 then
- gDump = 1
- end
- local depth = 0
- local collected = 0
- local swap = 1
- local aDump = 0
- local cPos = 0
- local function dump()
- for i=1, gDump do
- turtle.back()
- end
- turtle.turnLeft()
- turtle.turnLeft()
- turtle.select(1)
- turtle.drop()
- turtle.select(2)
- turtle.drop()
- turtle.select(3)
- turtle.drop()
- turtle.select(4)
- turtle.drop()
- turtle.select(5)
- turtle.drop()
- turtle.select(6)
- turtle.drop()
- turtle.select(7)
- turtle.drop()
- turtle.select(8)
- turtle.drop()
- turtle.select(9)
- turtle.drop()
- turtle.select(1)
- for i=1, gDump do
- turtle.back()
- end
- turtle.turnLeft()
- turtle.turnLeft()
- end
- local function collect()
- print( "Collect Called" )
- collected = collected + 1
- if math.fmod(collected, 25) == 0 then
- print( "Mined "..collected.." blocks." )
- end
- for n=1,9 do
- if turtle.getItemCount(n) == 0 then
- return true
- end
- end
- print( "No empty slots left." )
- return false
- end
- local function tryPush()
- if not turtle.forward() then
- if turtle.dig() then
- if not collect() then
- return false
- end
- else
- -- give sand a chance to fall
- sleep(0.8)
- if turtle.dig() then
- if not collect() then
- return false
- end
- else
- return false
- end
- end
- end
- return true
- end
- local function tryDown()
- print (" Down Called ")
- if not turtle.down() then
- print (" Can't move down, trying dig... ")
- if turtle.digDown() then
- if not collect() then
- print (" Can't collect down, oddly. ")
- return false
- end
- end
- if not turtle.down() then
- print (" Can't move down, oddly. ")
- return false
- end
- end
- if math.fmod( depth, 10 ) == 0 then
- print( "Descended "..depth.." metres." )
- end
- return true
- end
- local function goHome()
- print( " Coming Home... " )
- for i=depth, 0, -1 do
- depth = i
- turtle.up()
- end
- if swap > 0 then
- turtle.turnLeft()
- turtle.turnLeft()
- swap = -1
- end
- for i=cPos, 0, -1 do
- turtle.forward()
- cPos = i
- end
- print ( "Now Home" )
- turtle.turnLeft()
- turtle.turnLeft()
- swap = 1
- dump()
- end
- local function goOut()
- for x=1,size,1 do
- if tryPush() == false then
- goHome()
- end
- cPos = x-1
- print (x)
- end
- end
- local function comeBack()
- for x=size,1,-1 do
- if tryPush() == false then
- goHome()
- end
- cPos = x-1
- print (x)
- end
- end
- local reseal = false
- local cPos = 0
- local done = false
- local function digall()
- print( "I'm home and now (re)digging..." )
- if turtle.digDown() then
- reseal = true
- else
- print( "NO HOME BLOCK! Terminating! :(" )
- return false
- end
- for i=0, tStop do
- if swap > 0 then
- goOut()
- else
- comeBack()
- end
- if tryDown() == false then
- print (" Down Failed on Main ")
- goHome()
- end
- depth = depth + 1
- turtle.turnLeft()
- turtle.turnLeft()
- if swap == 1 then
- swap = -1
- else
- swap = 1
- end
- end
- goHome()
- print( "COMPLETE" )
- end
- digall()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement