King-Skyline

customtunnel

Sep 8th, 2023
19
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. -- Advanced Tunnel by Henness
  2. -- Version 1.3.4 1/4/2013
  3.  
  4. -- Config
  5. Version = "v1.3.4"
  6. HeightQuestion = true
  7. WidthQuestion = true
  8. LengthQuestion = true
  9. TorchesQuestion = true
  10.  
  11. -- Functions
  12. function version() -- Version function
  13. return Version
  14. end
  15.  
  16. function clearscreen() -- Clearscreen function
  17. term.clear()
  18. regwrite( "Advanced Tunnel", 12, 1 )
  19. regwrite( version(), 2, 12 )
  20. regwrite( "Designed by Henness", 17, 12 )
  21. term.setCursorPos( 1, 3 )
  22. end
  23.  
  24. function regwrite(string, columnVar, rowVar) -- Write a string to the cords
  25. term.setCursorPos( columnVar, rowVar )
  26. write (string)
  27. end
  28.  
  29. function arcwrite(number, columnVar, rowVar) -- Write a number "right to left" to the cords
  30. digits = math.ceil(math.log10(number))
  31. if 10^digits == number then
  32. digits = digits + 1
  33. end
  34. term.setCursorPos( columnVar, rowVar )
  35. while digits > 1 do
  36. digits = digits - 1
  37. columnVar = columnVar - 1
  38. term.setCursorPos( columnVar, rowVar )
  39. end
  40. write (number)
  41. end
  42.  
  43. function createtable() -- Make a table function
  44. clearscreen()
  45. print ( [[
  46. +--------------------------------+
  47. |Blocks Mined: 0 |
  48. |Torches Placed: 0 |
  49. +--------------------------------+
  50. | Status |
  51. |[ ]|
  52. | 0% |
  53. +--------------------------------+
  54. ]] )
  55. placedValue = 0
  56. minedValue = 0
  57. end
  58.  
  59. function updatetable() -- Update the table
  60. -- Update Blocks Mined
  61. minedValue = minedValue + 1
  62. arcwrite(minedValue, 33, 4)
  63.  
  64. -- Update Percentage
  65. if length > 0 then
  66. area = (height * width * length)
  67. else
  68. area = minedValue
  69. end
  70. percentage = math.ceil((minedValue / area) * 100)
  71. arcwrite(percentage, 19, 9)
  72.  
  73. -- Update Percentage Bar
  74. percentageBar = math.floor(percentage * 0.3)
  75. columnVar = 4
  76. while percentageBar > 0 do
  77. regwrite( "=", columnVar, 8 )
  78. percentageBar = percentageBar - 1
  79. columnVar = columnVar + 1
  80. end
  81. end
  82.  
  83. function placetorch() -- Place a torch
  84. if torches == true then
  85. if lengthSpacingVar == 0 and ( spaceFromWallVar == 0 or widthSpacingVar == 0 ) then
  86. turtle.placeDown()
  87. if turtle.getItemCount(1) == 0 then
  88. noTorches = true
  89. end
  90. spaceFromWallVar = -1
  91. widthSpacingVar = widthSpacing
  92. -- Update Torches Placed
  93. placedValue = placedValue + 1
  94. arcwrite(placedValue, 33, 5)
  95. else
  96. spaceFromWallVar = spaceFromWallVar - 1
  97. widthSpacingVar = widthSpacingVar - 1
  98. end
  99. end
  100. end
  101.  
  102. function widthtest() -- Test width for numbers that = 4+10n
  103. widthTestVar = width
  104. while widthTestVar > 4 do
  105. widthTestVar = widthTestVar - 10
  106. end
  107. if widthTestVar == 4 then
  108. return true
  109. end
  110. end
  111.  
  112. function setspacing() -- Calculate spacing of torches
  113. if width < 6 then
  114. if math.fmod( width, 2 ) == 0 then -- If even
  115. if width == 2 then
  116. lengthSpacing = 9
  117. spaceFromWall = ( 1 + ( -1 )^placedValue ) / 2
  118. else
  119. lengthSpacing = 7
  120. spaceFromWall = (( 1 + ( -1 )^placedValue ) / 2 ) + 1
  121. end
  122. else -- If odd
  123. spaceFromWall = math.floor( width / 2 )
  124. if width == 5 then
  125. lengthSpacing = 6
  126. elseif width == 3 then
  127. lengthSpacing = 8
  128. else
  129. lengthSpacing = 10
  130. end
  131. end
  132. widthSpacing = -1
  133. else
  134. if math.fmod( width, 2 ) == 0 then -- If even
  135. widthSpacing = 4
  136. lengthSpacing = 4
  137. if widthtest() == true or width == 6 then
  138. spaceFromWall = 0
  139. else
  140. spaceFromWallVar = width
  141. while spaceFromWallVar > 7 do
  142. spaceFromWallVar = spaceFromWallVar - ( widthSpacing + 1 )
  143. end
  144. spaceFromWall = ( spaceFromWallVar - 1 ) / 2
  145. end
  146. else -- If odd
  147. widthSpacing = 5
  148. lengthSpacing = 4
  149. if width == 7 then
  150. spaceFromWall = 0
  151. else
  152. spaceFromWallVar = width
  153. while spaceFromWallVar > 7 do
  154. spaceFromWallVar = spaceFromWallVar - ( widthSpacing + 1 )
  155. end
  156. spaceFromWall = ( spaceFromWallVar - 1 ) / 2
  157. end
  158. end
  159. end
  160. spaceFromWallVar = spaceFromWall
  161. widthSpacingVar = widthSpacing
  162. lengthSpacingVar = lengthSpacing
  163. end
  164.  
  165. function digdown() -- Dig down and update the table
  166. if turtle.detectDown() then
  167. turtle.digDown()
  168. end
  169. updatetable()
  170. end
  171.  
  172. function digup() -- Dig up and update the table
  173. while turtle.detectUp() do
  174. turtle.digUp()
  175. sleep(0.5)
  176. end
  177. updatetable()
  178. end
  179.  
  180. function digforward() -- Dig forward and update the table
  181. local moved = moveforward()
  182. if not moved and turtle.detect() then
  183. repeat turtle.dig() until moveforward()
  184. local moved = true
  185. elseif not moved and not turtle.detect() then
  186. repeat turtle.attack() until moveforward()
  187. end
  188. updatetable()
  189. end
  190.  
  191. function moveforward() -- Move forward
  192. return turtle.forward()
  193. end
  194.  
  195. function largetunnel() -- Mine a tunnel larger then one wide
  196. widthvar = width - 1
  197. while widthvar > 0 do
  198. if tunnelheight == 1 then
  199. digdown()
  200. placetorch()
  201. moveforward()
  202. end
  203. if tunnelheight == 2 then
  204. digdown()
  205. placetorch()
  206. digforward()
  207. end
  208. if tunnelheight == 3 then
  209. digup()
  210. digdown()
  211. placetorch()
  212. digforward()
  213. end
  214. if tunnelheight > 3 then
  215. digup()
  216. digdown()
  217. digforward()
  218. end
  219. widthvar = widthvar - 1
  220. end
  221. if tunnelheight == 1 then
  222. digdown()
  223. tunnelheight = tunnelheight - 1
  224. elseif tunnelheight == 2 then
  225. digdown()
  226. tunnelheight = tunnelheight - 2
  227. elseif tunnelheight == 3 then
  228. digup()
  229. digdown()
  230. tunnelheight = tunnelheight - 3
  231. else
  232. digup()
  233. digdown()
  234. tunnelheight = tunnelheight - 3
  235. if tunnelheight == 1 then
  236. turtle.down()
  237. end
  238. if tunnelheight == 2 then
  239. turtle.down()
  240. digdown()
  241. turtle.down()
  242. end
  243. if tunnelheight >= 3 then
  244. turtle.down()
  245. digdown()
  246. turtle.down()
  247. digdown()
  248. turtle.down()
  249. end
  250. end
  251. end
  252.  
  253. function smalltunnel() -- Mine a one wide tunnel
  254. if tunnelheight == 2 then
  255. digdown()
  256. end
  257. if tunnelheight == 3 then
  258. digup()
  259. digdown()
  260. end
  261. if tunnelheight > 3 then
  262. digup()
  263. digdown()
  264. turtle.down()
  265. tunnelheight = tunnelheight - 3
  266. while tunnelheight > 1 do
  267. digdown()
  268. turtle.down()
  269. tunnelheight = tunnelheight - 1
  270. end
  271. digdown()
  272. end
  273. placetorch()
  274. end
  275.  
  276. -- Questions
  277. clearscreen()
  278. while HeightQuestion == true do -- Height Question
  279. print("Height of tunnel?")
  280. height = tonumber(read())
  281. clearscreen()
  282. if height == nil then
  283. print( "Please answer with a number." )
  284. elseif height >= 2 then
  285. HeightQuestion = false
  286. startheight = height - 3
  287. elseif height == 1 then
  288. print( "The tunnel height must be larger than one." )
  289. elseif height == 0 then
  290. print( "The tunnel height can't be infinite." )
  291. else
  292. print( "The tunnel height must be positive." )
  293. end
  294. end
  295.  
  296. clearscreen()
  297. while WidthQuestion == true do -- Width Question
  298. print("Width of tunnel?")
  299. width = tonumber(read())
  300. clearscreen()
  301. if width == nil then
  302. print( "Please answer with a number." )
  303. elseif width > 0 then
  304. WidthQuestion = false
  305. elseif width == 0 then
  306. print( "The tunnel width can't be infinite." )
  307. else
  308. print( "The tunnel width must be positive." )
  309. end
  310. end
  311.  
  312. clearscreen()
  313. while LengthQuestion == true do -- Length Question
  314. print("Length of tunnel?")
  315. length = tonumber(read())
  316. clearscreen()
  317. if length == nil then
  318. print( "Please answer with a number." )
  319. elseif length > 0 then
  320. LengthQuestion = false
  321. lengthVar = 0
  322. elseif length == 0 then
  323. LengthQuestion = false
  324. Infinitelength = true
  325. TorchesQuestion = false
  326. TorchSpacingQuestion = false
  327. lengthVar = (-1)
  328. else
  329. print( "The tunnel length must be positive." )
  330. end
  331. end
  332.  
  333. clearscreen()
  334. while TorchesQuestion == true do -- Torch Question
  335. print("Place torches?")
  336. light = string.lower(read())
  337. clearscreen()
  338. if light == ( 'yes' ) then
  339. if turtle.getItemCount(1) == 0 then
  340. print("Please place torches in the first inventory slot.")
  341. else
  342. torches = true
  343. TorchesQuestion = false
  344. noTorches = false
  345. setspacing()
  346. lengthSpacingVar = 0
  347. end
  348. elseif light == ( 'no' ) then
  349. torches = false
  350. TorchesQuestion = false
  351. else
  352. print("Please answer yes or no.")
  353. end
  354. end
  355.  
  356. -- Create the gui
  357. createtable()
  358.  
  359. -- Mining Loop
  360. turtle.up()
  361. while startheight > 0 do
  362. local moved = turtle.up()
  363. if not moved and turtle.detectUp() then
  364. repeat turtle.digUp() until turtle.up()
  365. local moved = true
  366. elseif not moved and not turtle.detectUp() then
  367. repeat turtle.attackUp() until turtle.up()
  368. end
  369. startheight = startheight - 1
  370. end
  371. while lengthVar < length do
  372. lengthVar = lengthVar + 1
  373. digforward()
  374. if width > 1 then
  375. turtle.turnRight()
  376. end
  377.  
  378. -- Mine a one wide tunnel or a larger tunnel.
  379. tunnelheight = height
  380. if width > 1 then
  381. while tunnelheight > 0 do
  382. largetunnel()
  383. turtle.turnRight()
  384. turtle.turnRight()
  385. if tunnelheight > 0 then
  386. largetunnel()
  387. if tunnelheight > 0 then
  388. turtle.turnRight()
  389. turtle.turnRight()
  390. end
  391. else
  392. widthvar = width - 1
  393. while widthvar > 0 do
  394. moveforward()
  395. widthvar = widthvar - 1
  396. end
  397. end
  398. end
  399. else
  400. smalltunnel()
  401. end
  402. if torches == true then
  403. if lengthSpacingVar == 0 then
  404. spaceFromWallVar = spaceFromWall
  405. widthSpacingVar = widthSpacing
  406. lengthSpacingVar = lengthSpacing
  407. else
  408. spaceFromWallVar = spaceFromWall
  409. widthSpacingVar = widthSpacing
  410. lengthSpacingVar = lengthSpacingVar - 1
  411. end
  412. end
  413. startheight = height - 3
  414. while startheight > 0 do
  415. turtle.up()
  416. startheight = startheight - 1
  417. end
  418.  
  419. -- Infinite Length
  420. if Infinitelength == true then
  421. lengthVar = lengthVar - 1
  422. end
  423.  
  424. -- Stop or Continue
  425. if lengthVar == length or noTorches == true then
  426. if width > 1 then
  427. turtle.turnLeft()
  428. else
  429. turtle.turnRight()
  430. turtle.turnRight()
  431. end
  432. while lengthVar > 0 do
  433. moveforward()
  434. lengthVar = lengthVar - 1
  435. end
  436. while startheight < ( height - 3 ) do
  437. turtle.down()
  438. startheight = startheight + 1
  439. end
  440. turtle.turnLeft()
  441. turtle.turnLeft()
  442. lengthVar = length
  443. term.setCursorPos( 1, 11 )
  444. if noTorches == true then
  445. print ("Out of Torches!")
  446. else
  447. print ("Tunnel Complete!")
  448. end
  449. term.setCursorPos( 1, 2 )
  450. else
  451. if width > 1 then
  452. turtle.turnRight()
  453. end
  454. end
  455. end
Add Comment
Please, Sign In to add comment