Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Args = {...}
- dirDown = true
- found = 0
- dug = 0
- function printUsage()
- print("Usage:")
- print("Place block in first slot.")
- print("search <TIMES> <HEIGHT>")
- end
- function digFor()
- if turtle.dig() or not turtle.detect() then
- os.sleep(0.5)
- while turtle.detect() do
- turtle.dig()
- os.sleep(0.5)
- end
- return turtle.forward()
- else
- return false
- end
- end
- function digDown()
- if checkDown() then
- dug = dug + 1
- end
- if turtle.digDown() or not turtle.detectDown() then
- return turtle.down()
- else
- return false
- end
- end
- function digUp()
- if checkUp() then
- dug = dug + 1
- end
- if turtle.digUp() or not turtle.detectUp() then
- return turtle.up()
- else
- return false
- end
- end
- function check()
- turtle.select(1)
- return turtle.compare()
- end
- function checkUp()
- turtle.select(1)
- return turtle.compareUp()
- end
- function checkDown()
- turtle.select(1)
- return turtle.compareDown()
- end
- function digAround()
- for i=1,4 do
- if check() then
- found = found + 1
- else
- while turtle.detect() do
- turtle.dig()
- os.sleep(0.5)
- end
- end
- turtle.turnRight()
- end
- end
- function search()
- if dirDown then
- if digDown() then
- y = y - 1
- end
- else
- if digUp() then
- y = y + 1
- end
- end
- digAround()
- end
- function reset()
- while y < starty do
- if digUp() then
- y = y + 1
- end
- end
- while y > starty do
- if digDown() then
- y = y - 1
- end
- end
- end
- function cycle()
- if dirDown then
- while y > 2 do
- search()
- end
- else
- while y < starty do
- search()
- end
- end
- dirDown = not dirDown
- if cycles < tonumber(Args[1]) then
- for i=1,3 do
- digFor()
- end
- digAround()
- end
- end
- if #Args ~= 2 then
- printUsage()
- else
- if tonumber(Args[1]) == 0 and tonumber(Args[2]) == 0 then
- printUsage()
- else
- print("Searching...")
- y = tonumber(Args[2])
- starty = tonumber(Args[2])
- cycles = 1
- for i=1,tonumber(Args[1]) do
- cycle()
- cycles = cycles + 1
- end
- print("Done searching. Resetting.")
- reset()
- end
- print("Found "..found.." matched block(s) and")
- print("Dug "..dug.." matched block(s).")
- end
Advertisement
Add Comment
Please, Sign In to add comment