Advertisement
feedmecookies

Turtle miner?

Jul 23rd, 2019
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.42 KB | None | 0 0
  1. --define--
  2. x = 0
  3. y = 0
  4. z = 0
  5. tx = 0
  6. ty = 0
  7. tz = 0
  8. mx = 0
  9. my = 0--mvariables are used for orientation during mining--
  10. mz = 0
  11. rx = 0
  12. ry = 0 --rvariables is where the turtle goes after its done working--
  13. rz = 0
  14. height = 0
  15. rotation = 1 --North = 1 (default), East = 2, South = 3, West = 4--
  16. depositChest = 2
  17. refuelChest = 4
  18. usingEnderchest = false -- set to true if you are using an enderchest for depositing--
  19. refuelTimes = 0
  20. fuelMultiplier = 15 --default value for wooden planks--
  21. jobs = 0
  22. Mr = rotation
  23. ----------
  24.  
  25. --functions--
  26. function rotate(w)
  27. if (rotation == 1 and w == 4) or (rotation == w + 1) then
  28. turtle.turnLeft()
  29. rotation = rotation - 1
  30. if rotation == 0 then
  31. rotation = 4
  32. end
  33. end
  34. while rotation ~= w do
  35. rotation = rotation + 1
  36. turtle.turnRight()
  37. if rotation == 5 then
  38. rotation = 1
  39. end
  40. end
  41. end
  42.  
  43.  
  44.  
  45.  
  46. function LoadCoords()
  47. file = fs.open("/disk/info.lua","r")
  48. x = tonumber(file.readLine())
  49. y = tonumber(file.readLine())
  50. z = tonumber(file.readLine())
  51. tx = tonumber(file.readLine())
  52. ty = tonumber(file.readLine())
  53. tz = tonumber(file.readLine())
  54. area = tonumber(file.readLine())
  55. height = tonumber(file.readLine())
  56. file.close()
  57. end
  58.  
  59. function SaveCoords() --takes a job and changes it so other turtles doesn't mine the same stuff--
  60. file = fs.open("/disk/info.lua","w")
  61. file.writeLine(x)
  62. file.writeLine(y)
  63. file.writeLine(z)
  64. file.writeLine(tx+area)
  65. file.writeLine(ty)
  66. file.writeLine(tz)
  67. file.writeLine(area)
  68. file.writeLine(height)
  69. file.close()
  70. end
  71.  
  72. function Refuel()
  73.  
  74. for i = 1, 2 do
  75. if x > tx then
  76. fuelx = (x - tx) + mx
  77. else
  78. fuelx = (tx - x) + mx
  79. end
  80.  
  81. if y > ty then
  82. fuely = (y - ty) + my
  83. else
  84. fuely = (ty - y) + my
  85. end
  86.  
  87. if z > tz then
  88. fuelz = (z - tz) + mz
  89. else
  90. fuelz = (tx - x) + mz
  91. end
  92.  
  93. if (refuelTimes == 0)then
  94. refuelAmount = fuelx+fuely+fuelz+(area*area*ty) - turtle.getFuelLevel()
  95. else
  96. refuelAmount = fuelx+fuely+fuelz - turtle.getFuelLevel()
  97. end
  98.  
  99. refuelTimes = refuelTimes + 1
  100.  
  101. rotate(4)
  102. turtle.select(2)
  103.  
  104. while (math.ceil((refuelAmount/fuelMultiplier)) > 64) do
  105. turtle.suck(64)
  106. turtle.refuel(64)
  107. refuelAmount = fuelx+fuely+fuelz - turtle.getFuelLevel()
  108. end
  109.  
  110. if (math.ceil((refuelAmount/fuelMultiplier)) < 64) and math.ceil((refuelAmount/fuelMultiplier)) > 0 then
  111. turtle.suck(math.ceil((refuelAmount/fuelMultiplier)))
  112. turtle.refuel(math.ceil((refuelAmount/fuelMultiplier)))
  113. refuelAmount = fuelx+fuely+fuelz - turtle.getFuelLevel()
  114. end
  115. end
  116. rotate(1)
  117. end
  118.  
  119.  
  120.  
  121. -- proper use of these are Go(from, to)--
  122.  
  123. function GoX(cx,gx)
  124.  
  125. if cx > gx then
  126. rotate(4)
  127. for i = cx, gx + 1, -1 do
  128. turtle.dig()
  129. turtle.forward()
  130. end
  131. elseif cx < gx then
  132. rotate(2)
  133. for i = cx, gx - 1 do
  134. turtle.dig()
  135. turtle.forward()
  136. end
  137.  
  138. end
  139. end
  140.  
  141. function GoY(cy,gy)
  142.  
  143. if cy > gy then
  144. for i = cy, gy + 1, -1 do
  145. turtle.digDown()
  146. turtle.down()
  147. end
  148. elseif cy < gy then
  149. for i = cy, gy - 1 do
  150. turtle.digUp()
  151. turtle.up()
  152. end
  153. end
  154. end
  155.  
  156. function GoZ(cz,gz)
  157. if cz > gz then
  158. rotate(1)
  159. for i = cz, gz+1, -1 do
  160. turtle.dig()
  161. turtle.forward()
  162. end
  163. elseif cz < gz then
  164. rotate(3)
  165. for i = cz, gz - 1 do
  166. turtle.dig()
  167. turtle.forward()
  168. end
  169. end
  170. end
  171.  
  172. function fromM()
  173. Mr = rotation
  174. rotate(1)
  175. GoY(ty-my,height)
  176. GoX(tx+mx,x)
  177. GoZ(tz+mz,z)
  178. GoY(height,y)
  179. end
  180.  
  181. function toM()
  182. rotate(1)
  183. GoY(y,height)
  184. GoX(x,tx+mx)
  185. GoZ(z,tz+mz)
  186. GoY(height,ty-my)
  187. rotate(Mr)
  188. end
  189.  
  190.  
  191.  
  192.  
  193.  
  194.  
  195. function Drop()
  196. rotate(depositChest)
  197. for i = 1, 16 do
  198. turtle.select(i)
  199. turtle.drop(64)
  200. end
  201. end
  202.  
  203. function inventoryCheck()
  204. if turtle.getItemCount(16) > 0 then
  205. if usingEnderchest == true then
  206. turtle.select(1)
  207. turtle.placeUp()
  208. for i = 1, 16 do
  209. turtle.select(i)
  210. turtle.drop(64)
  211. end
  212. turtle.select(1)
  213. turtle.digUp()
  214. else
  215. fromM()
  216. Drop()
  217. Refuel()
  218. toM()
  219. end
  220. end
  221. end
  222.  
  223.  
  224.  
  225.  
  226. function MineFloor()
  227. for i = 0, ty-1 do
  228. GoX(tx+mx,tx)
  229. GoZ(tz+mz,tz)
  230. inventoryCheck()
  231. turtle.digDown()
  232. turtle.down()
  233. for x = 0, area do
  234. while turtle.detect() == true do
  235. inventoryCheck()
  236. if turtle.dig() == false then
  237. fromM()
  238. newJob()
  239. end
  240. end
  241. turtle.forward()
  242. end
  243. for b = 0, area-1 do
  244. if rotation == 1 then
  245. rotate(2)
  246. inventoryCheck()
  247. turtle.dig()
  248. turtle.forward()
  249. rotate(3)
  250. elseif rotation == 3 then
  251. rotate(2)
  252. inventoryCheck()
  253. turtle.dig()
  254. turtle.forward()
  255. rotate(1)
  256. end
  257. end
  258. end
  259. end
  260.  
  261.  
  262. function newJob()
  263. LoadCoords()
  264. SaveCoords()
  265. Drop()
  266. Refuel()
  267. Mr = 1
  268. mx = 0
  269. mz = 0
  270. my = 0
  271. toM()
  272. for u = 1, ty-1 do
  273. MineFloor()
  274. end
  275. fromM()
  276. Drop()
  277. jobs = jobs + 1
  278. end
  279. -------------
  280.  
  281. --main--
  282. while jobs < 3 do
  283. newJob()
  284. end
  285. tx = rx
  286. tz = rz
  287. ty = ry
  288. Refuel()
  289. toM()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement