ravneravn

mine uden modem fix

Jan 1st, 2014
59
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. area = 15
  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. savePos()
  37. printPos()
  38. end
  39.  
  40. function moveUp()
  41. while not turtle.up() do
  42. turtle.digUp()
  43. end
  44. position["currY"] = position["currY"]+1
  45. savePos()
  46. printPos()
  47. end
  48.  
  49. function moveDown()
  50. while not turtle.down() do
  51. turtle.digDown()
  52. end
  53. position["currY"] = position["currY"]-1
  54. savePos()
  55. printPos()
  56. end
  57.  
  58. function turnRight()
  59. turtle.turnRight()
  60. position["direction"] = position["direction"] +1
  61. savePos()
  62. if position["direction"] > 4 then position["direction"] = 1
  63. savePos()
  64. end
  65. printPos()
  66. end
  67.  
  68. function turnLeft()
  69. turtle.turnLeft()
  70. position["direction"] = position["direction"] -1
  71. savePos()
  72. if position["direction"] < 1 then position["direction"] = 4
  73. savePos()
  74. end
  75. printPos()
  76. end
  77.  
  78.  
  79.  
  80. --#### COMPARE UP ####
  81. function compareUp()
  82. turtle.select(1)
  83. turtle.compareUp()
  84. if turtle.compareUp() == true then
  85. notinuse = 1
  86. else
  87.  
  88. turtle.select(2)
  89. turtle.compareUp()
  90. if turtle.compareUp() == true then
  91. notinuse = 1
  92. else
  93.  
  94. turtle.select(3)
  95. turtle.compareUp()
  96. if turtle.compareUp() == true then
  97. notinuse = 1
  98. else
  99.  
  100.  
  101. turtle.digUp()
  102. position["valuable"] = position["valuable"] +1
  103. end
  104. end
  105. end
  106. end
  107.  
  108.  
  109. --#### COMPARE DOWN ####
  110. function compareDown()
  111. turtle.select(1)
  112. turtle.compareDown()
  113. if turtle.compareDown() == true then
  114. notinuse = 1
  115.  
  116. else
  117.  
  118. turtle.select(2)
  119. turtle.compareDown()
  120. if turtle.compareDown() == true then
  121. notinuse = 1
  122.  
  123. else
  124.  
  125. turtle.select(3)
  126. turtle.compareDown()
  127. if turtle.compareDown() == true then
  128. notinuse = 1
  129.  
  130. else
  131.  
  132. turtle.digDown()
  133. position["valuable"] = position["valuable"] +1
  134. end
  135. end
  136. end
  137. end
  138.  
  139.  
  140. function layerResumeManual()
  141. loadPosManual()
  142. turnRight()
  143. while position["currZ"] < positionResumeManual["currZ"] do
  144. moveForward()
  145. position["currZ"] = position["currZ"] +1
  146. savePos()
  147. end
  148. turnLeft()
  149. while position["currX"] < positionResumeManual["currX"] do
  150. moveForward()
  151. position["currX"] = position["currX"] +1
  152. savePos()
  153. end
  154. while position["direction"] ~= positionResumeManual["direction"] do
  155. turnRight()
  156. savePos()
  157. end
  158. end
  159.  
  160.  
  161.  
  162. function dropOff()
  163. if position["enderchest"] == "yes" then
  164. stone = turtle.getItemCount(4)
  165. turtle.select(4)
  166. turtle.drop(stone-1)
  167. turtle.dig()
  168. turtle.select(16)
  169. turtle.place()
  170. for i = 5, 15 do
  171. turtle.select(i)
  172. turtle.drop()
  173. end
  174. turtle.select(16)
  175. turtle.dig()
  176.  
  177. elseif position["enderchest"] == "no" then
  178. stone = turtle.getItemCount(4)
  179. turtle.select(4)
  180. turtle.drop(stone-1)
  181. if turtle.getItemCount(16) > 0 then
  182. savePosManual()
  183. findPos()
  184. savePos()
  185. position["resumeY"] = tonumber(position["currY"])
  186. toSurface()
  187. turnRight()
  188. turnRight()
  189. for i = 5, 16 do
  190. turtle.select(i)
  191. turtle.drop()
  192. end
  193. turtle.select(5)
  194. turnRight()
  195. turnRight()
  196. while position["currY"] > position["resumeY"] do
  197. moveDown()
  198. printPos()
  199. savePos()
  200. end
  201. --os.reboot()
  202. layerResumeManual()
  203. end
  204. end
  205. end
  206.  
  207.  
  208.  
  209.  
  210.  
  211. function mineRowXPlus()
  212. --for i = 1, area do
  213. while position["currX"] < area do
  214. moveForward()
  215. position["currX"] = position["currX"] +1
  216. savePos()
  217. printPos()
  218. compareUp()
  219. compareDown()
  220. end
  221. turnRight()
  222. dropOff()
  223. moveForward()
  224. compareUp()
  225. compareDown()
  226. position["currZ"] = position["currZ"] +1
  227. savePos()
  228. turnRight()
  229. end
  230.  
  231. function mineRowXMinus()
  232. --for i = 1, area do
  233. while position["currX"] > 1 do
  234. moveForward()
  235. position["currX"] = position["currX"] -1
  236. savePos()
  237. printPos()
  238. compareUp()
  239. compareDown()
  240. end
  241. turnLeft()
  242. dropOff()
  243. moveForward()
  244. compareUp()
  245. compareDown()
  246. position["currZ"] = position["currZ"] +1
  247. savePos()
  248. turnLeft()
  249. end
  250.  
  251. function mineLayer()
  252. --for i = 1, area/2 do
  253. while position["currZ"] < area do
  254. mineRowXPlus()
  255. mineRowXMinus()
  256. end
  257. findPos()
  258. end
  259.  
  260.  
  261. function newLayer()
  262. for i = 1, 3 do
  263. moveUp()
  264. printPos()
  265. savePos()
  266. end
  267. position["currLayer"] = position["currLayer"] + 1
  268. savePos()
  269. --sendBroadcast("Layer #"..position["currLayer"]..", Y:"..position["currY"])
  270. --sendBroadcast("current valuables: "..position["valuable"])
  271. end
  272.  
  273.  
  274.  
  275. function toBedrock()
  276. mineStart = position["yStart"] - 6
  277. for i = 1, mineStart do
  278. turtle.digDown()
  279. turtle.down()
  280. position["currY"] = position["currY"] -1
  281. printPos()
  282. savePos()
  283. end
  284. position["currLayer"] = 1
  285. savePos()
  286. position["currY"] = 6
  287. savePos()
  288. --sendBroadcast("Bottom reached")
  289. printPos()
  290. end
  291.  
  292.  
  293.  
  294. function toSurface()
  295. findPos()
  296. --sendBroadcast("Going up")
  297. --for i = 1, position["yStart"] - position["currY"] do
  298. while tonumber(position["currY"]) < tonumber(position["yStart"]) do
  299. moveUp()
  300. savePos()
  301. end
  302. --if tonumber(position["currY"]) > tonumber(position["yStart"]) then
  303. while tonumber(position["currY"]) > tonumber(position["yStart"]) do
  304. turtle.down()
  305. position["currY"] = position["currY"] -1
  306. printPos()
  307. savePos()
  308. end
  309. --end
  310. end
  311.  
  312.  
  313. function sendBroadcast(message)
  314. --rednet.open("right")
  315. --rednet.broadcast("["..turtleId.."] "..message)
  316. end
  317.  
  318.  
  319.  
  320.  
  321. function findPos()
  322. while position["direction"] ~= 3 do
  323. turnRight()
  324. savePos()
  325. end
  326. while position["currX"] > 1 do
  327. moveForward()
  328. position["currX"] = position["currX"] -1
  329. savePos()
  330. end
  331. while position["direction"] ~= 4 do
  332. turnRight()
  333. savePos()
  334. end
  335. while position["currZ"] > 1 do
  336. moveForward()
  337. position["currZ"] = position["currZ"] -1
  338. savePos()
  339. end
  340. while position["direction"] ~= 1 do
  341. turnRight()
  342. savePos()
  343. end
  344. end
  345.  
  346.  
  347.  
  348. function resume()
  349. --sendBroadcast("Resuming, Y:"..position["currY"])
  350. turtle.select(16)
  351. turtle.dig()
  352. layersToGo = math.floor((position["yStart"] - position["currY"])/4)
  353. for i = 1, layersToGo do
  354. mineLayer()
  355. newLayer()
  356. if position["currY"] > 50 then
  357. break
  358. end
  359. end
  360. position["status"] = "off"
  361. toSurface()
  362. end
  363.  
  364.  
  365.  
  366.  
  367.  
  368. -- ## WRITE FILE ##
  369. function savePos()
  370. handle = fs.open("enderMine/savedPosition", "w")
  371. handle.write(textutils.serialize(position))
  372. handle.close()
  373. end
  374.  
  375. function savePosManual()
  376. handle = fs.open("enderMine/savedPositionResume", "w")
  377. handle.write(textutils.serialize(position))
  378. handle.close()
  379. end
  380.  
  381. function loadPos()
  382. handle = fs.open("enderMine/savedPosition", "r")
  383. readFile = handle.readLine()
  384. if readFile ~= nil then
  385. position = textutils.unserialize(readFile)
  386. end
  387. handle.close()
  388. end
  389.  
  390. function loadPosManual()
  391. handle = fs.open("enderMine/savedPositionResume", "r")
  392. readFile = handle.readLine()
  393. if readFile ~= nil then
  394. positionResumeManual = textutils.unserialize(readFile)
  395. end
  396. handle.close()
  397. end
  398.  
  399.  
  400. function checkFuel()
  401. layers = math.floor(position["yStart"] / 4)
  402. mass = area * area * layers
  403. fuel = turtle.getFuelLevel()
  404. if fuel < mass then
  405. term.clear()
  406. term.setCursorPos(1,1)
  407. print("Not enought fuel")
  408. print("Fuel needed: "..mass)
  409. print("Current fuel: "..fuel)
  410. print("Put fuel in slot 15")
  411. sleep(1)
  412. print("")
  413. print("Press a key to continue")
  414. event = os.pullEvent("key")
  415. turtle.select(15)
  416. turtle.refuel()
  417. end
  418. end
  419.  
  420.  
  421. --------------- LOOP
  422.  
  423. if args[2] == "on" then
  424. --if position["status"] == "on" then
  425. loadPos()
  426. findPos()
  427. resume()
  428. position["status"] = nil
  429. position["status"] = "off"
  430. os.reboot()
  431. end
  432.  
  433. print("checking fuel")
  434.  
  435. checkFuel()
  436.  
  437. print("fuel checked")
  438.  
  439. savePos()
  440. position["status"] = "on"
  441. layers = math.floor(position["yStart"] / 4)
  442. position["currY"] = position["yStart"]
  443. toBedrock()
  444. for i = 1, layers do
  445. mineLayer()
  446. newLayer()
  447. if position["currY"] > 50 then
  448. break
  449. end
  450. end
  451. toSurface()
  452. position["status"] = "off"
  453. --sendBroadcast("Done")
  454. os.reboot()
RAW Paste Data