Advertisement
feedmecookies

Finished Mining turtle with enderchest

Aug 2nd, 2021 (edited)
35
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.92 KB | None | 0 0
  1. --excavate--
  2. times = tonumber(read())
  3.  
  4. mx = 0
  5. mz = 0
  6. my = 0
  7.  
  8. x = 0
  9. y = 60 --where the refill pad is located--
  10. z = 0
  11.  
  12. tx = 0
  13. ty = 40 --where you want the turtle to dig--
  14. tz = 100
  15.  
  16. height = 30 --how high up you want the turtle to go to avoid digging through buildings on its way to the mine --
  17. ex = 5
  18. ez = 5 --quarry size--
  19. ey = 25
  20.  
  21. FuelCoefficent = 15 --oak plank--
  22. FuelCoefficent = 15 --oak plank--
  23.  
  24.  
  25.  
  26. function digUp()
  27. while turtle.detectUp() do
  28. turtle.digUp()
  29. end
  30. end
  31. function digDown()
  32. while turtle.detectDown() do
  33. turtle.digDown()
  34. end
  35. end
  36.  
  37.  
  38. Orientation = 1 --North = 1, East = 2, South = 3 and West = 4
  39. tempor = 0
  40. round = 1
  41.  
  42. FuelCoefficent = 15 --oak plank--
  43.  
  44. function refuel(amount)
  45. Rotate(2)
  46. while math.ceil((amount-turtle.getFuelLevel())/FuelCoefficent) >= 64 do
  47. turtle.suck(64)
  48. turtle.refuel(64)
  49. end
  50. if math.ceil((amount-turtle.getFuelLevel())/FuelCoefficent) > 0 then
  51. turtle.suck(math.ceil((amount-turtle.getFuelLevel())/FuelCoefficent))
  52. turtle.refuel(math.ceil((amount-turtle.getFuelLevel())/FuelCoefficent))
  53. end
  54. Rotate(1)
  55. end
  56.  
  57.  
  58. function GetOri()
  59. return Orientation
  60. end
  61.  
  62. function SetOri(rot)
  63. Orientation = rot
  64. end
  65.  
  66.  
  67. function Rotate(rotation)
  68. if (Orientation == rotation-2) or (Orientation == rotation+2) then
  69. turtle.turnRight()
  70. turtle.turnRight()
  71. Orientation = rotation
  72. elseif(Orientation == 1 and rotation == 4 ) or (Orientation == rotation + 1) then
  73. turtle.turnLeft()
  74. Orientation = rotation
  75. elseif (Orientation == 4 and rotation == 1 ) or (Orientation == rotation - 1) then
  76. turtle.turnRight()
  77. Orientation = rotation
  78. end
  79. end
  80.  
  81. function GoX(C,T)
  82.  
  83. if C > T then
  84. Rotate(4)
  85. for i = T+1, C do
  86. while turtle.detect() do
  87. turtle.dig()
  88. end
  89. turtle.forward()
  90. end
  91. elseif T > C then
  92. Rotate(2)
  93. for i = C+1, T do
  94. while turtle.detect() do
  95. turtle.dig()
  96. end
  97. turtle.forward()
  98. end
  99. end
  100. end
  101.  
  102. function GoY(C,T)
  103.  
  104. if C > T then
  105. for i = T+1, C do
  106. turtle.digDown()
  107. turtle.down()
  108. end
  109. elseif C < T then
  110. for i = C+1, T do
  111. digUp()
  112. turtle.up()
  113. end
  114. end
  115. end
  116.  
  117.  
  118.  
  119. function GoZ(C,T)
  120. if C > T then
  121. Rotate(1)
  122. for i = T+1, C do
  123. while turtle.detect() do
  124. turtle.dig()
  125. end
  126. turtle.forward()
  127. end
  128. elseif T > C then
  129. Rotate(3)
  130. for i = C+1, T do
  131. while turtle.detect() do
  132. turtle.dig()
  133. end
  134. turtle.forward()
  135. end
  136. end
  137. end
  138. function checkinv()
  139. tempor = GetOri()
  140. if turtle.getItemCount(16) ~=0 then
  141. GoX(tx+mx,tx)
  142. GoZ(tz+mz,tz)
  143. GoY(ty+my,height)
  144. GoX(tx,x)
  145. GoZ(tz,z)
  146. GoY(height,y)
  147. Rotate(3)
  148. for i = 1,16 do
  149. turtle.select(i)
  150. turtle.drop(64)
  151. end
  152. turtle.select(1)
  153. Rotate(2)
  154. print("full inventory, need to drop off and refuel")
  155. refuel(2*(math.abs(mx)+math.abs(mz)+math.abs(my)+math.abs(tx-x)+math.abs(tz-z)+math.abs(height - y)+math.abs(ty-height)) + turtle.getFuelLevel() + ex+ez+ey)
  156. Rotate(1)
  157. GoY(y,height)
  158. GoX(x,tx)
  159. GoZ(z,tz)
  160. GoY(height,ty+my)
  161. GoX(tx,tx+mx)
  162. GoZ(tz,tz+mz)
  163. Rotate(tempor)
  164. end
  165. end
  166.  
  167. function dig()
  168. checkinv()
  169. while turtle.detect() do
  170. turtle.dig()
  171. end
  172. if GetOri() == 1 then
  173. mz = mz-1
  174. elseif GetOri() == 2 then
  175. mx = mx+1
  176. elseif GetOri() == 3 then
  177. mz = mz+1
  178. elseif GetOri() == 4 then
  179. mx = mx-1
  180. end
  181. turtle.forward()
  182. end
  183.  
  184.  
  185.  
  186. function excavate(x,y,z)
  187. Rotate(1)
  188. for p = 1, y do
  189. for i = 1, z do
  190. for o = 2, x do
  191. dig()
  192. end
  193. if GetOri() == 1 and i ~= z and round == 1 then
  194. Rotate(2)
  195. dig()
  196. Rotate(3)
  197. elseif GetOri() == 3 and i ~= z and round == 1 then
  198. Rotate(2)
  199. dig()
  200. Rotate(1)
  201. elseif GetOri() == 1 and i ~= z and round == 2 then
  202. Rotate(4)
  203. dig()
  204. Rotate(3)
  205. elseif GetOri() == 3 and i ~= z and round == 2 then
  206. Rotate(4)
  207. dig()
  208. Rotate(1)
  209. end
  210. end
  211. if round == 1 then
  212. round = 2
  213. Rotate(3)
  214. else
  215. round = 1
  216. Rotate(1)
  217. end
  218. checkinv()
  219. turtle.digDown()
  220. if p ~= ey then
  221. if turtle.down() == true then
  222. my = my - 1
  223. end
  224. end
  225. end
  226. end
  227. for i = 1, times do
  228. round = 1
  229. mx = 0
  230. mz = 0
  231. my = 0
  232. print("new job, refueling....")
  233. refuel(2*(math.abs(height - y)+math.abs(ty-height)+math.abs(tx-x)+math.abs(tz-z))+(ex*ez*ey)+ex+ez+ey)
  234. GoY(y,height)
  235. GoX(x,tx)
  236. GoZ(z,tz)
  237. GoY(height,ty+my)
  238. GoX(tx,tx+mx)
  239. GoZ(tz,tz+mz)
  240. excavate(ex,ey,ez)
  241. GoX(tx+mx,tx)
  242. GoZ(tz+mz,tz)
  243. GoY(ty+my,height)
  244. GoX(tx,x)
  245. GoZ(tz,z)
  246. GoY(height,y)
  247. Rotate(3)
  248. tz = tz - ez
  249. for i = 1,16 do
  250. turtle.select(i)
  251. turtle.drop(64)
  252. end
  253. turtle.select(1)
  254. Rotate(1)
  255. print("done")
  256. end
  257.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement