ravneravn

Endermine uden modem

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