Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local tArgs = { ... }
- if #tArgs ~= 2 then
- print( "Usage: stripmine <length> <Amount of Mines>" )
- return
- end
- -- Mine in a quarry pattern until we hit something we can't dig
- local length = tonumber( tArgs[1] )
- local mines = tonumber( tArgs[2] )
- if length < 1 then
- print( "Tunnel length must be positive" )
- return
- end
- if mines < 1 then
- print( "Number of Mines must be positive" )
- return
- end
- local depth = 0
- local collected = 0
- local function collect()
- collected = collected + 1
- if math.fmod(collected, 25) == 0 then
- print( "Mined "..collected.." items." )
- end
- end
- local function tryDig()
- while turtle.detect() do
- if turtle.dig() then
- collect()
- sleep(0.5)
- else
- return false
- end
- end
- return true
- end
- local function tryDigUp()
- while turtle.detectUp() do
- if turtle.digUp() then
- collect()
- sleep(0.5)
- else
- return false
- end
- end
- return true
- end
- local function tryDigDown()
- while turtle.detectDown() do
- if turtle.digDown() then
- collect()
- sleep(0.5)
- else
- return false
- end
- end
- return true
- end
- local function refuel()
- local fuelLevel = turtle.getFuelLevel()
- if fuelLevel == "unlimited" or fuelLevel > 0 then
- return
- end
- local function tryRefuel()
- for n=1,16 do
- if turtle.getItemCount(n) > 0 then
- turtle.select(n)
- if turtle.refuel(1) then
- turtle.select(1)
- return true
- end
- end
- end
- turtle.select(1)
- return false
- end
- if not tryRefuel() then
- print( "Add more fuel to continue." )
- while not tryRefuel() do
- sleep(1)
- end
- print( "Resuming Tunnel." )
- end
- end
- local function tryUp()
- refuel()
- while not turtle.up() do
- if turtle.detectUp() then
- if not tryDigUp() then
- return false
- end
- elseif turtle.attackUp() then
- collect()
- else
- sleep( 0.5 )
- end
- end
- return true
- end
- local function tryDown()
- refuel()
- while not turtle.down() do
- if turtle.detectDown() then
- if not tryDigDown() then
- return false
- end
- elseif turtle.attackDown() then
- collect()
- else
- sleep( 0.5 )
- end
- end
- return true
- end
- local function tryForward()
- refuel()
- while not turtle.forward() do
- if turtle.detect() then
- if not tryDig() then
- return false
- end
- elseif turtle.attack() then
- collect()
- else
- sleep( 0.5 )
- end
- end
- return true
- end
- local lighta = 0
- local function addLight()
- lighta = (lighta + 1)
- print( fs.combine("Light Amount = ", tostring(lighta)) )
- end
- local function stripm()
- for n=1,length do
- tryDig()--Digs Forward(bottom)
- tryUp() --Goes Up
- tryDig()--Digs Forward(top)
- tryDown()
- addLight()
- if lighta == 8 then
- tryUp()
- tryDigUp()
- turtle.select(1)
- if turtle.getItemCount(1) <= 1 then
- print( "Out of Tourches" )
- else
- turtle.placeUp()
- end
- tryDown()
- lighta = 0
- print( "Torch Placed, Light Reset." )
- end
- if n<length then
- tryDig()
- if not tryForward() then
- print( "Aborting Tunnel." )
- break
- end
- else
- print( "Tunnel complete." )
- end
- end
- print( "Returning" )
- shell.run("go", "back", tostring(length - 1))
- print( "Tunnel complete." )
- end
- local function stripv2()
- for n=1,length do
- tryDig()--Digs Forward(bottom)
- tryDigUp()
- addLight()
- if lighta == 8 then
- tryUp()
- tryDigUp()
- turtle.select(1)
- if turtle.getItemCount(1) <= 1 then
- print( "Out of Tourches" )
- else
- turtle.placeUp()
- end
- tryDown()
- lighta = 0
- print( "Torch Placed, Light Reset." )
- end
- if n<length then
- tryDig()
- if not tryForward() then
- print( "Aborting Tunnel." )
- break
- end
- else
- print( "Tunnel complete." )
- end
- end
- print( "Returning" )
- shell.run("go", "back", tostring(length - 1))
- print( "Tunnel complete." )
- end
- local function nextmine()
- turtle.turnLeft()
- turtle.forward()
- turtle.forward()
- turtle.turnRight()
- end
- local function layChest()
- turtle.digDown()
- turtle.select(2)
- turtle.placeDown()
- --Deposits in chest
- turtle.select(3)
- turtle.dropDown()
- turtle.select(4)
- turtle.dropDown()
- turtle.select(5)
- turtle.dropDown()
- turtle.select(6)
- turtle.dropDown()
- turtle.select(7)
- turtle.dropDown()
- turtle.select(8)
- turtle.dropDown()
- turtle.select(9)
- turtle.dropDown()
- turtle.select(10)
- turtle.dropDown()
- turtle.select(11)
- turtle.dropDown()
- turtle.select(12)
- turtle.dropDown()
- turtle.select(13)
- turtle.dropDown()
- turtle.select(14)
- turtle.dropDown()
- turtle.select(15)
- turtle.dropDown()
- turtle.select(16)
- turtle.dropDown()
- end
- print( "Strip Mining..." )
- for n=1,mines do
- stripv2()
- layChest()
- nextmine()
- --shell.run("nextmine")
- end
- print( "Strip Mine complete." )
- print( "Mined "..collected.." items total." )
- --310926
Advertisement
Add Comment
Please, Sign In to add comment