Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ----------------------------------------------
- -- Nether Excavation Turtle
- -- 1) Upload code to your turtle with "pastebin get Bb9DsaFX excavateNether"
- -- 2) Dig down to the edge of a lava lake (level 32).
- -- 3) Place chest behind your turtle. Place one bucket of lava into the first slot of its inventory.
- -- 4) Run code using "excavateNether <bore size>" replacing <bore size> with the width of the hole you wish to dig
- -- 5) It will draw as much lava as is necessary to mine and bore upwards and deposit items in the chest as it gets full.
- -- Note: If you run this program in the overworld you WILL lose your turtle.
- ----------------------------------------------
- -- Credit to leftler for his lava refueling code: https://pastebin.com/nFSUKiYE
- ----------------------------------------------
- -- V1 - basic dig up Function
- -- V2 - added lava refueling
- -- V3 - added findCeiling function to start digging faster
- ----------------------------------------------
- local tArgs = { ... }
- if #tArgs ~= 1 then
- print( "Usage: excavateNether <diameter>" )
- return
- end
- local size = tonumber( tArgs[1] )
- -- Mine in a quarry pattern until we hit something we can't dig
- if size < 1 then
- print( "Excavate diameter must be positive" )
- return
- end
- local height = 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
- local function unload( _bKeepOneFuelStack )
- print( "Unloading items..." )
- for n=1,16 do
- local nCount = turtle.getItemCount(n)
- if nCount > 0 then
- turtle.select(n)
- local bDrop = true
- if _bKeepOneFuelStack and turtle.refuel(0) then
- bDrop = false
- _bKeepOneFuelStack = false
- end
- if bDrop then
- turtle.drop()
- unloaded = unloaded + nCount
- end
- end
- end
- collected = 0
- turtle.select(1)
- end
- local function returnSupplies()
- local x,y,z,xd,zd = xPos,height,zPos,xDir,zDir
- print( "Returning to surface..." )
- goTo( 0,0,0,0,-1 )
- local fuelNeeded = 2*(x+y+z) + 1
- if not refuel( fuelNeeded ) then
- unload( true )
- print( "Waiting for fuel" )
- while not refuel( fuelNeeded ) do
- os.pullEvent( "turtle_inventory" )
- end
- else
- unload( true )
- end
- print( "Resuming mining..." )
- goTo( x,y,z,xd,zd )
- end
- local function collect()
- local bFull = true
- local nTotalItems = 0
- for n=1,16 do
- local nCount = turtle.getItemCount(n)
- if nCount == 0 then
- bFull = false
- end
- nTotalItems = nTotalItems + nCount
- end
- if nTotalItems > collected then
- collected = nTotalItems
- if math.fmod(collected + unloaded, 50) == 0 then
- print( "Mined "..(collected + unloaded).." items." )
- end
- end
- if bFull then
- print( "No empty slots left." )
- return false
- end
- return true
- end
- function refuel( ammount )
- local fuelLevel = turtle.getFuelLevel()
- if fuelLevel == "unlimited" then
- return true
- end
- local needed = ammount or (xPos + zPos + height + 2)
- if turtle.getFuelLevel() < needed then
- local fueled = false
- for n=1,16 do
- if turtle.getItemCount(n) > 0 then
- turtle.select(n)
- if turtle.refuel(1) then
- while turtle.getItemCount(n) > 0 and turtle.getFuelLevel() < needed do
- turtle.refuel(1)
- end
- if turtle.getFuelLevel() >= needed then
- turtle.select(1)
- return true
- end
- end
- end
- end
- turtle.select(1)
- return false
- end
- return true
- end
- local function tryForwards()
- if not refuel() then
- print( "Not enough Fuel" )
- returnSupplies()
- end
- while not turtle.forward() do
- if turtle.detect() then
- if turtle.dig() then
- if not collect() then
- returnSupplies()
- end
- else
- return false
- end
- elseif turtle.attack() then
- if not collect() then
- returnSupplies()
- end
- else
- sleep( 0.5 )
- end
- end
- xPos = xPos + xDir
- zPos = zPos + zDir
- return true
- end
- local function tryUp()
- if not refuel() then
- print( "Not enough Fuel" )
- returnSupplies()
- end
- while not turtle.up() do
- if turtle.detectUp() then
- if turtle.digUp() then
- if not collect() then
- returnSupplies()
- end
- else
- return false
- end
- elseif turtle.attackUp() then
- if not collect() then
- returnSupplies()
- end
- else
- sleep( 0.5 )
- end
- end
- height = height + 1
- if math.fmod( height, 10 ) == 0 then
- print( "Ascended "..height.." 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 height > y do
- if turtle.down() then
- height = height - 1
- elseif turtle.digDown() or turtle.attackDown() then
- collect()
- else
- 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 height < y do
- if turtle.up() then
- height = height + 1
- elseif turtle.digUp() or turtle.attackUp() then
- collect()
- else
- sleep( 0.5 )
- end
- end
- while zDir ~= zd or xDir ~= xd do
- turnLeft()
- end
- end
- -- Function to find nether ceiling first.
- local function findCeiling()
- while turtle.detectUp() == false do
- if turtle.up() then
- height = height + 1
- end
- end
- end
- ----
- -- Lava Refuel Program (leftler's code)
- local fuelReq = 93*size*size+93
- local lavaBuckets = (fuelReq*0.001)*0.5
- --Number of blocks to travel to get the lava
- local maxDistance = math.ceil(lavaBuckets)+math.ceil(0.25*size)
- --local counter for how far the turtle has travle
- local traveled = 0
- --A helper function to try and move up, it will attempt to dig if it is blocked.
- local function moveUp()
- if turtle.up() == false then
- --Failed to move, see if we can dig our way down
- while turtle.digUp() do
- --Keep digging till we can't dig any more, in case gravel is falling.
- end
- if turtle.up() == false then
- print("I am either blocked or out of fuel.")
- return false
- end
- end
- return true
- end
- --A helper function to try and move forward, it will attempt to dig if it is blocked.
- local function moveForward()
- if turtle.forward() == false then
- --Failed to move, see if we can dig our way forward
- while turtle.dig() do
- --Keep digging till we can't dig any more, in case gravel is falling.
- end
- if turtle.forward() == false then
- print("I am either blocked or out of fuel.")
- return false
- end
- end
- return true
- end
- ------
- -- Program Start
- ------
- if turtle.refuel() == false then
- print("The turtle must have at least one lava bucket to start with.")
- return
- elseif turtle.getFuelLevel() == "unlimited" then
- print("This turtle does not use fuel to move")
- return
- end
- for i = 1, maxDistance do
- if moveForward() == false then
- print("Could not move forward the full requested distance, starting U-Turn early.")
- break
- end
- traveled = traveled + 1
- --grab the fule
- turtle.placeDown()
- if turtle.refuel() == false then
- --Whatever we picked up is invalid for fuel, put it back down
- turtle.placeDown()
- end
- end
- --Turn around move a block over and get more lava
- turtle.turnRight()
- moveForward()
- turtle.turnRight()
- --Travel back the same number of blocks we came
- for i = 1, traveled do
- turtle.placeDown()
- turtle.refuel()
- if moveForward() == false then
- --We are stuck, attempt to go up a level to get home
- if drop > 0 then
- repeat
- moveUp()
- drop = drop - 1
- lastMove = moveForward()
- until lastMove == true or drop == 0
- if lastMove == false then
- print("I am stuck!")
- end
- end
- end
- end
- turtle.turnRight()
- moveForward()
- turtle.turnRight()
- print( "Finding ceiling... ")
- findCeiling()
- print( "Excavating..." )
- local reseal = false
- turtle.select(1)
- if turtle.digUp() 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 tryUp() 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.placeUp()
- end
- print( "Mined "..(collected + unloaded).." items total." )
Advertisement
Add Comment
Please, Sign In to add comment