Advertisement
Guest User

Untitled

a guest
Dec 15th, 2019
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.00 KB | None | 0 0
  1. function isblock_f(id)
  2. local success, data = turtle.inspect()
  3. if success then
  4. if id == data.name then
  5. return true
  6. end
  7. end
  8. end
  9.  
  10. function isblock_l(id)
  11. turtle.turnLeft()
  12. local success, data = turtle.inspect()
  13. turtle.turnRight()
  14. if success then
  15. if id == data.name then
  16. return true
  17. end
  18. end
  19. end
  20.  
  21. function isblock_r(id)
  22. turtle.turnRight()
  23. local success, data = turtle.inspect()
  24. turtle.turnLeft()
  25. if success then
  26. if id == data.name then
  27. return true
  28. end
  29. end
  30. end
  31.  
  32. function isblock_u(id)
  33. local success, data = turtle.inspectUp()
  34. if success then
  35. if id == data.name then
  36. return true
  37. end
  38. end
  39. end
  40.  
  41. function isblock_d(id)
  42. local success, data = turtle.inspectDown()
  43. if success then
  44. if id == data.name then
  45. return true
  46. end
  47. end
  48. end
  49.  
  50. function isblock_b(id)
  51. turtle.turnLeft()
  52. turtle.turnLeft()
  53. local success, data = turtle.inspect()
  54. turtle.turnRight()
  55. turtle.turnRight()
  56. if success then
  57. if id == data.name then
  58. return true
  59. end
  60. end
  61. end
  62.  
  63. -- Stack Table
  64. -- Uses a table as stack, use <table>:push(value) and <table>:pop()
  65. -- Lua 5.1 compatible
  66.  
  67. -- GLOBAL
  68. Stack = Core.class()
  69.  
  70. function Stack:init(list)
  71.  
  72. if not list then
  73. -- create an empty stack
  74. self.stack = {}
  75. else
  76. -- initialise the stack
  77. self.stack = list
  78. end
  79. end
  80.  
  81. function Stack:push(item)
  82. -- put an item on the stack
  83. self.stack[#self.stack+1] = item
  84. end
  85.  
  86. function Stack:pop()
  87. -- make sure there's something to pop off the stack
  88. if #self.stack > 0 then
  89. -- remove item (pop) from stack and return item
  90. return table.remove(self.stack, #self.stack)
  91. end
  92. end
  93.  
  94. function Stack:iterator()
  95. -- wrap the pop method in a function
  96. return function()
  97. -- call pop to iterate through all items on a stack
  98. return self:pop()
  99. end
  100. end
  101.  
  102. orestack = Stack.new()
  103.  
  104. function minevein(id)
  105. if isblock_f(id) then
  106. print("f")
  107. turtle.dig()
  108. orestack:push("f")
  109. turtle.forward()
  110. return minevein(id)
  111. end
  112. if isblock_u(id) then
  113. print("u")
  114. turtle.digUp()
  115. orestack:push("u")
  116. turtle.up()
  117. return minevein(id)
  118. end
  119. if isblock_d(id) then
  120. print("d")
  121. turtle.digDown()
  122. orestack:push("d")
  123. turtle.down()
  124. return minevein(id)
  125. end
  126. turtle.turnLeft()
  127. if isblock_f(id) then
  128. print("l")
  129. turtle.dig()
  130. orestack:push("l")
  131. turtle.forward()
  132. return minevein(id)
  133. end
  134. turtle.turnLeft()
  135. if isblock_f(id) then
  136. print("b")
  137. turtle.dig()
  138. orestack:push("b")
  139. turtle.forward()
  140. return minevein(id)
  141. end
  142. turtle.turnLeft()
  143. if isblock_f(id) then
  144. print("r")
  145. turtle.dig()
  146. orestack:push("r")
  147. turtle.forward()
  148. return minevein(id)
  149. end
  150.  
  151. last_mov = orestack:pop()
  152. if last_mov then
  153. if last_mov == "u" then
  154. turtle.down()
  155. return minevein(id)
  156. elseif last_mov == "d" then
  157. turtle.up()
  158. return minevein(id)
  159. else
  160. turtle.back()
  161. return minevein(id)
  162. end
  163. end
  164. end
  165.  
  166. turtle.refuel(5)
  167. print(turtle.getFuelLevel())
  168. minevein("minecraft:dirt")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement