Advertisement
LivioBrunner

Minerv3

Sep 29th, 2013
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.45 KB | None | 0 0
  1. local l = 0
  2. local allitems = 0
  3. local selectcounter = 0
  4. local maxprogram = 3
  5. local forwardcounter = 0
  6. local fullblocksize = 0
  7. local i = 0
  8. local j = 0
  9. local k = 0
  10. local width = 0
  11. local height = 0
  12. local length = 0
  13. local actx = 0
  14. local acty = 0
  15. local actz = 0
  16. local actyaw = 0
  17. local lastx = 0
  18. local lasty = 0
  19. local lastz = 0
  20. local lastyaw = 0
  21. local anwser = false
  22. turtle.select(1)
  23. function startMessage()
  24. print("----Welcome to the miner v.3----")
  25. end
  26. function items()
  27. for i = 1, 16 do
  28. actitem = turtle.getItemCount(i)
  29. allitems = allitems + actitem
  30. end
  31. return allitems
  32. end
  33. function clearInv()
  34. for i = 1,16 do
  35. turtle.select(i)
  36. turtle.drop(turtle.getItemCount(i))
  37. end
  38. turtle.select(1)
  39. end
  40. function clearterm()
  41. term.clear()
  42. term.setCursorPos(1,1)
  43. end
  44. function usefuel(slotnum)
  45. turtle.select(slotnum)
  46. turtle.refuel(1)
  47. end
  48. function setPositionVars()
  49. lastx = actx
  50. lasty = acty
  51. lastz = actz
  52. lastyaw = actyaw
  53. end
  54. function turtledig()
  55. forwardcounter = forwardcounter + 1
  56. blocksleft = fullblocksize - forwardcounter
  57. writeterm(blocksleft.." Blocks left until end", 0)
  58. writeterm(turtle.getFuelLevel().." Fuellevel", 1)
  59. blocksleft = 0
  60. turtle.dig()
  61. if turtle.getItemCount(16) > 0 then
  62. setPositionVars()
  63. findBack(0,0,0,0,true)
  64.  
  65. end
  66. end
  67. function turtledigup()
  68. forwardcounter = forwardcounter + 1
  69. blocksleft = fullblocksize - forwardcounter
  70. writeterm(blocksleft.." Blocks left until end", 0)
  71. writeterm(turtle.getFuelLevel().." Fuellevel", 1)
  72. blocksleft = 0
  73. turtle.digUp()
  74. end
  75. function turtledigdown()
  76. forwardcounter = forwardcounter + 1
  77. blocksleft = fullblocksize - forwardcounter
  78. writeterm(blocksleft.." Blocks left until end", 0)
  79. writeterm(turtle.getFuelLevel().." Fuellevel", 1)
  80. blocksleft = 0
  81. turtle.digDown()
  82. if turtle.getItemCount(16) > 0 then
  83. setPositionVars()
  84. findBack(0,0,0,0,true)
  85. end
  86. end
  87. function turtleup()
  88. if turtle.up() == false then
  89. while turtle.up() == false do
  90. turtledigup()
  91. end
  92. end
  93. acty = acty + 1
  94. writeterm("x : ".. actx .. ", y : ".. acty .. ", z : ".. actz .. ", yaw : ".. actyaw, 2)
  95. end
  96. function turtledown()
  97. if turtle.down() == false then
  98. while turtle.down() == false do
  99. turtledigdown()
  100. end
  101. end
  102. acty = acty - 1
  103. end
  104. function goforward()
  105. if turtle.forward() == false then
  106. while turtle.forward() == false do
  107. turtledig()
  108. end
  109. end
  110. if actyaw == 0 then
  111. actx = actx + 1
  112. elseif actyaw == 1 then
  113. actz = actz - 1
  114. elseif actyaw == 2 then
  115. actx = actx - 1
  116. elseif actyaw == 3 then
  117. actz = actz + 1
  118. end
  119. writeterm("x : ".. actx .. ", y : ".. acty .. ", z : ".. actz .. ", yaw : ".. actyaw, 2)
  120. end
  121. function findBack(x, y, z, yaw, anwser)
  122. if anwser ~= true then
  123. anwser = false
  124. end
  125. if x < actx then
  126. while actyaw ~= 2 do
  127. turtleleft()
  128. end
  129. elseif x > actx then
  130. while actyaw ~= 0 do
  131. turtleleft()
  132. end
  133. end
  134. while actx ~= x do
  135. goforward()
  136. end
  137. if z > actz then
  138. while actyaw ~= 3 do
  139. turtleleft()
  140. end
  141. elseif z < actz then
  142. while actyaw ~= 1 do
  143. turtleleft()
  144. end
  145. end
  146. while actz ~= z do
  147. goforward()
  148. end
  149. if y < acty then
  150. while acty ~= y do
  151. turtledown()
  152. end
  153. elseif y > acty then
  154. while acty ~= y do
  155. turtleup()
  156. end
  157. end
  158. while actyaw ~= yaw do
  159. turtleleft()
  160. end
  161. if anwser == true then
  162. turtleleft()
  163. turtleleft()
  164. clearInv()
  165. turtleleft()
  166. turtleleft()
  167. findBack(lastx, lasty, lastz, lastyaw, false)
  168. end
  169. end
  170. function turtleright()
  171. turtle.turnRight()
  172. actyaw = actyaw + 1
  173. if actyaw > 3 then
  174. actyaw = 0
  175. end
  176. writeterm("x : ".. actx .. ", y : ".. acty .. ", z : ".. actz .. ", yaw : ".. actyaw, 2)
  177. end
  178. function turtleleft()
  179. turtle.turnLeft()
  180. actyaw = actyaw - 1
  181. if actyaw < 0 then
  182. actyaw = 3
  183. end
  184. writeterm("x : ".. actx .. ", y : ".. acty .. ", z : ".. actz .. ", yaw : ".. actyaw, 2)
  185. end
  186. function turnright()
  187. turtleright()
  188. turtledig()
  189. goforward()
  190. turtleright()
  191. end
  192. function turnleft()
  193. turtleleft()
  194. turtledig()
  195. goforward()
  196. turtleleft()
  197. end
  198. function manual()
  199. clearterm()
  200. startMessage()
  201. write("Fuel slot:")
  202. fuelslotnum = tonumber(read())
  203. usefuel(fuelslotnum)
  204. write("High:")
  205. high = tonumber(read())
  206. write("Width:")
  207. width = tonumber(read())
  208. write("Length")
  209. length = tonumber(read())
  210. clearterm()
  211. createterm()
  212. mine(high,width,length, fuelslotnum)
  213. end
  214. function createterm()
  215. term.setCursorPos(1,6)
  216. term.clearLine()
  217. print("------X Blocks left until end------")
  218. print("------X Fuellevel------")
  219. end
  220. function writeterm(msg,cursorlevel)
  221. cursorlevel = 6 + cursorlevel
  222. term.setCursorPos(1,cursorlevel)
  223. term.clearLine()
  224. print("------"..msg.."------")
  225. end
  226. function control()
  227. clearterm()
  228. startMessage()
  229. print("[p] = stop")
  230. print("[w] = forward")
  231. print("[f] = down")
  232. print("[r] = up")
  233. while true do
  234. local event, param1 = os.pullEvent("char")
  235. if param1 == "p" then
  236. break
  237. elseif param1 == "w" then
  238. goforward()
  239. elseif param1 == "d" then
  240. turtle.turnRight()
  241. elseif param1 == "a" then
  242. turtle.turnLeft()
  243. elseif param1 == "s" then
  244. turtle.back()
  245. elseif param1 == "f" then
  246. turtle.down()
  247. elseif param1 == "r" then
  248. turtle.up()
  249. end
  250. end
  251. end
  252. function path()
  253. clearterm()
  254. startMessage()
  255. createterm()
  256. mine(4,1,150,16)
  257. end
  258. function refuel()
  259. clearterm()
  260. startMessage()
  261. createterm()
  262. for i = 1,16 do
  263. if turtle.getItemCount(i) > 0 then
  264. for j = 1,turtle.getItemCount(i) do
  265. usefuel(i)
  266. writeterm("", 0)
  267. writeterm(turtle.getFuelLevel().." Fuellevel", 1)
  268. end
  269. end
  270. end
  271. end
  272. function mainmenu()
  273. print("Choose Program:")
  274. print("[X path of pain]")
  275. print(" Manual ")
  276. print(" Control Turtle ")
  277. print(" Refuel ")
  278. print()
  279. print("------"..turtle.getFuelLevel().." Fuellevel------")
  280. while true do
  281. local event1, param2 = os.pullEvent("key")
  282. if param2 == 200 then
  283. selectcounter = selectcounter - 1
  284. changeSelector(selectcounter)
  285. elseif param2 == 208 then
  286. selectcounter = selectcounter + 1
  287. changeSelector(selectcounter)
  288. elseif param2 == 28 then
  289. if selectcounter == 0 then
  290. path()
  291. elseif selectcounter == 1 then
  292. manual()
  293. elseif selectcounter == 2 then
  294. control()
  295. elseif selectcounter == 3 then
  296. refuel()
  297. end
  298. end
  299. end
  300. end
  301. function changeSelector(selectcounter)
  302. if selectcounter < 0 then
  303. selectcounter = maxprogram
  304. elseif selectcounter > maxprogram then
  305. selectcounter = 0
  306. end
  307. if selectcounter == 0 then
  308. term.setCursorPos(1,3)
  309. term.clearLine()
  310. print("[X path of pain]")
  311. term.setCursorPos(1,4)
  312. term.clearLine()
  313. print(" Manual ")
  314. term.setCursorPos(1,5)
  315. term.clearLine()
  316. print(" Control Turtle ")
  317. term.setCursorPos(1,6)
  318. term.clearLine()
  319. print(" Refuel ")
  320. elseif selectcounter == 1 then
  321. term.setCursorPos(1,3)
  322. term.clearLine()
  323. print(" X path of pain ")
  324. term.setCursorPos(1,4)
  325. term.clearLine()
  326. print("[Manual]")
  327. term.setCursorPos(1,5)
  328. term.clearLine()
  329. print(" Control Turtle ")
  330. term.setCursorPos(1,6)
  331. term.clearLine()
  332. print(" Refuel ")
  333. elseif selectcounter == 2 then
  334. term.setCursorPos(1,3)
  335. term.clearLine()
  336. print(" X path of pain ")
  337. term.setCursorPos(1,4)
  338. term.clearLine()
  339. print(" Manual ")
  340. term.setCursorPos(1,5)
  341. term.clearLine()
  342. print("[Control Turtle]")
  343. term.setCursorPos(1,6)
  344. term.clearLine()
  345. print(" Refuel ")
  346. elseif selectcounter == 3 then
  347. term.setCursorPos(1,3)
  348. term.clearLine()
  349. print(" X path of pain ")
  350. term.setCursorPos(1,4)
  351. term.clearLine()
  352. print(" Manual ")
  353. term.setCursorPos(1,5)
  354. term.clearLine()
  355. print(" Control Turtle ")
  356. term.setCursorPos(1,6)
  357. term.clearLine()
  358. print("[Refuel]")
  359. end
  360. end
  361. function mine(high, width, length, fuelslotnum)
  362. l = 0
  363. fullblocksize = high * width * length
  364. for i = 1, high do
  365. for j = 1, width do
  366. for k = 1, length do
  367. if turtle.refuel(1) == true then
  368. usefuel(fuelslotnum)
  369. end
  370. turtledig()
  371. goforward()
  372. end
  373. if j < width then
  374. l = l + 1
  375. if l < 2 then
  376. turnright()
  377. else
  378. turnleft()
  379. l = 0
  380. end
  381. end
  382. end
  383. turtledigup()
  384. turtleup()
  385. turtleleft()
  386. turtleleft()
  387. end
  388. findBack(0,0,0,0)
  389. end
  390. clearterm()
  391. startMessage()
  392. mainmenu()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement