Advertisement
Guest User

Untitled

a guest
Apr 29th, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.64 KB | None | 0 0
  1. local mode = "spiral" -- Has to be either "spiral" or "excavate"
  2.  
  3. -- Excavate config (starts at the bottom left corner of designated area)
  4.  
  5. local depth = 100
  6. local height = 3;
  7. local width = 20;
  8.  
  9. -- Spiral mining config
  10.  
  11. local radius = 30
  12.  
  13. -- ===================================
  14.  
  15. -- Mapping turtle position along a new x, y, z coordinate system (turtle starts at 0, 0, 0 facing positive x)
  16.  
  17. local posX = 0
  18. local posY = 0
  19. local posZ = 0
  20.  
  21. local facing = 0; -- 0: positive x / 1: positive z / 2: negative x / 3: negative z
  22.  
  23. -- Ore inspection methods
  24.  
  25. function isOreUp()
  26. local success, block = turtle.inspectUp()
  27.  
  28. if success then
  29. if string.match(block.name, "ore") or string.match(block.name, "Ore") then
  30. return true
  31. end
  32. end
  33. end
  34.  
  35. function isOreDown()
  36. local success, block = turtle.inspectDown()
  37.  
  38. if success then
  39. if string.match(block.name, "ore") or string.match(block.name, "Ore") then
  40. return true
  41. end
  42. end
  43. end
  44.  
  45. function isOre()
  46. local success, block = turtle.inspect()
  47.  
  48. if success then
  49. if string.match(block.name, "ore") or string.match(block.name, "Ore") then
  50. return true
  51. end
  52. end
  53. end
  54.  
  55. -- Movement/mining methods
  56.  
  57. function forceUp()
  58. turtle.digUp()
  59. moveUp()
  60. end
  61.  
  62. function forceForward()
  63. turtle.dig()
  64. moveForward()
  65. end
  66.  
  67. function forceDown()
  68. turtle.digDown()
  69. moveDown()
  70. end
  71.  
  72. function moveUp()
  73. turtle.up()
  74. posY = posY + 1
  75. end
  76.  
  77. function moveDown()
  78. turtle.down()
  79. posY = posY - 1
  80. end
  81.  
  82. function moveForward()
  83. turtle.forward()
  84.  
  85. if facing == 0 then
  86. posX = posX + 1
  87. elseif facing == 1 then
  88. posZ = posZ + 1
  89. elseif facing == 2 then
  90. posX = posX - 1
  91. elseif facing == 3 then
  92. posZ = posZ - 1
  93. end
  94. end
  95.  
  96. function moveBack()
  97. turtle.back()
  98.  
  99. if facing == 0 then
  100. posX = posX - 1
  101. elseif facing == 1 then
  102. posZ = posZ - 1
  103. elseif facing == 2 then
  104. posX = posX + 1
  105. elseif facing == 3 then
  106. posZ = posZ + 1
  107. end
  108. end
  109.  
  110. function turnRight()
  111. turtle.turnRight()
  112.  
  113. if facing < 3 then
  114. facing = facing + 1
  115. else
  116. facing = 0
  117. end
  118. end
  119.  
  120. function turnLeft()
  121. turtle.turnLeft()
  122.  
  123. if facing > 0 then
  124. facing = facing - 1
  125. else
  126. facing = 3
  127. end
  128. end
  129.  
  130. -- Mining methods
  131.  
  132. function mineVein()
  133. if isOreUp() then
  134. forceUp()
  135. mineVein()
  136. turtle.down()
  137. end
  138.  
  139. if isOreDown() then
  140. forceDown()
  141. mineVein()
  142. turtle.up()
  143. end
  144.  
  145. for i=0, 3 do
  146. if isOre() then
  147. forceForward()
  148. mineVein()
  149. turtle.back()
  150. end
  151.  
  152. turtle.turnRight()
  153. end
  154. end
  155.  
  156. function mineSpiral()
  157.  
  158. end
  159.  
  160. -- Position retrieval methods
  161.  
  162. function getDistanceToStart()
  163. return tostring(vector.new(posX, posY, posZ) - vector.new(0, 0, 0))
  164. end
  165.  
  166. -- Main method
  167.  
  168. function main()
  169. print("==== Fredriks Miner v1.0 ====")
  170. print()
  171.  
  172. if mode == "spiral" then
  173. mineSpiral()
  174. elseif mode == "excavate" then
  175. mineExcavate()
  176. else
  177. print("[Error] Please set mode to either 'spiral' or 'excavate'")
  178. end
  179. end
  180.  
  181. print(getDistanceToStart())
  182. moveForward()
  183. print(getDistanceToStart())
  184. moveForward()
  185. print(getDistanceToStart())
  186. turnRight()
  187. print(getDistanceToStart())
  188. moveForward()
  189. print(getDistanceToStart())
  190. moveForward()
  191. print(getDistanceToStart())
  192. moveForward()
  193. print(getDistanceToStart())
  194. moveUp()
  195. getDistanceToStart()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement