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 aDump = 0
- local cPos = 0
- local reseal = false
- local done = false
- local lastDepth = 0
- local function dump()
- while turtle.back() == false do
- sleep(0.8)
- end
- while turtle.back() == false do
- sleep(0.8)
- 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)
- while turtle.back() == false do
- sleep(0.8)
- end
- while turtle.back() == false do
- sleep(0.8)
- 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
- else
- cPos = cPos + 1
- 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... " )
- while depth > 0 do
- if turtle.up() == true then
- depth = depth - 1
- else
- print ( "Up is blocked, can't come home" )
- end
- end
- while cPos > 0 do
- if turtle.back() == false then
- print ( "Back is blocked, can't come home" )
- else
- cPos = cPos - 1
- end
- end
- print ( "Now Home" )
- dump()
- if not done then
- print ( " Going back to work. " )
- while depth < lastDepth do
- if tryDown() == true then
- depth = depth + 1
- end
- end
- print ( " Now Working... " )
- end
- end
- local function goOut()
- while cPos < size do
- if tryPush() == false then
- lastDepth = depth
- goHome()
- else
- -- print( "Moving" )
- end
- end
- end
- local function comeBack()
- while cPos > 0 do
- if turtle.back() == true then
- cPos = cPos - 1
- else
- -- print ( "Move your ass" )
- end
- -- print (cPos)
- end
- end
- local function digDown()
- if tryDown() == false then
- lastDepth = depth
- goHome()
- return false
- else
- depth = depth + 1
- print ( " Layer: "..depth )
- end
- end
- local function digall()
- while depth < tStop do
- goOut()
- comeBack()
- digDown()
- end
- done = true
- goHome()
- end
- digall()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement