Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Fetch beginning position.
- local startPos = npos.getPosition()
- print("Starting position:")
- print(startPos)
- -- Find refuel/stop waypoint position.
- --local forwardStart = 5
- --for fscnt=1,forwardStart,1 do
- -- npos.move(npos.directions.FORWARD, true)
- --end
- local routeWaypoint = npos.getPosition()
- print("Return waypoint:")
- print(routeWaypoint)
- --npos.moveTo(startPos)
- local exiting = false
- -- Get back to our house safely.
- function navigateHome()
- print("Moving to house entrance")
- npos.moveTo(routeWaypoint)
- print("Moving to home")
- npos.moveTo(startPos)
- end
- -- Get out of our house.
- function exitHome()
- print("Exiting the house")
- npos.moveTo(routeWaypoint)
- end
- -- Check if we need to unload.
- function isUnloadRequired()
- for i=1,16,1 do
- if(turtle.getItemDetail(i) == nil) then
- return false
- end
- end
- return true
- end
- -- Select an empty slot.
- function selectEmptySlot()
- for i=1,16,1 do
- if(turtle.getItemDetail(i) == nil) then
- turtle.select(i)
- return true
- end
- end
- return false
- end
- -- Check our inventory/fuel status.
- function blockCheck()
- if(turtle.getFuelLevel() < 5000 or isUnloadRequired()) then
- local cpos = npos.getPosition()
- print("Making a drop and refuel run")
- navigateHome()
- -- 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(rfi)
- 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
- -- Resume where we left off.
- exitHome()
- npos.moveTo(cpos)
- npos.setOrientation(cpos.o)
- end
- 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
- print("Looks like we're done with this chunk, going home.")
- navigateHome()
- end
- local args = { ... }
- local chunkForward = tonumber(args[1])
- local chunkLateral = tonumber(args[2])
- -- Leave the comfort of our warm, warm home.
- exitHome()
- -- Move right the given amount of chunks we're mining from here.
- --if(chunkLateral > 0) then
- -- print("Moving laterally a chunk or so")
- -- npos.turnRight()
- -- for cl=1,chunkLateral,1 do
- -- for cli=1,16,1 do
- -- npos.move(npos.directions.FORWARD, true)
- -- end
- -- end
- -- npos.setOrientation(startPos.o)
- -- npos.turnLeft()
- --end
- -- Move forward the given amount of chunks we're mining from here.
- --if(chunkForward > 0) then
- -- for cf=1,chunkForward,1 do
- -- print("Moving forward a chunk or so")
- -- for cfi=1,16,1 do
- -- npos.move(npos.directions.FORWARD, true)
- -- end
- -- end
- --end
- -- Move backwards our 'forward start' amount.
- --print("Resetting to pre-forward start offset")
- --npos.turnLeft()
- --npos.turnLeft()
- --for fsr=1,forwardStart,1 do npos.move(npos.directions.FORWARD, true) end
- --npos.turnLeft()
- --npos.turnLeft()
- -- We good to go.
- print("Kicking off excavation...")
- excavateChunk()
- npos.setOrientation(startPos.o)
- print("Done.")a
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement