Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local tArgs = { ... }
- if #tArgs ~= 1 then
- print( "Usage: excavate <diameter>" )
- return
- end
- -- Mine in a quarry pattern until we hit something we can't dig
- local size = tonumber( tArgs[1] )
- if size < 1 then
- print( "Excavate diameter must be positive" )
- return
- end
- local depth = 0
- local unloaded = 0
- local collected = 0
- local xPos,zPos = 0,0
- local xDir,zDir = 0,1
- local goTo -- Filled in further down
- local refuel -- Filled in further down
- function refuel( ammount )
- local fuelLevel = turtle.getFuelLevel()
- if fuelLevel == "unlimited" then
- return true
- end
- if turtle.getFuelLevel() < 5000 then
- for dropar= 1,15 do
- turtle.select(dropar)
- turtle.drop()
- end
- turtle.select(16)
- turtle.placeUp()
- turtle.suckUp(1)
- turtle.refuel()
- turtle.dropUp()
- turtle.digUp()
- turtle.select(1)
- return false
- end
- return true
- end
- local function tryForwards()
- if not refuel() then
- print( "Not enough Fuel... Refuel in a Second" )
- end
- while not turtle.forward() do
- if turtle.detect() then
- if turtle.dig() then
- turtle.dropDown()
- else
- return false
- end
- end
- end
- xPos = xPos + xDir
- zPos = zPos + zDir
- return true
- end
- local function tryDown()
- while not turtle.down() do
- if turtle.detectDown() then
- if turtle.digDown() then
- turtle.dropUp()
- else
- return false
- end
- end
- end
- depth = depth + 1
- if math.fmod( depth, 10 ) == 0 then
- print( "Descended "..depth.." metres." )
- end
- return true
- end
- local function turnLeft()
- turtle.turnLeft()
- xDir, zDir = -zDir, xDir
- end
- local function turnRight()
- turtle.turnRight()
- xDir, zDir = zDir, -xDir
- end
- function goTo( x, y, z, xd, zd )
- while depth > y do
- if turtle.up() then
- depth = depth - 1
- sleep( 0.5 )
- end
- end
- if xPos > x then
- while xDir ~= -1 do
- turnLeft()
- end
- while xPos > x do
- if turtle.forward() then
- xPos = xPos - 1
- elseif turtle.dig() or turtle.attack() then
- collect()
- else
- sleep( 0.5 )
- end
- end
- elseif xPos < x then
- while xDir ~= 1 do
- turnLeft()
- end
- while xPos < x do
- if turtle.forward() then
- xPos = xPos + 1
- elseif turtle.dig() or turtle.attack() then
- collect()
- else
- sleep( 0.5 )
- end
- end
- end
- if zPos > z then
- while zDir ~= -1 do
- turnLeft()
- end
- while zPos > z do
- if turtle.forward() then
- zPos = zPos - 1
- elseif turtle.dig() or turtle.attack() then
- collect()
- else
- sleep( 0.5 )
- end
- end
- elseif zPos < z then
- while zDir ~= 1 do
- turnLeft()
- end
- while zPos < z do
- if turtle.forward() then
- zPos = zPos + 1
- elseif turtle.dig() or turtle.attack() then
- collect()
- else
- sleep( 0.5 )
- end
- end
- end
- while depth < y do
- if turtle.down() then
- depth = depth + 1
- elseif turtle.digDown() or turtle.attackDown() then
- collect()
- else
- sleep( 0.5 )
- end
- end
- while zDir ~= zd or xDir ~= xd do
- turnLeft()
- end
- end
- print( "Excavating..." )
- local reseal = false
- turtle.select(1)
- if turtle.digDown() then
- reseal = true
- end
- local alternate = 0
- local done = false
- while not done do
- for n=1,size do
- for m=1,size-1 do
- if not tryForwards() then
- done = true
- break
- end
- end
- if done then
- break
- end
- if n<size then
- if math.fmod(n + alternate,2) == 0 then
- turnLeft()
- if not tryForwards() then
- done = true
- break
- end
- turnLeft()
- else
- turnRight()
- if not tryForwards() then
- done = true
- break
- end
- turnRight()
- end
- end
- end
- if done then
- break
- end
- if size > 1 then
- if math.fmod(size,2) == 0 then
- turnRight()
- else
- if alternate == 0 then
- turnLeft()
- else
- turnRight()
- end
- alternate = 1 - alternate
- end
- end
- if not tryDown() then
- done = true
- break
- end
- end
- print( "Returning to surface..." )
- -- Return to where we started
- goTo( 0,0,0,0,-1 )
- unload( false )
- goTo( 0,0,0,0,1 )
- -- Seal the hole
- if reseal then
- turtle.placeDown()
- end
- print( "Mined "..(collected + unloaded).." items total." )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement