neo34rd

scanbranchminer.lua

Apr 19th, 2019
318
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.01 KB | None | 0 0
  1. --os.loadAPI("stack")
  2.  
  3. input_table = {}
  4.  
  5. function loadWorthyOres()
  6. local file = fs.open("ore_worthy", "r")
  7. local fileData = {}
  8. line = nil
  9. repeat
  10. line = file.readLine()
  11. if line ~= nil then
  12. fileData[line] = true
  13. end
  14. until line == nil
  15. file.close()
  16. return fileData
  17. end
  18.  
  19. function isTargeted(oreName)
  20. if input_table.targets[oreName] ~= nil then
  21. return true
  22. end
  23. return false
  24. end
  25.  
  26.  
  27. function recordLast()
  28. local p = input_table.t.position
  29. local f = input_table.t.forward
  30. stack.push(input_table.sPos, vector.make(p.x, p.y, p.z))
  31. stack.push(input_table.sFor, vector.make(f.x, f.y, f.z))
  32. end
  33.  
  34.  
  35. function getLast()
  36. local p = stack.pop(input_table.sPos)
  37. local f = stack.pop(input_table.sFor)
  38. return p, f
  39. end
  40.  
  41.  
  42. function backTrack()
  43. p, f = getLast()
  44. digGoto(input_table.t, p)
  45. transformation.face(input_table.t, f)
  46. end
  47.  
  48.  
  49. function digTrace(digFunc, moveFunc)
  50. recordLast()
  51. digFunc()
  52. moveFunc()
  53. end
  54.  
  55.  
  56. function forward()
  57. while turtle.detect() do
  58. turtle.dig()
  59. end
  60. transformation.forward(input_table.t)
  61. end
  62.  
  63.  
  64. function up()
  65. sleep(0.6)
  66. while turtle.detectUp() do
  67. sleep(0.6)
  68. turtle.digUp()
  69. end
  70. transformation.up(input_table.t)
  71. end
  72.  
  73.  
  74. function down()
  75. while turtle.detectDown() do
  76. turtle.digDown()
  77. end
  78. transformation.down(input_table.t)
  79. end
  80.  
  81.  
  82. --- Dig until the turtle can move
  83. function digGoto(t, pos)
  84. transformation.gotoPosition(t, pos)
  85. while t.ret == false do
  86. --TODO: Find out which direction goto is trying to move
  87. turtle.dig()
  88. turtle.digUp()
  89. turtle.digDown()
  90. transformation.gotoPosition(t, pos)
  91. end
  92. end
  93.  
  94.  
  95. function scanHorizontal()
  96. success, data = turtle.inspect()
  97. if isTargeted(data.name) then
  98. digTrace(turtle.dig, forward)
  99. scanAll()
  100. backTrack()
  101. end
  102. for i = 0, 3 do
  103. success, data = turtle.inspect()
  104. if isTargeted(data.name) then
  105. digTrace(turtle.dig, forward)
  106. scanAll()
  107. backTrack()
  108. end
  109. transformation.turnLeft(input_table.t)
  110. end
  111. end
  112.  
  113.  
  114. function scanVertical()
  115. success, data = turtle.inspectUp()
  116. if isTargeted(data.name) then
  117. digTrace(turtle.digUp, up)
  118. scanAll()
  119. backTrack()
  120. end
  121.  
  122. success, data = turtle.inspectDown()
  123. if isTargeted(data.name) then
  124. digTrace(turtle.digDown, down)
  125. scanAll()
  126. backTrack()
  127. end
  128. end
  129.  
  130.  
  131. function scanAll()
  132. scanHorizontal()
  133. scanVertical()
  134. end
  135.  
  136.  
  137. function scanAllStart(transform, position_stack, forward_stack, worthy_ores)
  138. input_table["t"] = transform
  139. input_table["sPos"] = position_stack
  140. input_table["sFor"] = forward_stack
  141. input_table["targets"] = worthy_ores
  142. scanAll()
  143. end
  144.  
  145.  
  146. -- sPos = stack.newStack()
  147. -- sFor = stack.newStack()
  148. -- targets = loadWorthyOres()
  149. -- scanAll()
Advertisement
Add Comment
Please, Sign In to add comment