Advertisement
feedmecookies

turtle digger with screen

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