feedmecookies

Floppy finished miner

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