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> <depth>" )
- 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 = 255
- 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 bedrock = false
- local fcDown = 0
- local fcPush = 0
- local function findFuel()
- if turtle.getFuelLevel() < 1 then
- for i = 1, 16 do -- loop through the slots
- turtle.select(i) -- change to the slot
- if turtle.refuel(0) then -- if it's valid fuel
- local halfStack = math.ceil(turtle.getItemCount(i)/2) -- work out half of the amount of fuel in the slot
- turtle.refuel(halfStack) -- consume half the stack as fuel
- return true
- end
- end
- end
- return false
- end
- local function proxyDown()
- if not turtle.down() then
- print ("Move down failed. Checking fuel...")
- if not findFuel() then
- print ("Out of fuel!")
- return false
- else
- if not turtle.down() then
- print ("Something in the way! Bedrock?")
- return false
- end
- end
- end
- return true
- end
- local function proxyForward()
- if not turtle.forward() then
- print ("Move forward failed. Checking fuel...")
- if not findFuel() then
- print ("Out of fuel!")
- return false
- else
- if not turtle.forward() then
- print ("Something in front!")
- return false
- end
- end
- end
- return true
- end
- local function proxyUp()
- if not turtle.up() then
- print ("Move forward failed. Checking fuel...")
- if not findFuel() then
- print ("Out of fuel!")
- return false
- else
- if not turtle.up() then
- print ("Something in front!")
- return false
- end
- end
- end
- return true
- end
- 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." )
- print (" Going Home to Dump. ")
- lastDepth = depth
- goHome()
- return false
- end
- local function tryPush()
- if not proxyForward() then
- if turtle.dig() then
- collect()
- else
- fcPush = fcPush + 1
- -- give sand a chance to fall
- sleep(0.8)
- if turtle.dig() then
- collect()
- else
- fcPush = fcPush + 1
- return false
- end
- end
- else
- cPos = cPos + 1
- end
- return true
- end
- local function tryDown()
- -- print (" Down Called ")
- if not proxyDown() then
- print (" Can't move down, trying dig... ")
- if turtle.digDown() then
- collect()
- else
- fcDown = fcDown + 1
- end
- if not proxyDown() then
- fcDown = fcDown + 1
- print ("Move down failed.")
- else
- depth = depth + 1
- end
- else
- depth = depth + 1
- end
- print (" I moved down. ")
- return true
- end
- local function goHome()
- print( " Coming Home... From Depth: "..depth )
- while depth > 0 do
- if proxyUp() == true then
- print ( "Updiddy: "..depth )
- depth = depth - 1
- else
- turtle.digUp()
- print ( "Up is blocked, panicing." )
- end
- end
- while cPos > 0 do
- if turtle.back() == false then
- print ( "Back is blocked, panicing." )
- turtle.turnLeft()
- turtle.turnLeft()
- turtle.dig()
- turtle.turnLeft()
- turtle.turnLeft()
- else
- cPos = cPos - 1
- end
- end
- print ( "Now Home, failed: "..(fcDown+fcPush).." times." )
- dump()
- if done == false then
- print ( " Going back to work. " )
- while depth < lastDepth do
- if tryDown() == true then
- -- D
- end
- end
- print ( " Now Working... " )
- end
- end
- local function goOut()
- while cPos < size do
- if tryPush() == false then
- return false
- -- print( "Not Moving " )
- else
- -- print( "Moving" )
- end
- end
- end
- local function comeBack()
- while cPos > 0 do
- if turtle.back() == true then
- cPos = cPos - 1
- else
- turtle.turnLeft()
- turtle.turnLeft()
- turtle.dig()
- turtle.turnLeft()
- turtle.turnLeft()
- -- print ( "Move your ass" )
- end
- -- print (cPos)
- end
- end
- local function digDown()
- if tryDown() == false then
- lastDepth = depth
- return false
- else
- -- depth = depth + 1
- print ( " Layer: "..depth )
- end
- end
- local fcTotal = 0
- local function digall()
- while (done ~= true) do
- fcTotal = fcPush + fcDown
- print ("Fails: "..fcPush.." : "..fcDown)
- if fcTotal > 2 then
- done = true
- end
- if (depth > tStop) then
- done = true
- end
- goOut()
- comeBack()
- if digDown() == false then
- done = true
- end
- end
- print (" Done, Coming Home Last Time ")
- done = true
- goHome()
- end
- digall()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement