Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- snake
- os.loadAPI("path")
- os.loadAPI("dig")
- local foundBlockToMine = 0
- function digIt()
- path.forward()
- -- Algorithm continuation: while nothing detected 'up', simply move on. First time we find something, start being throrough again.
- if turtle.detectUp() and foundBlockToMine == 0 then
- foundBlockToMine = 1
- print("* Found first block to mine, being thorough now")
- end
- if foundBlockToMine == 0 then return end
- dig.leftWithoutMoving()
- dig.rightWithoutMoving()
- dig.up()
- dig.leftWithoutMoving()
- dig.rightWithoutMoving()
- dig.up()
- dig.leftWithoutMoving()
- dig.rightWithoutMoving()
- dig.up()
- dig.leftWithoutMoving()
- dig.rightWithoutMoving()
- dig.up()
- dig.leftWithoutMoving()
- dig.rightWithoutMoving()
- dig.up()
- dig.leftWithoutMoving()
- dig.rightWithoutMoving()
- dig.down()
- dig.down()
- dig.down()
- dig.down()
- dig.down()
- end
- function placeTorch()
- turtle.turnLeft()
- if turtle.getItemCount(16) > 0 then
- turtle.select(16)
- turtle.place()
- turtle.select(1)
- else
- print("* No torches in inventory to place")
- end
- turtle.turnRight()
- end
- function fuelCheck()
- if path.length() + 50 > turtle.getFuelLevel() then
- print("* I'm about to go out of fuel, going back")
- path.navigateBack()
- print("* I'm back. Emptying and shutting down.")
- emptyInventory()
- quit()
- end
- end
- function fullCheck()
- if turtle.getItemCount(15) > 0 then
- print("* My 15th slot is used. Heading back to empty.")
- path.navigateBack()
- print("* I'm back, emptying!")
- emptyInventory()
- if (path.length() * 2) + 50 > turtle.getFuelLevel() then
- print("* Fuel is kind of low, not heading out!")
- quit()
- else
- print("* Heading out again!")
- path.navigateForward()
- end
- end
- end
- function emptyInventory()
- print("* Finding something to drop items in!")
- if turtle.detect() then
- emptyInventoryFront()
- end
- turtle.turnLeft()
- if turtle.detect() then
- emptyInventoryFront()
- end
- turtle.turnLeft()
- if turtle.detect() then
- emptyInventoryFront()
- end
- turtle.turnLeft()
- if turtle.detect() then
- emptyInventoryFront()
- end
- turtle.turnLeft()
- end
- function emptyInventoryFront()
- print("* Found something, dropping items!")
- for l = 1, 15 do
- turtle.select(l)
- turtle.drop()
- end
- turtle.select(1)
- end
- -- Q: Length of the lane?
- local lanelength = 0
- term.write("Length of the lane (#)? ")
- lanelength = tonumber(read())
- -- Q: Do we go LEFT or RIGHT at end of lane?
- local leftright = ""
- term.write("Left or Right at end (L/R)? ")
- leftright = read()
- local leftrightmod = 1
- if leftright == "l" or leftright == "L" then
- leftrightmod = 0
- end
- -- Q: How many lanes?
- local lanecount = 0
- term.write("How many lanes (#)? ")
- lanecount = tonumber(read())
- -- Q: Start at lane?
- local offset = 0
- term.write("Lane offset (#)? ")
- offset = tonumber(read()) * 5
- -- Simple fuel check before we start
- if turtle.getFuelLevel() < 100 then
- print("* Fuel me first, mister!")
- quit()
- end
- -- Offsets?
- if offset > 0 and leftrightmod == 1 then
- path.right()
- for i = 1, offset do
- path.forward()
- end
- path.left()
- end
- if offset > 0 and leftrightmod == 0 then
- path.left()
- for i = 1, offset do
- path.forward()
- end
- path.right()
- end
- -- Go through lanes
- for i = 1, lanecount do
- print("* Proceeding with lane "..i)
- -- Go through the current lane
- for j = 1, lanelength do
- fuelCheck()
- fullCheck()
- digIt()
- if j % 7 == 0 then placeTorch() end
- end
- -- If this was the last lane, break out
- if i < lanecount then
- -- When we finished a lane and there's more to do, move a bit for the next lane
- print("* Going around the corner!")
- digIt()
- path.back()
- if i % 2 == leftrightmod then
- -- Turn right
- path.right()
- digIt()
- digIt()
- digIt()
- digIt()
- digIt()
- digIt()
- path.back()
- path.right()
- else
- -- Turn left
- path.left()
- digIt()
- digIt()
- digIt()
- digIt()
- digIt()
- digIt()
- path.back()
- path.left()
- end
- end
- end
- -- All done
- print("* All done! Heading back.")
- path.navigateBack()
- emptyInventory()
- print("* Shutting down!")
Advertisement
Add Comment
Please, Sign In to add comment