Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- The Water Ferret - by Paul Olinger
- Ever been deep under the ocean and wish there was an easier way to
- go up and back down? Is your nearest stronghold buried deep under
- the ocean? Or maybe you just want to have a deep underwater secret
- base?
- Introducing the water ferret program. This program will go down to
- the deep ocean depths and build an access pipe straight up for you.
- Ideal for trying to reach underground mineshafts, strongholds, or
- other hard to reach places deep under the ocean. As an added bonus,
- it also works on land, and even in lava.
- The program starts out by plummeting down until it detects a block
- which determines where the bottom of the ocean floor is. From there
- , the turtle pierces the ground and builds underground. This is so
- you can mine straight off your new tunnel without hitting water.
- Just running the program without arguments works fine, but there
- are some commands that help improve the building process...
- ARGUMENTS:
- [goto] [x] [y]
- The goto argument tells your turtle where to go to potentially
- start drilling. Placing a turtle down in the middle of the ocean
- isn't that easy unless you have a lilly pad, or some other way of
- getting a block there to place the turtle down. This argument
- exists so you can tell your turtle where to move to.
- If you use the goto argument, the next two arguments MUST be
- numeric values for the coordinates. The turtle's starting location
- is considered x: 0 y: 0, so you determine where you want to move
- from there.
- Example: waterFerret goto 140 -15
- This will move the turtle forward 140 places, then left 15 places.
- If you use the goto argument, the next two arguments must be
- numeric values for the x and y locations. If you don't wish to move
- x or y, then enter a value of zero for that coordinate.
- [force]
- The force argument tells the turtle to immediately start tunneling
- after it reaches the entered goto x and y coordinates.
- Example: waterFerret goto 10 5 force
- This will move the turtle forward 10 places, then right 5 places,
- then it will start tunneling.
- [dock]
- The dock option will append a small area next to the access pipe
- where you can dock your boat. Nothing fancy, but enough to keep
- your boat from drifting away.
- Example: waterFerret dock
- [pierce] [z]
- Using the pierce argument allows you to change the penetration
- depth. The default value is 6. A value of zero would build it right
- at the ocean floor surface. The argument after pierce determines
- your depth. A negative value here also works, which will build
- above the ocean surface somewhere. Not sure how that might be
- useful, but it works. Setting a high value for pierceDepth is
- useful if you're wanting to use this program for land penetration.
- Example: waterFerret dock pierce 10
- This would build a dock, then burrow down under the ocean floor 10
- blocks.
- SLOT PLACEMENT:
- Slots 1 - 13 are for structure blocks.
- Slot 14 is reserved for torches.
- Slot 15 and 16 are for ladders.
- PROGRAM HIGHLIGHTS:
- I have implemented a lot of failsafes for the program so that the
- turtle does not stall at the bottom of an abyss somewhere. Whenever
- the turtle needs something, it will make it's way to the surface.
- The turtle will come to the surface to be refueled, or to get new
- blocks if it happens to run out. Once refueled or restocked, the
- turtle will resume building.
- This program handles obstacles fine, including sand, mobs, etc. If
- the turtle happens to hit bedrock, it will return home and abort
- the mission. This will happen early on, as the turtle starts from
- the bottom up.
- PITFALLS:
- Do not leave any block slot empty. Doing so, the turtle may pick up
- rubble from the ocean floor and then start using that for building.
- This program does not do item checking for torches and ladders. I
- will probably add this soon, as it's fairly trivial to add, but for
- now, make sure the turtle has enough. Even so, this isn't a huge
- deal, as the pipe is pretty much done by the time the program gets
- this far.
- Bedrock if you happen to hit it. If the turtle hits bedrock, it
- will return to the surface and shut down. This will happen early
- in the program if you're going to hit bedrock.
- Happy tunneling!
- ]]--
- local arg = { ... }
- --defaults
- gotoX = nil
- gotoY = nil
- length = 5
- width = 5
- slot = 1
- ctr = 0
- check = 1
- ladderDetect = false
- dock = false
- goto = false
- force = false
- pierceDepth = 6
- fuelAlert = false
- for i = 1, 7 do
- if arg[i] == "dock" then
- dock = true
- end
- if arg[i] == "goto" then
- goto = true
- gotoX = tonumber(arg[i +1])
- gotoY = tonumber(arg[i +2])
- end
- if arg[i] == "pierce" then
- pierceDepth = tonumber(arg[i +1])
- end
- if arg[i] == "force" then
- force = true
- end
- end
- --home coordinates
- homeF = 1 -- 1 == north, 2 east, etc
- homeX = 0
- homeY = 0
- homeZ = 0
- --away coordinates
- awayF = 1
- awayX = 0
- awayY = 0
- awayZ = 0
- --current coordinates
- curF = 1
- curX = 0
- curY = 0
- curZ = 0
- --inner coordinates
- innerF = 0
- innerX = 1
- innerY = 1
- innerZ = -1
- --sweep coordinates
- sweepZ = 0
- --Emergency refill coordinates
- emerF = 0
- emerX = 0
- emerY = 0
- emerZ = 0
- function pushForward()
- local deathcount = 0
- while not turtle.forward() do
- turtle.dig()
- turtle.attack()
- deathcount = deathcount + 1
- if deathcount == 20 then
- goHome()
- print("Bedrock detected. Program aborted.")
- error()
- end
- end
- if curF == 1 then
- curX = curX + 1
- end
- if curF == 2 then
- curY = curY + 1
- end
- if curF == 3 then
- curX = curX - 1
- end
- if curF == 4 then
- curY = curY - 1
- end
- if not fuelAlert then
- checkFuelLevel()
- end
- end
- function pushUpward()
- local deathcount = 0
- while not turtle.up() do
- turtle.digUp()
- turtle.attackUp()
- deathcount = deathcount + 1
- if deathcount == 20 then
- goHome()
- print("Bedrock detected. Program aborted.")
- error()
- end
- end
- curZ = curZ + 1
- if not fuelAlert then
- checkFuelLevel()
- end
- end
- function pushDownward()
- local deathcount = 0
- while not turtle.down() do
- turtle.digDown()
- turtle.attackDown()
- deathcount = deathcount + 1
- if deathcount == 20 then
- goHome()
- print("Bedrock detected. Program aborted.")
- error()
- end
- end
- curZ = curZ - 1
- if not fuelAlert then
- checkFuelLevel()
- end
- end
- function left()
- turtle.turnLeft()
- if curF == 1 then
- curF = 4
- elseif curF == 2 then
- curF = 1
- elseif curF == 3 then
- curF = 2
- elseif curF == 4 then
- curF = 3
- end
- end
- function right()
- turtle.turnRight()
- if curF == 1 then
- curF = 2
- elseif curF == 2 then
- curF = 3
- elseif curF == 3 then
- curF = 4
- elseif curF == 4 then
- curF = 1
- end
- end
- function recordAway()
- awayF = curF
- awayX = curX
- awayY = curY
- awayZ = curZ
- end
- function recordEmergency()
- emerF = curF
- emerX = curX
- emerY = curY
- emerZ = curZ
- end
- function goHome()
- --Go to z axis center
- while curZ < (homeZ) do
- pushUpward()
- end
- -- Go to y axis center
- while curY < homeY do
- while curF ~= 2 do
- left()
- end
- pushForward()
- end
- while curY > homeY do
- while curF ~= 4 do
- left()
- end
- pushForward()
- end
- --Go to x axis center
- while curX < homeX do
- while curF ~= 1 do
- left()
- end
- pushForward()
- end
- while curX > homeX do
- while curF ~= 3 do
- left()
- end
- pushForward()
- end
- while curF ~= 3 do
- left()
- end
- while curZ > homeZ do
- pushDownward()
- end
- right()
- right()
- end
- function widthEven()
- left()
- left()
- for i=2, width do
- pushForward()
- end
- right()
- end
- function widthOdd()
- right()
- end
- function waterPlunge()
- print("Looking for the ocean bottom...")
- while not turtle.detectDown() do
- pushDownward()
- end
- print("Depth determined. Penetrating " .. pierceDepth .. " blocks deep.")
- awayZ = (curZ - pierceDepth)
- goAway()
- end
- function goAway()
- --Go to z axis center
- while curZ < awayZ do
- pushUpward()
- end
- while curZ > awayZ do
- pushDownward()
- end
- -- Go to y axis center
- while curY < awayY do
- while curF ~= 2 do
- left()
- end
- pushForward()
- end
- while curY > awayY do
- while curF ~= 4 do
- left()
- end
- pushForward()
- end
- --Go to x axis center
- while curX < awayX do
- while curF ~= 1 do
- left()
- end
- pushForward()
- end
- while curX > awayX do
- while curF ~= 3 do
- left()
- end
- pushForward()
- end
- while curF ~= awayF do
- left()
- end
- while curZ > awayZ do
- pushDownward()
- end
- end
- function goInner()
- pushDownward()
- -- Go to y axis center
- while curY < innerY do
- while curF ~= 2 do
- left()
- end
- pushForward()
- end
- while curY > innerY do
- while curF ~= 4 do
- left()
- end
- pushForward()
- end
- --Go to x axis center
- while curX < innerX do
- while curF ~= 1 do
- left()
- end
- pushForward()
- end
- while curX > innerX do
- while curF ~= 3 do
- left()
- end
- pushForward()
- end
- while curF ~= innerF do
- left()
- end
- --Only ever runs once
- if check == 1 then
- pushDownward()
- check = nil
- end
- end
- function goEmergency()
- print("Returning to work...")
- -- Go to y axis center
- while curY < emerY do
- while curF ~= 2 do
- left()
- end
- pushForward()
- end
- while curY > emerY do
- while curF ~= 4 do
- left()
- end
- pushForward()
- end
- --Go to x axis center
- while curX < emerX do
- while curF ~= 1 do
- left()
- end
- pushForward()
- end
- while curX > emerX do
- while curF ~= 3 do
- left()
- end
- pushForward()
- end
- while curF ~= 3 do
- left()
- end
- --Go to z axis center
- while curZ < emerZ do
- pushUpward()
- end
- while curZ > emerZ do
- pushDownward()
- end
- while curF ~= emerF do
- right()
- end
- end
- function buildWall()
- turtle.select(slot)
- local depth = awayZ
- while depth ~= homeZ + 1 do
- --Every 4 passes will reset slot to 1 in case the turtle
- -- is filled with blocks while running
- if depth % 4 == 1 then
- slot = 1
- turtle.select(slot)
- end
- --repeats the next for loops twice to make a complete pass
- for squareCount = 1, 2 do
- for count = 2, length do
- pushForward()
- checkInventorySlot()
- if turtle.detectDown() then
- turtle.digDown()
- end
- --This skips the corners to save blocks
- if count ~= length then
- turtle.placeDown()
- end
- end
- right()
- for count = 2, width do
- pushForward()
- checkInventorySlot()
- if turtle.detectDown() then
- turtle.digDown()
- end
- if count ~= width then
- turtle.placeDown()
- end
- end
- right()
- end
- pushUpward()
- depth = depth + 1
- end
- end
- function clearBottom()
- turtle.select(slot)
- local widthCounter = 1
- local directionCounter = 2
- local innerWidth = width - 2
- local innerLength = length - 2
- while widthCounter <= innerWidth do
- --Every 4 passes will reset slot to 1 if turtle is filled
- --with blocks while running
- if widthCounter % 4 == 1 then
- slot = 1
- turtle.select(slot)
- end
- --for loop goes forward to the value entered for length
- for i=2, innerLength do
- if ctr == 0 and (not ladderDetect) then
- turtle.digDown()
- end
- checkInventorySlot()
- if ctr == 0 then
- turtle.placeDown()
- end
- pushForward()
- end
- if directionCounter % 2 ~= 1 then
- right()
- if ctr == 0 then
- if (not ladderDetect) then
- turtle.digDown()
- end
- checkInventorySlot()
- turtle.placeDown()
- end
- if widthCounter < innerWidth then
- pushForward()
- right()
- end
- else
- left()
- if ctr == 0 then
- if not ladderDetect then
- turtle.digDown()
- end
- checkInventorySlot()
- turtle.placeDown()
- end
- if widthCounter < innerWidth then
- pushForward()
- left()
- end
- end
- widthCounter = widthCounter + 1
- directionCounter = directionCounter + 1
- end
- if innerWidth % 2 == 0 then
- widthEven()
- else
- widthOdd()
- end
- ctr = nil
- end
- function recordBottom()
- innerF = curF
- innerX = curX
- innerY = curY
- end
- function checkInventorySlot()
- local toggle --Gatekeeper. Must be set to "go" before turtle will continue.
- while turtle.getItemCount(slot) == 1 do
- slot = slot + 1
- --Turtle is empty. Fill the slots and reset slot to 1.
- if slot == 14 then
- recordEmergency()
- goHome()
- print("\nTurtle needs more blocks! Please reload.")
- print("Type 'go' to continue after reloading")
- toggle = io.read()
- while toggle ~= "go" do
- print("Please type 'go' and hit enter")
- toggle = io.read()
- end
- --Setting slot back to one after turtle is refilled and returning slot back to 2
- slot = 1
- turtle.select(slot)
- goEmergency()
- end
- --switches to the next slot
- turtle.select(slot)
- end
- end
- function checkFuelLevel()
- if turtle.getFuelLevel() < 150 then
- recordEmergency()
- fuelAlert = true
- goHome()
- end
- while turtle.getFuelLevel() < 150 do
- print("\nTurtle needs more Fuel! Insert fuel sources in any slot. Then,")
- print("replace your slots with building materials when you're done.")
- print("Type 'go' to begin refueling.")
- toggle = io.read()
- while toggle ~= "go" do
- print("Please type 'go' and hit enter")
- toggle = io.read()
- end
- refuelTurtle()
- end
- if turtle.getFuelLevel() > 150 and fuelAlert then
- print("Turtle refilled. Type 'go' to return to the depths ")
- print("after reloading building materials.")
- toggle = io.read()
- while toggle ~= "go" do
- print("Please type 'go' and hit enter")
- toggle = io.read()
- end
- fuelAlert = false
- goEmergency()
- end
- end
- function refuelTurtle()
- for i = 1, 16 do
- turtle.select(i)
- turtle.refuel()
- end
- turtle.select(slot)
- end
- function buildBoatDock()
- print("Building dock...")
- left()
- pushForward()
- turtle.placeDown()
- pushForward()
- turtle.placeDown()
- pushForward()
- turtle.placeDown()
- pushForward()
- turtle.placeDown()
- right()
- pushUpward()
- turtle.select(14)
- turtle.placeDown()
- turtle.select(slot)
- pushForward()
- pushDownward()
- pushForward()
- pushForward()
- pushForward()
- right()
- turtle.placeDown()
- pushUpward()
- turtle.select(14)
- turtle.placeDown()
- pushForward()
- pushDownward()
- turtle.select(slot)
- turtle.placeDown()
- pushForward()
- turtle.placeDown()
- pushForward()
- turtle.placeDown()
- pushForward()
- print("Dock completed.")
- goHome()
- end
- function buildLadder()
- local num = 3
- pushForward()
- right()
- pushForward()
- if (curZ + 200) % 2 == 1 then
- right()
- right()
- end
- while curZ ~= (homeZ) do
- turtle.select(15)
- if turtle.select(15) == 0 then
- turtle.select(16)
- end
- turtle.place()
- pushUpward()
- if num % 5 == 0 and (curZ ~= homeZ - 1) then
- right()
- right()
- turtle.select(14)
- turtle.place()
- right()
- right()
- end
- num = num + 1
- end
- end
- function findStartingPoint()
- --Go to x axis center
- while curX < gotoX do
- while curF ~= 1 do
- left()
- end
- pushForward()
- end
- while curX > gotoX do
- while curF ~= 3 do
- left()
- end
- pushForward()
- end
- while curF ~= 3 do
- left()
- end
- -- Go to y axis center
- while curY < gotoY do
- while curF ~= 2 do
- left()
- end
- pushForward()
- end
- while curY > gotoY do
- while curF ~= 4 do
- left()
- end
- pushForward()
- end
- end
- --******************************* Main
- if goto then
- findStartingPoint()
- while curF ~= 1 do
- right()
- end
- if force then
- curX = 0
- curY = 0
- end
- end
- --Remove initial marker block just in case it was left.
- if turtle.detectDown() then
- turtle.digDown()
- end
- -- Will not run with the goto option unless force is true
- if not goto or force then
- print("Turtle is on a mission...")
- turtle.select(slot)
- if dock then
- buildBoatDock()
- end
- waterPlunge()
- right()
- pushForward()
- left()
- pushForward()
- recordBottom()
- clearBottom()
- goAway()
- buildWall()
- goInner()
- while curZ ~= awayZ do
- clearBottom()
- pushDownward()
- end
- clearBottom()
- buildLadder()
- goHome()
- pushForward()
- right()
- pushForward()
- left()
- --New values for clearBottom()
- ctr = 0
- ladderDetect = true
- clearBottom()
- --Just a few remaining details with torches
- turtle.select(14)
- right()
- right()
- turtle.place()
- right()
- right()
- pushForward()
- pushForward()
- turtle.place()
- right()
- pushForward()
- goHome()
- print("Mission Completed!")
- print(turtle.getFuelLevel() .. " units of fuel remaining.")
- end
Add Comment
Please, Sign In to add comment