Advertisement
willthamic

mine

Dec 29th, 2020 (edited)
21
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.82 KB | None | 0 0
  1. local centralLoc = {x=-149,y=8,z=-85}
  2.  
  3. --local base1 =
  4.  
  5. local dumpChestLoc = {x=-147, y=6, z=-97}
  6. local fuelChestLoc = {x=-147, y=6, z=-99}
  7. local bombChestLoc = {x=-147, y=6, z=-101}
  8. --local ????ChestLoc = {x=-147, y=6, z=-103}
  9.  
  10. local max = 16
  11.  
  12. function main()
  13.  
  14. end
  15.  
  16. function locate()
  17. x0, y0, z0 = gps.locate()
  18. if x0==nil or y0==nil or z0==nil then
  19. print("error locating")
  20. os.sleep(4)
  21. return locate()
  22. end
  23. return {x=x0,y=y0,z=z0}
  24. end
  25.  
  26. function dig()
  27. if turtle.getSelectedSlot ~= 16 then turtle.select(16) end
  28. turtle.select(16)
  29. if turtle.compare() then
  30. turtle.digUp()
  31. turtle.up()
  32. turtle.turnRight()
  33. turtle.dig()
  34. turtle.forward()
  35. moveTo({y=centralLoc.y, z=centralLoc.z}, 1)
  36. moveTo({x=centralLoc.x, y=centralLoc.y, z=centralLoc.z}, 1)
  37. end
  38. turtle.dig()
  39. end
  40.  
  41. function digDown()
  42. if turtle.getSelectedSlot ~= 16 then turtle.select(16) end
  43. if turtle.compareDown() then
  44. turtle.dig()
  45. turtle.forward()
  46. turtle.turnRight()
  47. turtle.dig()
  48. turtle.forward()
  49. moveTo({y=centralLoc.y, z=centralLoc.z}, 1)
  50. moveTo({x=centralLoc.x, y=centralLoc.y, z=centralLoc.z}, 1)
  51. end
  52. turtle.digDown()
  53. end
  54.  
  55. function digUp()
  56. if turtle.getSelectedSlot ~= 16 then turtle.select(16) end
  57. if turtle.compareUp() then
  58. turtle.dig()
  59. turtle.forward()
  60. turtle.turnRight()
  61. turtle.dig()
  62. turtle.forward()
  63. moveTo({y=centralLoc.y, z=centralLoc.z}, 1)
  64. moveTo({x=centralLoc.x, y=centralLoc.y, z=centralLoc.z}, 1)
  65. end
  66. turtle.digUp()
  67. end
  68.  
  69. function vertN(n, agg)
  70. if n<0 then
  71. for i=1,-n do
  72. if turtle.detectDown() then
  73. if agg then
  74. digDown()
  75. else
  76. return true
  77. end
  78. end
  79. turtle.down()
  80. end
  81. end
  82.  
  83. if n>0 then
  84. for i=1,n do
  85. if turtle.detectUp() then
  86. if agg then
  87. digUp()
  88. else
  89. return true
  90. end
  91. end
  92. turtle.up()
  93. end
  94. end
  95. end
  96.  
  97. function forwardN(n, agg)
  98. for i=1,n do
  99. if turtle.detect() then
  100. if agg then
  101. dig()
  102. else
  103. return true
  104. end
  105. end
  106. turtle.forward()
  107. end
  108. return false
  109. end
  110.  
  111. function orientNorth(agg)
  112. if turtle.detect() then
  113. turtle.turnRight()
  114. end
  115. if turtle.detect() then
  116. turtle.turnRight()
  117. end
  118. if turtle.detect() then
  119. turtle.turnRight()
  120. end
  121. if turtle.detect() then
  122. if agg then
  123. dig()
  124. else
  125. return true
  126. end
  127. end
  128.  
  129. local pos1 = locate()
  130. turtle.forward()
  131. local pos2 = locate()
  132. turtle.back()
  133.  
  134. if pos1.z-1==pos2.z then
  135. return false
  136. elseif pos1.x+1==pos2.x then
  137. turtle.turnLeft()
  138. return false
  139. elseif pos1.z+1==pos2.z then
  140. turtle.turnLeft()
  141. turtle.turnLeft()
  142. return false
  143. elseif pos1.x-1==pos2.x then
  144. turtle.turnRight()
  145. return false
  146. end
  147.  
  148. return true
  149.  
  150. end
  151.  
  152. function moveDelta(delta, agg)
  153. -- turn north (return error otherwise)
  154. if orientNorth(agg) then
  155. return true
  156. end
  157.  
  158. -- move y direction
  159. vertN(delta.y, agg)
  160.  
  161. -- move z direction
  162. if delta.z<0 then
  163. forwardN(-delta.z, agg)
  164. elseif delta.z>0 then
  165. turtle.turnLeft()
  166. turtle.turnLeft()
  167. forwardN(delta.z, agg)
  168. turtle.turnLeft()
  169. turtle.turnLeft()
  170. end
  171.  
  172. -- move x direction
  173. if delta.x<0 then
  174. turtle.turnLeft()
  175. forwardN(-delta.x, agg)
  176. turtle.turnRight()
  177. elseif delta.x>0 then
  178. turtle.turnRight()
  179. forwardN(delta.x, agg)
  180. turtle.turnLeft()
  181. end
  182. end
  183.  
  184. function moveTo(loc, agg)
  185. -- determine location
  186. local here = locate()
  187.  
  188. -- assign any unassigned locations
  189. if loc.x == nil then loc.x = here.x end
  190. if loc.y == nil then loc.y = here.y end
  191. if loc.z == nil then loc.z = here.z end
  192.  
  193. -- create delta vector
  194. local delta = {x=loc.x-here.x,y=loc.y-here.y,z=loc.z-here.z}
  195. if delta.x == 0 and delta.y == 0 and delta.z == 0 then
  196. return
  197. end
  198.  
  199. -- any values above max reduce
  200. if ( delta.x > max) then delta.x = max end
  201. if (-delta.x > max) then delta.x = -max end
  202. if ( delta.y > max) then delta.y = max end
  203. if (-delta.y > max) then delta.y = -max end
  204. if ( delta.z > max) then delta.z = max end
  205. if (-delta.z > max) then delta.z = -max end
  206.  
  207. moveDelta(delta, agg)
  208.  
  209. -- recurse to finish
  210. moveTo(loc, agg)
  211. end
  212.  
  213. function inventorySpace()
  214. local count = 0
  215. for i=1,16 do
  216. if turtle.getItemCount() == 0 then
  217. count = count + 1
  218. end
  219. end
  220. return count
  221. end
  222.  
  223. function alignX(agg, max)
  224. --local loc = locate()
  225. --moveTo({x=centralLoc.x,y=loc.y,z=loc.z}, agg, max)
  226. --moveTo({x=centralLoc.x}, agg, max)
  227. end
  228.  
  229. function dropAll()
  230. for i=1,16 do
  231. turtle.select(i)
  232. turtle.drop()
  233. end
  234. end
  235.  
  236. function emptyInventory(agg)
  237. moveTo({x=centralLoc.x}, agg)
  238. moveTo(dumpChestLoc, agg)
  239. orientNorth()
  240. turtle.turnRight()
  241. dropAll()
  242. end
  243.  
  244. function setInventory(num, agg)
  245. emptyInventory(agg)
  246. if num == 0 then
  247. moveTo(bombChestLoc, 0)
  248. turtle.turnRight()
  249. turtle.select(16)
  250. turtle.suck()
  251. end
  252. end
  253.  
  254. function strip(loc, length)
  255. setInventory(0, 0)
  256. moveTo(loc, 0)
  257. moveTo({loc.x-length, loc.y, loc.z}, 1)
  258. moveTo(loc, 1)
  259. end
  260.  
  261. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement