Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local startPos = npos.getPosition()
- local exiting = false
- function isUnloadRequired()
- for i=1,16,1 do
- if(turtle.getItemDetail(i) == nil) then
- return false
- end
- end
- return true
- end
- function selectEmptySlot()
- for i=1,16,1 do
- if(turtle.getItemDetail(i) == nil) then
- turtle.select(i)
- return true
- end
- end
- return false
- end
- function blockCheck()
- local cpos = npos.getPosition()
- if(turtle.getFuelLevel() < 5000 or isUnloadRequired()) then
- print("Making a drop and refuel run")
- npos.moveTo(startPos)
- -- Spit everything out.
- npos.setOrientation(npos.orientations.SOUTH)
- print("Dropping items...")
- for dx=1,16,1 do
- turtle.select(dx)
- if(turtle.getItemDetail(dx) == nil) then
- print(dx .. ": Nothing here, cant drop...")
- else
- if(turtle.drop() == false) then
- print(dx .. ": Can't drop anymore. stopping...")
- exiting = true
- return true
- else
- print(dx .. ": Dropped")
- end
- end
- end
- -- Check if we need to refuel.
- npos.setOrientation(npos.orientations.WEST)
- if(turtle.getFuelLevel() < 5000) then
- selectEmptySlot()
- while(turtle.getFuelLevel() < 15000) do
- if(turtle.suck() == true) then
- local refuelSuccess = false
- for rfi=1,16,1 do
- turtle.select(i)
- if(turtle.refuel()) then
- refuelSuccess = true
- end
- end
- if(refuelSuccess == false) then
- print("Couldn't refuel after fetching from fuel chest")
- exiting = true
- return true
- end
- else
- print("Couldn't refuel anymore, stopping...")
- exiting = true
- return true
- end
- end
- end
- end
- -- Resume where we left off.
- npos.moveTo(cpos)
- npos.setOrientation(cpos.o)
- end
- function excavateChunk()
- local isForward = true
- local startPos = npos.getPosition()
- w = 16
- h = 16
- l = 16
- for ch=1,16,1 do
- for cw=1,16,1 do
- for cl=1,15,1 do
- npos.move(npos.directions.FORWARD, true)
- blockCheck()
- if(exiting == true) then return true end
- end
- if(cw < w) then
- if(isForward) then
- npos.turnRight()
- npos.move(npos.directions.FORWARD, true)
- blockCheck()
- if(exiting == true) then return true end
- npos.turnRight()
- isForward = false
- else
- npos.turnLeft()
- npos.move(npos.directions.FORWARD, true)
- blockCheck()
- if(exiting == true) then return true end
- npos.turnLeft()
- isForward = true
- end
- end
- end
- if(ch < h) then
- npos.move(npos.directions.UP, true)
- blockCheck()
- if(exiting == true) then return true end
- npos.turnLeft()
- npos.turnLeft()
- end
- end
- for rl=1,h-1,1 do
- npos.move(npos.directions.DOWN, true)
- end
- npos.setOrientation(startPos.o)
- if(curX ~= startPos.x) then
- npos.turnLeft()
- for rsw=1,w-1,1 do npos.move(npos.directions.FORWARD, true) end
- npos.turnLeft()
- for rsl=1,l-1,1 do npos.move(npos.directions.FORWARD, true) end
- npos.setOrientation(startPos.o)
- end
- end
- print("Kicking off excavation...")
- excavateChunk()
- print("Done.")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement