Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --get Arguements
- local tArgs = { ... }
- --Validate Arguements
- if (#tArgs < 1) then
- print("Invalid # of Arguements")
- return
- end
- local evenodd = tonumber(tArgs[1])
- if (evenodd ~= 0) and (evenodd ~= 1) then
- print("Even/Odd should = 0 or 1")
- return
- end
- local function refuel(slot)
- local fuelLevel = turtle.getFuelLevel()
- if fuelLevel == "unlimited" or fuelLevel > 0 then
- return
- end
- local function tryRefuel()
- if turtle.getItemCount(1) > 0 then
- turtle.select(1)
- if turtle.refuel(1) then
- return true
- end
- end
- return false
- end
- if not tryRefuel() then
- print( "Add more fuel to continue." )
- while not tryRefuel() do
- sleep(5)
- end
- print( "Resuming..." )
- turtle.select(slot)
- end
- end
- local function checkStorage()
- if turtle.getItemCount(16) > 0 then
- print("Clean inventory...")
- while turtle.getItemCount(16) > 0 do
- sleep(5)
- end
- print( "Resuming..." )
- end
- end
- local function tryDig()
- while turtle.detect() do
- if turtle.dig() then
- checkStorage()
- sleep(0.5)
- else
- return false
- end
- end
- return true
- end
- local function tryForward(slot)
- refuel(slot)
- while not turtle.forward() do
- if turtle.detect() then
- if not tryDig() then
- return false
- end
- elseif turtle.attack() then
- checkStorage()
- else
- sleep(0.5)
- end
- end
- return true
- end
- local function checkBlock(slot,first,last,block)
- while turtle.getItemCount(slot) == 0 do
- slot = slot + 1
- if slot > last then
- print("Missing: " .. block)
- print("Slots: " .. first .. "-" .. last)
- local line=""
- repeat
- print("Enter 'Y' to continue: ")
- line = io.read()
- until string.lower(line) ~= "y"
- print("Resuming...")
- slot = first --Reset slot to first
- end
- end
- return slot
- end
- local function tryDig()
- while turtle.detect() do
- if turtle.dig() then
- checkStorage()
- sleep(0.5)
- else
- return false
- end
- end
- return true
- end
- local function tryBlock(slot,inv,first,last,block,dir)
- slot=checkBlock(slot,first,last,block)
- turtle.select(slot)
- if (dir == 0) then
- turtle.place()
- elseif (dir > 0) then
- turtle.placeUp()
- else
- turtle.placeDown()
- end
- turtle.select(inv)
- return checkBlock(slot,first,last,block)
- end
- local function placeBehind(slot,inv,first,last,block)
- turtle.turnLeft()
- turtle.turnLeft()
- slot = tryBlock(slot,inv,first,last,block,0)
- turtle.turnLeft()
- turtle.turnLeft()
- return slot
- end
- local len
- local slot=2
- local quad
- local seg
- local segpos
- local seglen
- for quad=0,3,1 do
- --set array length
- len=#tArgs
- --First section of Quandrant
- for seg=2,len,1 do
- seglen=tonumber(tArgs[seg])
- for segpos=1,(seglen-1),1 do
- tryForward(slot)
- slot = placeBehind(slot,9,2,8,"Placement Blocks")
- end
- turtle.turnLeft()
- tryForward(slot)
- slot = placeBehind(slot,9,2,8,"Placement Blocks")
- turtle.turnRight()
- tryForward(slot)
- end
- --Handle Odd Length Quadrants
- if evenodd==1 then
- len=len-1
- end
- --Last Section of Quandrant
- turtle.turnLeft()
- for seg=len,2,-1 do
- seglen=tonumber(tArgs[seg])
- for segpos=1,seglen,1 do
- tryForward(slot)
- slot = placeBehind(slot,9,2,8,"Placement Blocks")
- end
- if seg ~= 2 then
- turtle.turnRight()
- tryForward(slot)
- turtle.turnLeft()
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment