DrFair

Ore search

Feb 12th, 2013
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.13 KB | None | 0 0
  1. Args = {...}
  2. dirDown = true
  3. found = 0
  4. dug = 0
  5.  
  6. function printUsage()
  7. print("Usage:")
  8. print("Place block in first slot.")
  9. print("search <TIMES> <HEIGHT>")
  10. end
  11.  
  12. function digFor()
  13. if turtle.dig() or not turtle.detect() then
  14. os.sleep(0.5)
  15. while turtle.detect() do
  16. turtle.dig()
  17. os.sleep(0.5)
  18. end
  19. return turtle.forward()
  20. else
  21. return false
  22. end
  23. end
  24.  
  25. function digDown()
  26. if checkDown() then
  27. dug = dug + 1
  28. end
  29. if turtle.digDown() or not turtle.detectDown() then
  30. return turtle.down()
  31. else
  32. return false
  33. end
  34. end
  35.  
  36. function digUp()
  37. if checkUp() then
  38. dug = dug + 1
  39. end
  40. if turtle.digUp() or not turtle.detectUp() then
  41. return turtle.up()
  42. else
  43. return false
  44. end
  45. end
  46.  
  47. function check()
  48. turtle.select(1)
  49. return turtle.compare()
  50. end
  51.  
  52. function checkUp()
  53. turtle.select(1)
  54. return turtle.compareUp()
  55. end
  56.  
  57. function checkDown()
  58. turtle.select(1)
  59. return turtle.compareDown()
  60. end
  61.  
  62. function digAround()
  63. for i=1,4 do
  64. if check() then
  65. found = found + 1
  66. else
  67. while turtle.detect() do
  68. turtle.dig()
  69. os.sleep(0.5)
  70. end
  71. end
  72. turtle.turnRight()
  73. end
  74. end
  75.  
  76. function search()
  77. if dirDown then
  78. if digDown() then
  79. y = y - 1
  80. end
  81. else
  82. if digUp() then
  83. y = y + 1
  84. end
  85. end
  86. digAround()
  87. end
  88.  
  89. function reset()
  90. while y < starty do
  91. if digUp() then
  92. y = y + 1
  93. end
  94. end
  95. while y > starty do
  96. if digDown() then
  97. y = y - 1
  98. end
  99. end
  100. end
  101.  
  102. function cycle()
  103. if dirDown then
  104. while y > 2 do
  105. search()
  106. end
  107. else
  108. while y < starty do
  109. search()
  110. end
  111. end
  112. dirDown = not dirDown
  113. if cycles < tonumber(Args[1]) then
  114. for i=1,3 do
  115. digFor()
  116. end
  117. digAround()
  118. end
  119. end
  120.  
  121. if #Args ~= 2 then
  122. printUsage()
  123. else
  124. if tonumber(Args[1]) == 0 and tonumber(Args[2]) == 0 then
  125. printUsage()
  126. else
  127. print("Searching...")
  128. y = tonumber(Args[2])
  129. starty = tonumber(Args[2])
  130. cycles = 1
  131. for i=1,tonumber(Args[1]) do
  132. cycle()
  133. cycles = cycles + 1
  134. end
  135. print("Done searching. Resetting.")
  136. reset()
  137. end
  138. print("Found "..found.." matched block(s) and")
  139. print("Dug "..dug.." matched block(s).")
  140. end
Advertisement
Add Comment
Please, Sign In to add comment