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 xDir = 0
- local yDir = 1
- local myX = 0
- local myY = 0
- local myZ = 0
- 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
- else
- return true
- end
- return false
- 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 digFront()
- if turtle.dig() then
- collect()
- return true
- else
- return false
- end
- end
- local function digDown()
- if turtle.digDown() then
- collect()
- return true
- end
- return false
- end
- local function digUp()
- if turtle.digUp() then
- collect()
- return true
- end
- return false
- end
- local function moveForward()
- if not findFuel() then
- return false
- end
- if not turtle.forward() then
- if not digFront() then
- return false
- end
- else
- myX = myX + xDir
- myY = myY + yDir
- return true
- end
- return false
- end
- local function faceLeft()
- yd = yDir
- xd = xDir
- -- 0,1 -> -1,0
- -- -1,0 -> 0,-1
- -- 0,-1 -> 1,0
- -- 1,0 -> 0,1
- -- 0,1 -> -1
- -- -1,0 -> 0
- -- 0,-1 -> 1
- -- 1,0 -> 0
- -- 0,1 -> 0
- -- -1,0 -> -1
- -- 0,-1 -> 0
- -- 1,0 -> 1
- xDir = -1*yd
- yDir = xd
- turtle.turnLeft()
- end
- local function faceRight()
- yd = yDir
- xd = xDir
- -- 0,1 -> 1,0
- -- 1,0 -> 0,-1
- -- 0,-1 -> -1,0
- -- -1,0 -> 0,1
- -- 0,1 -> 1
- -- 1,0 -> 0
- -- 0,-1 -> -1
- -- -1,0 -> 0
- -- 0,1 -> 0
- -- 1,0 -> -1
- -- 0,-1 -> 0
- -- -1,0 -> 1
- xDir = yd
- yDir = -1 * xd
- turtle.turnRight()
- 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 digDown()
- if not turtle.digDown() then
- lastDepth = depth
- return false
- else
- depth = depth + 1
- print ( " Layer: "..depth )
- end
- end
- local function digLocal()
- digDown()
- digUp()
- digFront()
- end
- local function digLine()
- while (myY < size) do
- digLocal()
- moveForward()
- end
- digUp()
- while (myY > 0) do
- digDown()
- moveBack()
- end
- end
- local function newLine()
- faceRight()
- digFront()
- moveForward()
- faceLeft()
- end
- local function digall()
- while (~done == true) do
- while (myX < size) do
- digLine()
- faceRight()
- digFront()
- moveForward()
- faceLeft()
- end
- digLine()
- digDown()
- moveDown()
- digDown()
- moveDown()
- while (myX > 0) do
- digLine()
- faceLeft()
- digFront()
- moveForward()
- faceRight()
- end
- digLine()
- digDown()
- moveDown()
- digDown()
- moveDown()
- end
- print (" Done, Coming Home Last Time ")
- done = true
- goHome()
- end
- digall()
Add Comment
Please, Sign In to add comment