Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Miner
- local length = 3
- local unloaded = 0
- local collected = 0
- local depth = 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 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
- sleep(1)
- rednet.open("right")
- while true do
- term.clear()
- term.setCursorPos(1, 1)
- print("Ready to Receve Commands")
- local id, mgs, dis = rednet.receive()
- if mgs == "2Forward" then
- turtle.forward()
- end
- if mgs == "2Back" then
- turtle.back()
- end
- if mgs == "2TurnLeft" then
- turtle.turnLeft()
- end
- if mgs == "2TurnRight" then
- turtle.turnRight()
- end
- if mgs == "2Up" then
- turtle.up()
- end
- if mgs == "2Down" then
- turtle.down()
- end
- if mgs == "2Dig" then
- turtle.dig()
- end
- if mgs == "2DigUp" then
- turtle.digUp()
- end
- if mgs == "2DigDown" then
- turtle.digDown()
- end
- if mgs == "2Place" then
- turtle.place()
- end
- if mgs == "2PlaceDown" then
- turtle.placeDown()
- end
- if mgs == "2PlaceUp" then
- turtle.placeUp()
- end
- if mgs == "2Drop" then
- for n=1,16 do
- unloaded = unloaded + turtle.getItemCount(n)
- turtle.select(n)
- turtle.drop()
- end
- collected = 0
- turtle.select(1)
- end
- if mgs == "2Tunnel" then
- for n=1,length do
- turtle.placeDown()
- tryDigUp()
- turtle.turnLeft()
- tryDig()
- tryUp()
- tryDig()
- turtle.turnRight()
- turtle.turnRight()
- tryDig()
- tryDown()
- tryDig()
- turtle.turnLeft()
- if n<length then
- tryDig()
- if not tryForward() then
- print( "Aborting Tunnel." )
- break
- end
- else
- print( "Tunnel complete." )
- end
- end
- print( "Returning to start..." )
- turtle.turnLeft()
- turtle.turnLeft()
- while depth > 0 do
- if turtle.forward() then
- depth = depth - 1
- else
- turtle.dig()
- end
- end
- turtle.turnRight()
- turtle.turnRight()
- rednet.broadcast("MDone")
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment