Advertisement
feedmecookies

temp

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