Advertisement
melzneni

NEW_MINE_DOWN

Nov 13th, 2020 (edited)
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.69 KB | None | 0 0
  1. args = { ... }
  2.  
  3. garbage = {
  4. "minecraft:cobblestone",
  5. "minecraft:dirt",
  6. "minecraft:gravel",
  7. "chisel:diorite",
  8. "chisel:andesite",
  9. "chisel:granite",
  10. "chisel:marble",
  11. "chisel:limestone",
  12. }
  13.  
  14. function digForward()
  15. while turtle.detect() do
  16. turtle.dig()
  17. end
  18. end
  19.  
  20. function digUp()
  21. while turtle.detectUp() do
  22. turtle.digUp()
  23. end
  24. end
  25.  
  26. function digDown()
  27. while turtle.detectDown() do
  28. turtle.digDown()
  29. end
  30. end
  31.  
  32. local px = 0; local py = 0; local pz = 0
  33. local facing = 0
  34.  
  35. function back(count)
  36. for i = 1, count do
  37. if not turtle.back() then
  38. turnLeft(2)
  39. forward(1)
  40. turnLeft(2)
  41. else
  42. if facing == 0 then px = px - 1
  43. elseif facing == 1 then py = py - 1
  44. elseif facing == 2 then px = px + 1
  45. elseif facing == 3 then py = py + 1
  46. end
  47. end
  48. end
  49. end
  50.  
  51. function forward(count)
  52. for i = 1, count do
  53. digForward(1)
  54. while not turtle.forward() do
  55. if not digForward(1) then
  56. turtle.attack()
  57. end
  58. end
  59. end
  60. if facing == 0 then px = px + count
  61. elseif facing == 1 then py = py + count
  62. elseif facing == 2 then px = px - count
  63. elseif facing == 3 then py = py - count
  64. end
  65. end
  66.  
  67. function up(count)
  68. for i = 1, count do
  69. digUp(1)
  70. while not turtle.up() do
  71. if not digUp(1) then
  72. turtle.attackUp()
  73. end
  74. end
  75. end
  76. pz = pz + count
  77. end
  78.  
  79. function down(count)
  80. for i = 1, count do
  81. digDown(1)
  82. while not turtle.down() do
  83. if not digDown(1) then
  84. turtle.attackDown()
  85. end
  86. end
  87. end
  88. pz = pz - count
  89. end
  90.  
  91. function turnLeft(count)
  92. for i = 1, count do
  93. turtle.turnLeft()
  94. end
  95. facing = facing - count
  96. while facing < 0 do facing = facing + 4 end
  97. end
  98.  
  99. function turnRight(count)
  100. for i = 1, count do
  101. turtle.turnRight()
  102. end
  103. facing = facing + count
  104. while facing > 3 do facing = facing - 4 end
  105. end
  106.  
  107. function dig3xXInFront(height)
  108. forward(1)
  109. turnLeft(1)
  110. for i = 1, height - 1 do
  111. digForward(1)
  112. down(1)
  113. end
  114. checkForFilled()
  115. digForward(1)
  116. turnRight(2)
  117. for i = 1, height - 1 do
  118. digForward(1)
  119. up(1)
  120. end
  121. checkForFilled()
  122. digForward(1)
  123. turnLeft(1)
  124. end
  125.  
  126. function checkForFilled()
  127. if turtle.getItemCount(10) > 0 then
  128. checkForAndDropGarbage()
  129. local pos = getLocationData()
  130. moveToPos({ 0, 0, 0, 0 })
  131. checkForAndDropGarbage()
  132. turnLeft(1)
  133. dropAll()
  134. moveToPos(pos)
  135. end
  136. end
  137.  
  138. function isGarbage(val)
  139. for index, value in ipairs(garbage) do
  140. if value == val then
  141. return true
  142. end
  143. end
  144. return false
  145. end
  146.  
  147. function checkForAndDropGarbage()
  148. local filled=true;
  149. for i = 1, 16 do
  150. local data = turtle.getItemDetail(i)
  151. if data then
  152. if isGarbage(data.name) then
  153. turtle.select(i)
  154. turtle.drop()
  155. end
  156. else filled=false
  157. end
  158. end
  159. turtle.select(1)
  160.  
  161. refuel()
  162.  
  163. if turtle.getFuelLevel()<500 then
  164. print("please insert fuel")
  165. local pos=getLocationData()
  166. moveToPos({ 0, 0, 0, 3 })
  167. dropAll()
  168. turnRight(1)
  169. while turtle.getFuelLevel()<500 do
  170. refuel()
  171. os.sleep(1)
  172. end
  173. moveToPos(pos)
  174. end
  175. end
  176.  
  177. function getLocationData()
  178. return { px, py, pz, facing }
  179. end
  180.  
  181. function moveToPos(pos)
  182. local lpx = pos[1]
  183. local lpy = pos[2]
  184. local lpz = pos[3]
  185. local lfacing = pos[4]
  186. if lpx ~= px then
  187. if lpx > px then
  188. setFacing(0)
  189. forward(lpx - px)
  190. else
  191. setFacing(2)
  192. forward(px - lpx)
  193. end
  194. end
  195. if lpy ~= py then
  196. if lpy > py then
  197. setFacing(1)
  198. forward(lpy - py)
  199. else
  200. setFacing(3)
  201. forward(py - lpy)
  202. end
  203. end
  204. if lpz ~= pz then
  205. if lpz > pz then
  206. up(lpz - pz)
  207. else
  208. down(pz - lpz)
  209. end
  210. end
  211. setFacing(lfacing)
  212. end
  213.  
  214. function setFacing(lfacing)
  215. while lfacing ~= facing do
  216. turnLeft(1)
  217. end
  218. end
  219.  
  220. function digLoop(length, height)
  221. for i = 1, length do
  222. dig3xXInFront(height)
  223. end
  224. --checkForAndDropGarbage()
  225. back(1)
  226. turnRight(1)
  227. forward(1)
  228. dig3xXInFront(height)
  229. dig3xXInFront(height)
  230. dig3xXInFront(height)
  231. back(1)
  232. turnRight(1)
  233. forward(1)
  234. for i = 1, length do
  235. dig3xXInFront(height)
  236. end
  237. --checkForAndDropGarbage()
  238. back(1)
  239. turnLeft(1)
  240. forward(1)
  241. dig3xXInFront(height)
  242. dig3xXInFront(height)
  243. dig3xXInFront(height)
  244. back(1)
  245. turnLeft(1)
  246. forward(1)
  247. end
  248.  
  249. function refuel()
  250. for i = 1, 16 do
  251. turtle.select(i);
  252. turtle.refuel()
  253. end
  254. end
  255.  
  256. function dropAll()
  257. for i = 1, 16 do
  258. turtle.select(i)
  259. turtle.drop()
  260. end
  261. turtle.select(1)
  262. end
  263.  
  264. if table.getn(args) ~= 3 then
  265. print("arguments 'width', 'depth' and 'height' expected (width is not 100% accourate)")
  266. else
  267. local x = tonumber(args[1]) / 6
  268. if tonumber(args[1]) % 6 ~= 0 then x = x + 1 end
  269. local y = tonumber(args[2]) - 2
  270. local z = tonumber(args[3])
  271. for j = 1, x do
  272. digLoop(y, z)
  273. refuel()
  274. end
  275. checkForAndDropGarbage()
  276. moveToPos({ 0, 0, 0, 3 })
  277. dropAll()
  278. turnRight(1)
  279. end
  280.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement