Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- shaft
- -- Digs a vertical shaft straight down to the depth specified by the user
- -- If supplied, ladder is placed
- -- Written by HarvDad, March 2014
- args = {...}
- nArgs = #args
- print("shaft: Rev 2.2")
- x = 0
- y = 0
- z = 0
- face = 0
- minimumFuel = 100
- minLevel = 6
- missionMessage = "Mission complete."
- abort = false
- local currentFuelLevel = turtle.getFuelLevel()
- patchSlot = 1
- ladderSlot = 16
- goingUp = false
- if nArgs == 0 or (nArgs == 1 and args[1]== "help") then
- print("Digs a vertical shaft straight down.")
- print("This program assumes turtle is pre-fueled.")
- print("Usage: shaft <depth>")
- print("Specify the number of blocks to dig down.")
- print("If desired, place ladder in slot ", ladderSlot, ".")
- return
- end
- if nArgs ~= 1 then
- print("Usage: shaft <depth>")
- return
- end
- targetDepth = tonumber(args[1])
- if targetDepth == nil then
- print("\"", args[1], "\" is not a valid depth")
- return
- end
- if (targetDepth < 0) then
- goingUp = true
- end
- depth = 0
- function left()
- if face == 0 then face = 1 turtle.turnLeft() return end
- if face == 1 then face = 2 turtle.turnLeft() return end
- if face == 2 then face = 3 turtle.turnLeft() return end
- if face == 3 then face = 0 turtle.turnLeft() return end
- print("function left\(\): Bad face value: ", face)
- end
- function right()
- if face == 0 then face = 3 turtle.turnRight() return end
- if face == 1 then face = 0 turtle.turnRight() return end
- if face == 2 then face = 1 turtle.turnRight() return end
- if face == 3 then face = 2 turtle.turnRight() return end
- print("function right\(\): Bad face value: ", face)
- end
- function patchWalls()
- if turtle.getItemCount(patchSlot) < 4 then
- gatherPatchMaterial()
- end
- turtle.select(patchSlot)
- turtle.place()
- left()
- turtle.place()
- left()
- turtle.place()
- left()
- turtle.place()
- left()
- end
- function up()
- attackCount = 0
- while turtle.detectUp() do -- This loop added in case of falling sand or whatever
- turtle.digUp()
- end
- for i=1,10 do -- This loop tries to handle pests (mob) that might be in the way
- if turtle.up() then
- break
- end
- sleep(2)
- end
- if attackCount > 1 then
- turtle.attackUp()
- end
- gatherPatchMaterial()
- patchWalls()
- setFace(north)
- depth = depth-1
- y = y+1
- end
- function down()
- attackCount = 0
- if depth >= targetDepth then
- print("Hit target depth")
- return
- end
- if turtle.detectDown() then
- turtle.digDown()
- end
- for i=1,10 do -- This loop trys to handle pests (mobs) that might be in the way
- if turtle.down() then
- break
- end
- turtle.attackDown()
- attackCount = attackCount + 1
- sleep(2)
- end
- if attackCount > 1 then
- turtle.suckDown()
- turtle.suckUp()
- end
- gatherPatchMaterial()
- turtle.select(patchSlot)
- if not turtle.detect() then
- turtle.place()
- end
- turtle.turnLeft()
- if not turtle.detect() then
- turtle.place()
- end
- turtle.turnLeft()
- if not turtle.detect() then
- turtle.place()
- end
- turtle.turnLeft()
- if not turtle.detect() then
- turtle.place()
- end
- turtle.turnLeft()
- depth = depth+1
- y = y-1
- end
- function rise(nBlocks)
- local i
- for i=1,nBlocks do
- turtle.up()
- y = y+1
- end
- end
- function gatherPatchMaterial()
- local i
- patchCount = turtle.getItemCount(patchSlot)
- if patchCount < 5 then
- -- print("Attempting to refill slot ", patchSlot)
- for i=2,13 do
- turtle.select(i)
- if turtle.compareTo(patchSlot) then
- turtle.transferTo(patchSlot, 64-patchCount)
- -- print("Transferred ", 64 - patchCount, " cobble to slot ", patchSlot)
- end
- end
- end
- turtle.select(patchSlot)
- end
- function setFace(f)
- if f == 0 then
- if face == 0 then return end
- if face == 1 then right() return end
- if face == 2 then right() right() return end
- if face == 3 then left() return end
- end
- if f == 1 then
- if face == 0 then left() return end
- if face == 1 then return end
- if face == 2 then right() return end
- if face == 3 then right() right() return end
- end
- if f == 2 then
- if face == 0 then left() left() return end
- if face == 1 then left() return end
- if face == 2 then return end
- if face == 3 then right() return end
- end
- if f == 3 then
- if face == 0 then right() return end
- if face == 1 then left() left() return end
- if face == 2 then left() return end
- if face == 3 then return end
- end
- end
- function placeLadderUp()
- if turtle.getItemCount(ladderSlot) < 1 then
- ladderSlot = ladderSlot - 1
- if turtle.getItemCount(ladderSlot) < 1 then
- ladderSlot = ladderSlot - 1
- if turtle.getItemCount(ladderSlot) < 1 then
- ladderSlot = ladderSlot - 1
- if turtle.getItemCount(ladderSlot) < 1 then
- end
- end
- end
- end
- turtle.select(ladderSlot)
- turtle.placeUp()
- end
- function homeUp()
- setFace(north)
- turtle.select(ladderSlot)
- turtle.suckUp() -- in case we have monster guts on top of us
- while y < 0 do
- turtle.up()
- if not turtle.detectDown() then
- turtle.placeDown()
- end
- y = y+1
- end
- end
- function homeDown()
- setFace(north)
- turtle.select(ladderSlot)
- turtle.suckDown() -- in case we have monster guts on top of us
- while y > 0 do
- turtle.down()
- if not turtle.detectDown() then
- placeLadderUp()
- end
- y = y-1
- end
- end
- -- Main program loop
- if goingUp then
- while depth > targetDepth do
- up()
- end
- homeDown()
- else
- while depth < targetDepth do
- down()
- end
- homeUp()
- end
- setFace(north)
- print(missionMessage)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement