ravneravn

enderMine m pos. mulighed for uden modem

Oct 23rd, 2013
62
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. area = 16
  2. turtleId = os.getComputerLabel()
  3.  
  4. args = {...}
  5. position = {}
  6. position["yStart"] = tonumber(args[1])
  7. position["currY"] = tonumber(args[1])
  8. position["currX"] = 1
  9. position["currZ"] = 1
  10. position["direction"] = 1
  11. position["currLayer"] = "na"
  12. position["valuable"] = 0
  13.  
  14. if args[3] == "manual" then
  15. position["enderchest"] = "no"
  16. else
  17. position["enderchest"] = "yes"
  18. end
  19.  
  20. function printPos()
  21. term.clear()
  22. term.setCursorPos(1,1)
  23. print("------------")
  24. print("x"..position["currX"])
  25. print("z"..position["currZ"])
  26. print("y"..position["currY"])
  27. print("direction "..position["direction"])
  28. print("layer "..position["currLayer"])
  29. print("------------")
  30. end
  31.  
  32. function moveForward()
  33. while not turtle.forward() do
  34. turtle.dig()
  35. end
  36. printPos()
  37. end
  38.  
  39. function moveUp()
  40. while not turtle.up() do
  41. turtle.digUp()
  42. end
  43. position["currY"] = position["currY"]+1
  44. printPos()
  45. end
  46.  
  47. function moveDown()
  48. while not turtle.down() do
  49. turtle.digDown()
  50. end
  51. position["currY"] = position["currY"]-1
  52. printPos()
  53. end
  54.  
  55. function turnRight()
  56. turtle.turnRight()
  57. position["direction"] = position["direction"] +1
  58. if position["direction"] > 4 then position["direction"] = 1
  59. end
  60. savePos()
  61. printPos()
  62. end
  63.  
  64. function turnLeft()
  65. turtle.turnLeft()
  66. position["direction"] = position["direction"] -1
  67. if position["direction"] < 1 then position["direction"] = 4
  68. end
  69. savePos()
  70. printPos()
  71. end
  72.  
  73.  
  74.  
  75. --#### COMPARE UP ####
  76. function compareUp()
  77. turtle.select(1)
  78. turtle.compareUp()
  79. if turtle.compareUp() == true then
  80. notinuse = 1
  81. else
  82.  
  83. turtle.select(2)
  84. turtle.compareUp()
  85. if turtle.compareUp() == true then
  86. notinuse = 1
  87. else
  88.  
  89. turtle.select(3)
  90. turtle.compareUp()
  91. if turtle.compareUp() == true then
  92. notinuse = 1
  93. else
  94.  
  95.  
  96. turtle.digUp()
  97. position["valuable"] = position["valuable"] +1
  98. end
  99. end
  100. end
  101. end
  102.  
  103.  
  104. --#### COMPARE DOWN ####
  105. function compareDown()
  106. turtle.select(1)
  107. turtle.compareDown()
  108. if turtle.compareDown() == true then
  109. notinuse = 1
  110.  
  111. else
  112.  
  113. turtle.select(2)
  114. turtle.compareDown()
  115. if turtle.compareDown() == true then
  116. notinuse = 1
  117.  
  118. else
  119.  
  120. turtle.select(3)
  121. turtle.compareDown()
  122. if turtle.compareDown() == true then
  123. notinuse = 1
  124.  
  125. else
  126.  
  127. turtle.digDown()
  128. position["valuable"] = position["valuable"] +1
  129. end
  130. end
  131. end
  132. end
  133.  
  134.  
  135.  
  136.  
  137.  
  138. function dropOff()
  139. stone = turtle.getItemCount(4)
  140. turtle.select(4)
  141. turtle.drop(stone-1)
  142. findPos()
  143. savePos()
  144. position["resumeY"] = tonumber(position["currY"])
  145. toSurface()
  146. turnRight()
  147. turnRight()
  148. for i = 5, 15 do
  149. turtle.select(i)
  150. turtle.drop()
  151. end
  152. turnRight()
  153. turnRight()
  154. while position["currY"] > position["resumeY"] do
  155. moveDown()
  156. printPos()
  157. savePos()
  158. end
  159. end
  160.  
  161.  
  162.  
  163.  
  164.  
  165. function mineRowXPlus()
  166. --for i = 1, area do
  167. while position["currX"] < area do
  168. moveForward()
  169. position["currX"] = position["currX"] +1
  170. savePos()
  171. printPos()
  172. compareUp()
  173. compareDown()
  174. end
  175. turnRight()
  176. moveForward()
  177. compareUp()
  178. compareDown()
  179. position["currZ"] = position["currZ"] +1
  180. savePos()
  181. turnRight()
  182. end
  183.  
  184. function mineRowXMinus()
  185. --for i = 1, area do
  186. while position["currX"] > 1 do
  187. moveForward()
  188. position["currX"] = position["currX"] -1
  189. savePos()
  190. printPos()
  191. compareUp()
  192. compareDown()
  193. end
  194. turnLeft()
  195. moveForward()
  196. compareUp()
  197. compareDown()
  198. position["currZ"] = position["currZ"] +1
  199. savePos()
  200. turnLeft()
  201. stone = turtle.getItemCount(4)
  202. turtle.select(4)
  203. turtle.drop(stone-1)
  204. end
  205.  
  206. function mineLayer()
  207. --for i = 1, area/2 do
  208. while position["currZ"] < area do
  209. mineRowXPlus()
  210. mineRowXMinus()
  211. end
  212. findPos()
  213. dropOff()
  214. end
  215.  
  216.  
  217. function newLayer()
  218. for i = 1, 3 do
  219. moveUp()
  220. printPos()
  221. savePos()
  222. end
  223. position["currLayer"] = position["currLayer"] + 1
  224. savePos()
  225. sendBroadcast("Starting layer number: "..position["currLayer"]..", Y:"..position["currY"])
  226. sendBroadcast("current valuables: "..position["valuable"])
  227. end
  228.  
  229.  
  230.  
  231. function toBedrock()
  232. mineStart = position["yStart"] - 6
  233. for i = 1, mineStart do
  234. turtle.digDown()
  235. turtle.down()
  236. position["currY"] = position["currY"] -1
  237. printPos()
  238. savePos()
  239. end
  240. position["currLayer"] = 1
  241. savePos()
  242. position["currY"] = 6
  243. savePos()
  244. sendBroadcast("Bottom reached")
  245. printPos()
  246. end
  247.  
  248.  
  249.  
  250. function toSurface()
  251. findPos()
  252. sendBroadcast("Going up")
  253. --for i = 1, position["yStart"] - position["currY"] do
  254. while tonumber(position["currY"]) < tonumber(position["yStart"]) do
  255. moveUp()
  256. savePos()
  257. end
  258. --if tonumber(position["currY"]) > tonumber(position["yStart"]) then
  259. while tonumber(position["currY"]) > tonumber(position["yStart"]) do
  260. turtle.down()
  261. position["currY"] = position["currY"] -1
  262. printPos()
  263. savePos()
  264. end
  265. --end
  266. end
  267.  
  268.  
  269. function sendBroadcast(message)
  270. position["enderchest"] = "yes"
  271. rednet.open("right")
  272. rednet.broadcast("["..turtleId.."] "..message)
  273. end
  274.  
  275.  
  276.  
  277.  
  278. function findPos()
  279. while position["direction"] ~= 3 do
  280. turnRight()
  281. savePos()
  282. end
  283. while position["currX"] > 1 do
  284. moveForward()
  285. position["currX"] = position["currX"] -1
  286. savePos()
  287. end
  288. while position["direction"] ~= 4 do
  289. turnRight()
  290. savePos()
  291. end
  292. while position["currZ"] > 1 do
  293. moveForward()
  294. position["currZ"] = position["currZ"] -1
  295. savePos()
  296. end
  297. while position["direction"] ~= 1 do
  298. turnRight()
  299. savePos()
  300. end
  301. end
  302.  
  303.  
  304.  
  305. function resume()
  306. sendBroadcast("Resuming, Y:"..position["currY"])
  307. turtle.select(16)
  308. turtle.dig()
  309. layersToGo = math.floor((position["yStart"] - position["currY"])/4)
  310. for i = 1, layersToGo do
  311. mineLayer()
  312. newLayer()
  313. if position["currY"] > 50 then
  314. break
  315. end
  316. end
  317. position["status"] = "off"
  318. toSurface()
  319. end
  320.  
  321.  
  322.  
  323.  
  324.  
  325. -- ## WRITE FILE ##
  326. function savePos()
  327. --handle = fs.open("enderMine/savedPosition", "w")
  328. --handle.write(textutils.serialize(position))
  329. --handle.close()
  330. end
  331.  
  332. function loadPos()
  333. --handle = fs.open("enderMine/savedPosition", "r")
  334. --readFile = handle.readLine()
  335. --if readFile ~= nil then
  336. --position = textutils.unserialize(readFile)
  337. --end
  338. --handle.close()
  339. end
  340.  
  341.  
  342. function checkFuel()
  343. layers = math.floor(position["yStart"] / 4)
  344. mass = area * area * layers
  345. fuel = turtle.getFuelLevel()
  346. if fuel < mass then
  347. term.clear()
  348. term.setCursorPos(1,1)
  349. print("Not enought fuel")
  350. print("Fuel needed: "..mass)
  351. print("Current fuel: "..fuel)
  352. sleep(1)
  353. print("")
  354. print("Press a key to continue")
  355. event = os.pullEvent("key")
  356. end
  357. end
  358.  
  359.  
  360. --------------- LOOP
  361.  
  362. if args[2] == "on" then
  363. --if position["status"] == "on" then
  364. loadPos()
  365. findPos()
  366. resume()
  367. position["status"] = nil
  368. position["status"] = "off"
  369. os.reboot()
  370. end
  371.  
  372. checkFuel()
  373.  
  374. savePos()
  375. position["status"] = "on"
  376. layers = math.floor(position["yStart"] / 4)
  377. position["currY"] = position["yStart"]
  378. toBedrock()
  379. for i = 1, layers do
  380. mineLayer()
  381. newLayer()
  382. if position["currY"] > 50 then
  383. break
  384. end
  385. end
  386. position["status"] = "off"
  387. toSurface()
RAW Paste Data