Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local X = 0
- local Y = 0
- local Z = 0
- local Rotation = 0
- local User_Tags = {}
- local temp = 0
- print("This program uses a chunk loader, diamond pick, geoscanner, Water bucket, and fuel")
- print("The chunk loader should be equiped in the turtles left side prior to running")
- print("Fuel goes into the first inventory slot. Geoscanner in second, and bucket in third")
- print("Enter Desired Length")
- Length = tonumber(io.read())
- print("Enter Desired number of tunnels. Must be even")
- Tunnels = tonumber(io.read())
- Space = 16
- print("Enter the Block tags you'd like to scan for")
- print("Enter stop when done. Case sensitive")
- while temp ~= "stop"
- do
- temp = io.read()
- User_Tags[temp] = true
- print(User_Tags[temp])
- end
- Fuel = ((Length*Tunnels+(2*Space))/100)
- print(Fuel .. "Coal Needed for program. y/n to continue")
- answer = io.read()
- Location = vector.new(0,0,0)
- Ore_Location = vector.new(0,0,0)
- Scan_Location = vector.new(0,0,0)
- function Scan()
- print("scanning")
- local continue = true
- Scan_Location.x = X
- Scan_Location.y = Y
- Scan_Location.z = Z
- if turtle.getItemDetail(2).name == "advancedperipherals:geo_scanner"
- then
- turtle.select(2)
- turtle.equipRight()
- end
- Geoscan = peripheral.wrap('right')
- local scan = Geoscan.scan(8)
- for i, Scan_data in ipairs(scan) do
- if Scan_data.tags and continue == true
- then
- for i, Tag_data in ipairs(Scan_data.tags) do
- if User_Tags[Tag_data] == true
- then
- Ore_Location.x = Scan_data.x * -1 + Scan_Location.x
- Ore_Location.y = Scan_data.z + Scan_Location.y
- Ore_Location.z = Scan_data.y + Scan_Location.z
- if Ore_Location.x ~= Scan_Location.x and Ore_Location.z < 3 and Ore_Location.z > -3 and Ore_Location.x > Location.x -8 and Ore_Location.x < Location.x + 8
- and Ore_Location.y < Location.y + 8 and Ore_Location.y > Location.y - 8
- then
- print("Found Ore")
- continue = false
- if turtle.getItemDetail(2).name == "minecraft:diamond_pickaxe"
- then
- turtle.select(2)
- turtle.equipRight()
- end
- FindOre()
- Scan()
- Return()
- end
- end
- end
- end
- end
- if continue == false
- then
- Scan()
- end
- if turtle.getItemDetail(2).name == "minecraft:diamond_pickaxe"
- then
- turtle.select(2)
- turtle.equipRight()
- end
- end
- function FindOre()
- CheckInvOre()
- while Ore_Location.x < X
- do
- ALeft()
- Mine()
- end
- while Ore_Location.x > X
- do
- ARight()
- Mine()
- end
- while Ore_Location.y < Y
- do
- ABack()
- Mine()
- end
- while Ore_Location.y > Y
- do
- AForward()
- Mine()
- end
- while Ore_Location.z < Z
- do
- Down()
- end
- while Ore_Location.z > Z
- do
- Up()
- end
- end
- function SetReturn()
- Location.x = X
- Location.y = Y
- Location.z = Z
- end
- function Inspect()
- local success, data = turtle.inspect()
- if success then
- if data.name == "forbidden_arcanus:stella_arcanum"
- then
- turtle.select(3)
- Up()
- turtle.digUp()
- Down()
- turtle.placeUp()
- turtle.dig()
- turtle.select(3)
- turtle.placeUp()
- return "false"
- elseif data.state.level
- then
- print("Water")
- return "false"
- else
- return success
- end
- end
- end
- function InspectUp()
- local success, data = turtle.inspectUp()
- if success then
- if data.name == "forbidden_arcanus:stella_arcanum"
- then
- turtle.select(3)
- turtle.placeUp()
- turtle.digUp()
- turtle.select(3)
- turtle.placeUp()
- return "false"
- elseif data.state.level
- then
- return "false"
- else
- return success
- end
- end
- end
- function InspectDown()
- local success, data = turtle.inspectDown()
- if success then
- if data.name == "forbidden_arcanus:stella_arcanum"
- then
- turtle.select(3)
- Up()
- turtle.digUp()
- Down()
- turtle.placeUp()
- turtle.digDown()
- turtle.select(3)
- turtle.placeUp()
- return "false"
- elseif data.state.level
- then
- print("Water")
- return "false"
- else
- return success
- end
- end
- end
- function Forward()
- if turtle.getFuelLevel() == 0
- then
- turtle.select(1)
- turtle.refuel(1)
- end
- while (Inspect() == true)
- do
- turtle.dig()
- end
- turtle.forward()
- HorizontalPos()
- end
- function Up()
- if turtle.getFuelLevel() == 0
- then
- turtle.select(1)
- turtle.refuel(1)
- end
- while (InspectUp() == true)
- do
- turtle.digUp()
- end
- turtle.up()
- Z = Z + 1
- end
- function Down()
- if turtle.getFuelLevel() == 0
- then
- turtle.select(1)
- turtle.refuel(1)
- end
- while (InspectDown() == true)
- do
- turtle.digDown()
- end
- turtle.down()
- Z = Z - 1
- end
- -- HorizontalPos Counts location variables according to Rotation. Can be used to record turtle position
- function HorizontalPos()
- if Rotation == 0
- then
- Y = (Y+1)
- elseif Rotation == 1
- then
- X = (X+1)
- elseif Rotation == 2
- then
- Y = (Y-1)
- elseif Rotation == 3
- then X = (X-1)
- end
- end
- -- TurnRight & TurnLeft record direction turtle is facing while rotating
- function TurnRight()
- turtle.turnRight()
- if Rotation == 0
- then
- Rotation = 1
- elseif Rotation == 1
- then
- Rotation = 2
- elseif Rotation == 2
- then
- Rotation = 3
- elseif Rotation == 3
- then Rotation = 0
- end
- end
- function TurnLeft()
- turtle.turnLeft()
- if Rotation == 0
- then
- Rotation = 3
- elseif Rotation == 3
- then
- Rotation = 2
- elseif Rotation == 2
- then
- Rotation = 1
- elseif Rotation == 1
- then
- Rotation = 0
- end
- end
- -- A Movement functions are absolute movement relative to the direction the turtle was placed in
- function ARight()
- if Rotation == 0
- then
- TurnRight()
- Forward()
- elseif Rotation == 1
- then
- Forward()
- elseif Rotation == 2
- then
- TurnLeft()
- Forward()
- elseif Rotation == 3
- then
- TurnRight()
- TurnRight()
- Forward()
- end
- end
- function ALeft()
- if Rotation == 2
- then
- TurnRight()
- Forward()
- elseif Rotation == 3
- then
- Forward()
- elseif Rotation == 0
- then
- TurnLeft()
- Forward()
- elseif Rotation == 1
- then
- TurnRight()
- TurnRight()
- Forward()
- end
- end
- function AForward()
- if Rotation == 3
- then
- TurnRight()
- Forward()
- elseif Rotation == 0
- then
- Forward()
- elseif Rotation == 1
- then
- TurnLeft()
- Forward()
- elseif Rotation == 2
- then
- TurnRight()
- TurnRight()
- Forward()
- end
- end
- function ABack()
- if Rotation == 1
- then
- TurnRight()
- Forward()
- elseif Rotation == 2
- then
- Forward()
- elseif Rotation == 3
- then
- TurnLeft()
- Forward()
- elseif Rotation == 0
- then
- TurnRight()
- TurnRight()
- Forward()
- end
- end
- function Home()
- SetReturn()
- while(X > 0)
- do
- ALeft()
- end
- while(Y>0)
- do
- ABack()
- end
- while Rotation ~= 3
- do
- TurnRight()
- end
- end
- function HomeOre()
- while(Z>0)
- do
- Down()
- end
- while(Z<0)
- do
- Up()
- end
- while(X < 0)
- do
- ARight()
- end
- while(Y < 0)
- do
- AForward()
- end
- while(X > 0)
- do
- ALeft()
- Mine()
- end
- while(Y>0)
- do
- ABack()
- end
- while Rotation ~= 3
- do
- TurnRight()
- end
- end
- function Return()
- while(Z>0)
- do
- Down()
- end
- while(Z<0)
- do
- Up()
- end
- while(X<Location.x)
- do
- ARight()
- Mine()
- end
- while(X>Location.x)
- do
- ALeft()
- Mine()
- end
- while(Y<Location.y)
- do
- AForward()
- end
- while(Y>Location.y)
- do
- ABack()
- end
- end
- function Mine()
- if InspectUp() == true
- then
- turtle.digUp()
- end
- if InspectDown() == true
- then
- turtle.digDown()
- end
- end
- function CheckInv()
- if turtle.getItemCount(16) > 0
- then
- Home()
- Empty()
- Return()
- end
- end
- function CheckInvOre()
- if turtle.getItemCount(16) > 0
- then
- HomeOre()
- Empty()
- Return()
- end
- end
- -- Empties inventory except for 1st slot (reserved for fuel)
- function Empty()
- for i =4, 16, 1
- do
- turtle.select(i)
- turtle.drop()
- end
- turtle.select(1)
- end
- function Strip()
- local counter = 0
- while X < Tunnels * Space
- do
- while Y < Length
- do
- AForward()
- CheckInv()
- counter = counter + 1
- print(Y)
- if counter == 8
- then
- SetReturn()
- Scan()
- counter = 0
- end
- end
- if X < Tunnels * Space
- then
- for i = 0, Space, 1
- do
- ARight()
- Mine()
- end
- else
- home()
- os.shutdown()
- end
- while Y > 0
- do
- ABack()
- CheckInv()
- counter = counter + 1
- if counter == 8
- then
- SetReturn()
- Scan()
- counter = 0
- end
- end
- for i = 0, Space, 1
- do
- ARight()
- Mine()
- end
- end
- end
- if answer == "y"
- then
- Strip()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement