Advertisement
feedmecookies

testbuildmineturtle

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