feedmecookies

excavate

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