Advertisement
JMANN2400

OreGetter

Jul 25th, 2019
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.52 KB | None | 0 0
  1. x = 0
  2. y = 64
  3. z = 0
  4.  
  5. homeX = 0
  6. homeY = 64
  7. homeZ = 0
  8.  
  9. digDepth = 5
  10.  
  11. facing = "north"
  12.  
  13. coalSlots = {2,3,4}
  14. ironSlots = {5,6,7}
  15. goldSlots = {8,9}
  16. redstoneSlots = {10,11,12}
  17. lapisSlots = {13,14,15}
  18. diamondSlots = {16}
  19.  
  20. function refuelWithCoal()
  21. selectFromList(coalList)
  22. turtle.refuel()
  23. end
  24.  
  25. function selectFromList(list)
  26. for i, v in ipairs(list) do
  27. turtle.select(v)
  28. if turtle.getItemCount() > 0 then
  29. break
  30. end
  31. end
  32. end
  33.  
  34. function spaceLeft(slotList)
  35. space = 0
  36. for i, v in ipairs(slotList) do
  37. space = space + turtle.getItemSpace(v)
  38. end
  39. return space
  40. end
  41.  
  42. function setOres(c,i,g,r,l,d)
  43. file = fs.open("ores.txt", "w")
  44. file.writeLine(c)
  45. file.writeLine(i)
  46. file.writeLine(g)
  47. file.writeLine(r)
  48. file.writeLine(l)
  49. file.writeLine(d)
  50. file.close()
  51. end
  52.  
  53. function setCoords(xx,yy,zz)
  54. file = fs.open("coords.txt", "w")
  55. file.writeLine(xx)
  56. file.writeLine(yy)
  57. file.writeLine(zz)
  58. file.close()
  59. end
  60.  
  61. function setHome(hx,hy,hz)
  62. file = fs.open("home", "w")
  63. file.writeLine(hx)
  64. file.writeLine(hy)
  65. file.writeLine(hz)
  66. file.close()
  67. end
  68.  
  69. function getOres()
  70. file = fs.open("ores.txt", "r")
  71. coal = tonumber(file.readLine())
  72. iron = tonumber(file.readLine())
  73. gold = tonumber(file.readLine())
  74. redstone = tonumber(file.readLine())
  75. lapis = tonumber(file.readLine())
  76. diamond = tonumber(file.readLine())
  77. end
  78.  
  79. function getCoords()
  80. file = fs.open("coords.txt", "r")
  81. x = tonumber(file.readLine())
  82. y = tonumber(file.readLine())
  83. z = tonumber(file.readLine())
  84. end
  85.  
  86. function getHome()
  87. file = fs.open("home.txt", "r")
  88. homeX = tonumber(file.readLine())
  89. homeY = tonumber(file.readLine())
  90. homeZ = tonumber(file.readLine())
  91. end
  92.  
  93. function getUsedSlots(n)
  94. return math.ceil(n/64)
  95. end
  96.  
  97. function getTotalUsedSlots(c,i,g,r,l,d)
  98. t = getUsedSlots(c) + getUsedSlots(i) + getUsedSlots(g) + getUsedSlots(r) + getUsedSlots(l) + getUsedSlots(d)
  99. return t
  100. end
  101.  
  102. function move(dir)
  103. getCoords()
  104. if dir == "forward" then
  105. turtle.forward()
  106. if facing == "north" then
  107. x = x + 1
  108. end
  109. if facing == "south" then
  110. x = x - 1
  111. end
  112. if facing == "east" then
  113. z = z + 1
  114. end
  115. if facing == "west" then
  116. z = z - 1
  117. end
  118. end
  119. if dir == "back" then
  120. turtle.back()
  121. if facing == "north" then
  122. x = x - 1
  123. end
  124. if facing == "south" then
  125. x = x + 1
  126. end
  127. if facing == "east" then
  128. z = z - 1
  129. end
  130. if facing == "west" then
  131. z = z + 1
  132. end
  133. end
  134. if dir == "up" then
  135. turtle.up()
  136. y = y + 1
  137. end
  138. if dir == "down" then
  139. turtle.down()
  140. y = y - 1
  141. end
  142. if dir == "right" then
  143. turtle.turnRight()
  144. if facing == "north" then
  145. facing = "east"
  146. elseif facing == "east" then
  147. facing = "south"
  148. elseif facing == "south" then
  149. facing = "west"
  150. elseif facing == "west" then
  151. facing = "north"
  152. end
  153. end
  154. if dir == "left" then
  155. turtle.turnLeft()
  156. if facing == "north" then
  157. facing = "west"
  158. elseif facing == "west" then
  159. facing = "south"
  160. elseif facing == "south" then
  161. facing = "east"
  162. elseif facing == "east" then
  163. facing = "north"
  164. end
  165. end
  166. print("Coords")
  167. print(x)
  168. print(y)
  169. print(z)
  170. print(facing)
  171. setCoords(x,y,z)
  172. end
  173.  
  174. function digColumn()
  175. while turtle.getFuelLevel() < 100 do
  176. refuelWithCoal()
  177. end
  178. while y > digDepth do
  179. success, data = turtle.inspectDown()
  180. if data.name == "minecraft:lava" then
  181. turtle.select(1)
  182. turtle.placeDown()
  183. turtle.refuel()
  184. for i = 0, 3 do
  185. turtle.place()
  186. move("left")
  187. end
  188. end
  189. turtle.digDown()
  190. move("down")
  191. end
  192. while y < homeY do
  193. move("up")
  194. end
  195. end
  196.  
  197. function digRow(n)
  198. for a = 1, n do
  199. move("forward")
  200. move("forward")
  201. move("forward")
  202. digColumn()
  203. end
  204. for a = 1, n do
  205. move("back")
  206. move("back")
  207. move("back")
  208. end
  209. end
  210.  
  211. function changeRowPlus()
  212. move("right")
  213. move("forward")
  214. move("forward")
  215. move("left")
  216. move("forward")
  217. end
  218.  
  219. function changeRowMinus()
  220. move("left")
  221. move("forward")
  222. move("forward")
  223. move("left")
  224. move("forward")
  225. move("left")
  226. move("left")
  227. end
  228.  
  229. function dig(nCols, nRows)
  230. digRow(nCols)
  231. for q = 2, nRows do
  232. changeRowPlus()
  233. digRow(nCols)
  234. end
  235. for q = 2, nRows do
  236. changeRowMinus()
  237. end
  238. end
  239.  
  240. function goHome()
  241. while facing ~= "north" do
  242. move("left")
  243. end
  244. print("FACING NORTH")
  245. while y ~= homeY do
  246. move("up")
  247. end
  248. print("Y HOMED")
  249. while x ~= homeX do
  250. move("back")
  251. end
  252. print("X HOMED")
  253. move("left")
  254. while z ~= homeZ do
  255. move("forward")
  256. end
  257. print("Z HOMED")
  258. move("right")
  259. print("READY TO MINE")
  260. end
  261.  
  262. goHome()
  263. dig(25,25)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement