Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local tArgs={...}
- if #tArgs~=1 then
- print("Usage: mine <diameter>")
- print("ex: mine 10 will mine a 10x10x2 area")
- return
- end
- local size=tonumber(tArgs[1])
- if size<1 then
- print("mine diameter must be positve")
- return
- end
- local torches
- local function torch()
- torches=turtle.getItemCount(1)
- if torches==0 then
- return false
- end
- return true
- end
- while not torch() do
- print("Please put torches in slot 1")
- sleep(2)
- end
- 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 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("Resumming mine")
- end
- 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 function placeTorch()
- if torch() then
- turtle.turnLeft()
- turtle.turnLeft()
- turtle.select(1)
- turtle.place()
- torches=torches-1
- turtle.turnLeft()
- turtle.turnLeft()
- else
- while not torch() do
- sleep(2)
- end
- turtle.turnLeft()
- turtle.turnLeft()
- turtle.select(1)
- turtle.place()
- torches=torches-1
- turtle.turnLeft()
- turtle.turnLeft()
- end
- if torches==0 then
- while not torch() do
- print("Out of torches")
- print("put torches in slot 1")
- sleep(2)
- end
- end
- end
- local function checkinv()
- local inv=0
- for i=1,16 do
- if turtle.getItemCount(i)>0 then
- inv=inv+1
- end
- end
- if inv==16 then
- return false
- else
- inv=0
- return true
- end
- end
- local modN,modB
- local function dig()
- for b=1,size-1 do
- modB=b%5
- while not checkinv() do
- print("Inventory full")
- sleep(3)
- end
- if modB==0 and modN==0 then
- placeTorch()
- tryDigUp()
- tryForward()
- tryDigUp()
- else
- tryDigUp()
- tryForward()
- tryDigUp()
- end
- if b==size-1 and modN==0 then
- placeTorch()
- end
- end
- end
- local function left()
- turtle.turnLeft()
- tryDigUp()
- tryForward()
- tryDigUp()
- turtle.turnLeft()
- end
- local function right()
- turtle.turnRight()
- tryDigUp()
- tryForward()
- tryDigUp()
- turtle.turnRight()
- end
- print("Minning...")
- local alternate=0
- local start=true
- for n=1,size do
- modN=n%7
- if n==size or start then
- modN=0
- start=false
- end
- dig()
- if n<size then
- if math.fmod(n + alternate,2) == 0 then
- right()
- else
- left()
- end
- end
- end
- print("Minning Done")
- print("Mined a total of "..collected.." items")
Advertisement
Add Comment
Please, Sign In to add comment