Xgamer911

BridgeBuilder

Jun 12th, 2013
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.42 KB | None | 0 0
  1. -- slots 1-8 Sand
  2. -- slots 9-12 cobblestone
  3. -- slot 13 empty
  4. -- slot 14 cobblestone
  5. -- slot 15 sand
  6. -- slot 16 coal
  7.  
  8. local w,h = term.getSize()
  9. local selection = 0
  10. local internalselection = 0
  11. local range = 0
  12. local currentrange = 0
  13. local ypos = 1
  14. local fuel
  15. local fuelava
  16. local counter = 1
  17. local sandcounter=0
  18. local cobblecounter=0
  19.  
  20. --Some draw functions to get us started
  21. local function printCentered(str, ypos)
  22. term.setCursorPos(w/2 - #str/2, ypos)
  23. term.write(str)
  24. end
  25.  
  26. local function printFarLeft(str, ypos)
  27. term.setCursorPos(1, ypos)
  28. term.write(str)
  29. end
  30.  
  31. local function printLeft(str, ypos)
  32. term.setCursorPos(5, ypos)
  33. term.write(str)
  34. end
  35.  
  36. local function printLeft2(str, ypos)
  37. term.setCursorPos(10, ypos)
  38. term.write(str)
  39. end
  40.  
  41. local function printRight(str, ypos)
  42. term.setCursorPos(w - 15, ypos)
  43. term.write(str)
  44. end
  45.  
  46. local function printRight2(str, ypos)
  47. term.setCursorPos(w - 25, ypos)
  48. term.write(str)
  49. end
  50.  
  51. local function printFarRight(str, ypos)
  52. term.setCursorPos(w - #str, ypos)
  53. term.write(str)
  54. end
  55.  
  56. function drawHeader()
  57. printCentered("Turtle Bridge Builder", 1)
  58. printCentered(string.rep("-", w+1), 2)
  59.  
  60. -- print fuel level
  61. fuel = turtle.getFuelLevel()
  62. printFarLeft("Fuel " ,3)
  63. print(fuel)
  64.  
  65. -- print avilable fuel
  66. fuelava = turtle.getItemCount(16)
  67. printFarLeft("Fuel Available " ,5)
  68. print(fuelava)
  69.  
  70. -- print avilable fuel
  71. sandcounter = turtle.getItemCount(1) + turtle.getItemCount(2) + turtle.getItemCount(3) + turtle.getItemCount(4) + turtle.getItemCount(5) + turtle.getItemCount(6) + turtle.getItemCount(7) + turtle.getItemCount(8)
  72. printRight("Sand left "..tostring(sandcounter),3)
  73.  
  74. -- print avilable fuel
  75. cobblecounter = turtle.getItemCount(9) + turtle.getItemCount(10) + turtle.getItemCount(11) + turtle.getItemCount(12)
  76. printRight("Cobble left "..tostring(cobblecounter),4)
  77.  
  78. -- Print Range
  79. printRight("Range Left "..tostring(range),5)
  80. end
  81.  
  82. function drawMainMenu()
  83. printLeft2("1. Forward", 7)
  84. printRight("5. Up", 7)
  85.  
  86. printLeft2("2. Backward", 8)
  87. printRight("6. Down", 8)
  88.  
  89. printLeft2("3. Left", 9)
  90. printRight("7. Start bridge", 9)
  91.  
  92. printLeft2("4. Right", 10)
  93. printRight("8. Quit", 10)
  94.  
  95. printLeft2("Selection: ", 12)
  96. selection = tonumber(read())
  97. end
  98.  
  99. function forward()
  100. term.clear()
  101. term.setCursorPos(1,1)
  102. internalselection=0
  103. drawHeader()
  104.  
  105. printLeft("Forward", 7)
  106. printLeft("-------", 8)
  107. printLeft("1. Forward 1", 9)
  108. printRight("3. Main Menu", 9)
  109. printLeft("2. Forward range", 10)
  110.  
  111. printLeft("Selection: ", 12)
  112. internalselection = tonumber(read())
  113.  
  114. if internalselection==1 then
  115. turtle.forward()
  116. term.clear()
  117. term.setCursorPos(1,1)
  118. end
  119.  
  120. if internalselection==2 then
  121. term.clear()
  122. term.setCursorPos(1,1)
  123.  
  124. drawHeader()
  125.  
  126. printLeft("Forward Range", 7)
  127. printLeft("-------------", 8)
  128. printLeft("How far: ", 9)
  129. currentrange = 0
  130. range = tonumber(read())
  131.  
  132. repeat
  133. term.clear()
  134. term.setCursorPos(1,1)
  135. drawHeader()
  136.  
  137. turtle.forward()
  138. currentrange = currentrange + 1
  139. until currentrange == range
  140.  
  141. range=0
  142. end
  143. end
  144.  
  145. function backward()
  146. term.clear()
  147. term.setCursorPos(1,1)
  148. internalselection=0
  149. drawHeader()
  150.  
  151. printLeft("Backward", 7)
  152. printLeft("--------", 8)
  153. printLeft("1. Backward 1", 9)
  154. printRight("3. Main Menu", 9)
  155. printLeft("2. Backward range", 10)
  156.  
  157. printLeft("Selection: ", 12)
  158. internalselection = tonumber(read())
  159.  
  160. if internalselection==1 then
  161. turtle.back()
  162. term.clear()
  163. term.setCursorPos(1,1)
  164. end
  165.  
  166. if internalselection==2 then
  167. term.clear()
  168. term.setCursorPos(1,1)
  169.  
  170. drawHeader()
  171.  
  172. printLeft("Backward Range", 7)
  173. printLeft("-------------", 8)
  174. printLeft("How far: ", 9)
  175. currentrange = 0
  176. range = tonumber(read())
  177.  
  178. repeat
  179. term.clear()
  180. term.setCursorPos(1,1)
  181. drawHeader()
  182.  
  183. turtle.back()
  184. currentrange = currentrange + 1
  185. until currentrange == range
  186.  
  187. range=0
  188. end
  189.  
  190. if internalselection==3 then
  191. term.clear()
  192. term.setCursorPos(1,1)
  193. internalselection=0
  194. selection=0
  195. main()
  196. end
  197. end
  198.  
  199. function up()
  200. term.clear()
  201. term.setCursorPos(1,1)
  202. internalselection=0
  203. drawHeader()
  204.  
  205. printLeft("Up", 7)
  206. printLeft("--", 8)
  207. printLeft("1. Up 1", 9)
  208. printRight("3. Main Menu", 9)
  209. printLeft("2. Up range", 10)
  210.  
  211. printLeft("Selection: ", 12)
  212. internalselection = tonumber(read())
  213.  
  214. if internalselection==1 then
  215. turtle.up()
  216. term.clear()
  217. term.setCursorPos(1,1)
  218. end
  219.  
  220. if internalselection==2 then
  221. term.clear()
  222. term.setCursorPos(1,1)
  223.  
  224. drawHeader()
  225.  
  226. printLeft("Up Range", 7)
  227. printLeft("--------", 8)
  228. printLeft("How far: ", 9)
  229. currentrange = 0
  230. range = tonumber(read())
  231.  
  232. repeat
  233. term.clear()
  234. term.setCursorPos(1,1)
  235. drawHeader()
  236.  
  237. turtle.up()
  238. currentrange = currentrange + 1
  239. until currentrange == range
  240.  
  241. range=0
  242. end
  243.  
  244. if internalselection==3 then
  245. term.clear()
  246. term.setCursorPos(1,1)
  247. internalselection=0
  248. selection=0
  249. main()
  250. end
  251. end
  252.  
  253. function down()
  254. term.clear()
  255. term.setCursorPos(1,1)
  256. internalselection=0
  257. drawHeader()
  258.  
  259. printLeft("Down", 7)
  260. printLeft("----", 8)
  261. printLeft("1. Down 1", 9)
  262. printRight("3. Main Menu", 9)
  263. printLeft("2. Down range", 10)
  264.  
  265. printLeft("Selection: ", 12)
  266. internalselection = tonumber(read())
  267.  
  268. if internalselection==1 then
  269. turtle.down()
  270. term.clear()
  271. term.setCursorPos(1,1)
  272. end
  273.  
  274. if internalselection==2 then
  275. term.clear()
  276. term.setCursorPos(1,1)
  277.  
  278. drawHeader()
  279.  
  280. printLeft("Down Range", 7)
  281. printLeft("----------", 8)
  282. printLeft("How far: ", 9)
  283. currentrange = 0
  284. range = tonumber(read())
  285.  
  286. repeat
  287. term.clear()
  288. term.setCursorPos(1,1)
  289. drawHeader()
  290.  
  291. turtle.down()
  292. currentrange = currentrange + 1
  293. until currentrange == range
  294.  
  295. range=0
  296. end
  297.  
  298. if internalselection==3 then
  299. term.clear()
  300. term.setCursorPos(1,1)
  301. internalselection=0
  302. selection=0
  303. main()
  304. end
  305. end
  306.  
  307. function startbridge()
  308. term.clear()
  309. term.setCursorPos(1,1)
  310. internalselection=0
  311. drawHeader()
  312.  
  313. printLeft("Starting Bridge", 7)
  314. printLeft("---------------", 8)
  315. printLeft("1. Bridge by 1", 9)
  316. printRight("3. Main Menu", 9)
  317. printLeft("2. Bridge range", 10)
  318.  
  319. printLeft("Selection: ", 12)
  320. internalselection = tonumber(read())
  321.  
  322. if internalselection==1 then
  323. turtle.forward()
  324. while true do
  325.  
  326. turtle.select(1)
  327. turtle.placeDown()
  328.  
  329. turtle.select(1)
  330. if turtle.compareTo(13) then
  331. turtle.select(8)
  332. turtle.transferTo(1, 64)
  333. turtle.select(7)
  334. turtle.transferTo(1, 64)
  335. turtle.select(6)
  336. turtle.transferTo(1, 64)
  337. turtle.select(5)
  338. turtle.transferTo(1, 64)
  339. turtle.select(4)
  340. turtle.transferTo(1, 64)
  341. turtle.select(3)
  342. turtle.transferTo(1, 64)
  343. turtle.select(2)
  344. turtle.transferTo(1, 64)
  345. end
  346.  
  347. turtle.select(9)
  348. if turtle.compareTo(13) then
  349. turtle.select(12)
  350. turtle.transferTo(9, 64)
  351. turtle.select(11)
  352. turtle.transferTo(9, 64)
  353. turtle.select(10)
  354. turtle.transferTo(9, 64)
  355. end
  356.  
  357. if turtle.detectDown() then
  358. turtle.digDown()
  359. turtle.select(9)
  360. turtle.placeDown()
  361. break
  362. end
  363. end
  364.  
  365. term.clear()
  366. term.setCursorPos(1,1)
  367. end
  368.  
  369. if internalselection==2 then
  370. term.clear()
  371. term.setCursorPos(1,1)
  372.  
  373. drawHeader()
  374.  
  375. printLeft("Bridge Length", 7)
  376. printLeft("----------", 8)
  377. printLeft("How far: ", 9)
  378. currentrange = 0
  379. range = tonumber(read())
  380.  
  381. repeat
  382. term.clear()
  383. term.setCursorPos(1,1)
  384. drawHeader()
  385. turtle.forward()
  386. while true do
  387. turtle.select(1)
  388. turtle.placeDown()
  389.  
  390. turtle.select(1)
  391. if turtle.compareTo(13) then
  392. turtle.select(8)
  393. turtle.transferTo(1, 64)
  394. turtle.select(7)
  395. turtle.transferTo(1, 64)
  396. turtle.select(6)
  397. turtle.transferTo(1, 64)
  398. turtle.select(5)
  399. turtle.transferTo(1, 64)
  400. turtle.select(4)
  401. turtle.transferTo(1, 64)
  402. turtle.select(3)
  403. turtle.transferTo(1, 64)
  404. turtle.select(2)
  405. turtle.transferTo(1, 64)
  406. end
  407.  
  408. turtle.select(9)
  409. if turtle.compareTo(13) then
  410. turtle.select(12)
  411. turtle.transferTo(9, 64)
  412. turtle.select(11)
  413. turtle.transferTo(9, 64)
  414. turtle.select(10)
  415. turtle.transferTo(9, 64)
  416. end
  417.  
  418. if turtle.detectDown() then
  419. turtle.digDown()
  420. turtle.select(9)
  421. turtle.placeDown()
  422. break
  423. end
  424. end
  425. currentrange = currentrange + 1
  426. until currentrange == range
  427. end
  428.  
  429. if internalselection==3 then
  430. term.clear()
  431. term.setCursorPos(1,1)
  432. internalselection=0
  433. selection=0
  434. main()
  435. end
  436. end
  437.  
  438. function main()
  439. --PROGRAM START
  440. term.clear()
  441. term.setCursorPos(1,1)
  442.  
  443. while true do
  444. drawHeader()
  445. drawMainMenu()
  446.  
  447. if fuel < 5 then
  448. turtle.select(16)
  449. turtle.refuel(1)
  450. turtle.select(1)
  451. end
  452.  
  453. if selection==1 then
  454. forward()
  455. end
  456.  
  457. if selection==2 then
  458. backward()
  459. end
  460.  
  461. if selection==3 then
  462. turtle.turnLeft()
  463. term.clear()
  464. term.setCursorPos(1,1)
  465. end
  466.  
  467. if selection==4 then
  468. turtle.turnRight()
  469. term.clear()
  470. term.setCursorPos(1,1)
  471. end
  472.  
  473. if selection==5 then
  474. up()
  475. end
  476.  
  477. if selection==6 then
  478. down()
  479. end
  480.  
  481. if selection==7 then
  482. startbridge()
  483. end
  484.  
  485. if selection==8 then
  486. term.clear()
  487. term.setCursorPos(1,1)
  488. break
  489. end
  490.  
  491. end
  492. end
  493.  
  494. main()
Advertisement
Add Comment
Please, Sign In to add comment