Advertisement
Guest User

stairmine

a guest
Sep 26th, 2014
2,744
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.91 KB | None | 0 0
  1. -- Programmed: 17 May 2014
  2. -- by Skyler James
  3. --
  4. -- Digs stairs <width> wide
  5. -- and <length> long, placing
  6. -- blocks underneath it as
  7. -- needed (ensures you can
  8. -- always get to your turtle)
  9. --
  10. -- The most important functions
  11. -- are digstair and digxsides
  12.  
  13.  
  14. local tArgs = { ... }
  15. if #tArgs ~= 2 then
  16. print( "Usage: stairmine <width> <length>" )
  17. return
  18. end
  19.  
  20. -- Set width of stairs with user input
  21. local width = tonumber( tArgs[1] )
  22. if width < 1 or width > 3 then
  23. print( "Stair width must be between 1 and 3, inclusive" )
  24. return
  25. end
  26.  
  27. -- Set length of stairs with user input
  28. local length = tonumber( tArgs[2] )
  29. if length < 1 then
  30. print( "Stair length must be positive" )
  31. return
  32. end
  33.  
  34. -- Dig, then wait in case
  35. -- gravel / sand falls
  36. function digfront()
  37. while turtle.detect() do
  38. turtle.dig()
  39. sleep(0.65)
  40. end
  41. end
  42.  
  43. -- If width is 3 dig
  44. -- both sides of turtle
  45. function dig2sides()
  46. turtle.turnRight()
  47. digfront()
  48. turtle.turnLeft()
  49. turtle.turnLeft()
  50. digfront()
  51. turtle.turnRight()
  52. end
  53.  
  54. -- If width is 2 dig
  55. -- right side of turtle
  56. function dig1side()
  57. turtle.turnRight()
  58. digfront()
  59. turtle.turnLeft()
  60. end
  61.  
  62. -- Dig, then wait in case
  63. -- sand / gravel falls
  64. function digup()
  65. while turtle.detectUp() do
  66. turtle.digUp()
  67. sleep(0.65)
  68. end
  69. end
  70.  
  71. -- Decide which digside
  72. -- function to call based
  73. -- on user input
  74. function digxsides()
  75. if width == 3 then
  76. dig2sides()
  77. elseif width == 2 then
  78. dig1side()
  79. end
  80. end
  81.  
  82. -- If there is nothing under the turtle,
  83. -- it will place a block. Very prone
  84. -- to bugs, but not needed often
  85. -- Will only build bridge / stairs
  86. -- 1 block wide, but it works
  87. function putblockifneeded()
  88. -- first, of course, check
  89. -- if a block is needed
  90. if not (turtle.detectDown()) then
  91. local highestcount = 0
  92. local slotwithmost = 0
  93. local tempnum = 0
  94.  
  95. -- iterate through 9 slots
  96. -- and find which one has
  97. -- the most blocks. That
  98. -- slot is most likely
  99. -- dirt or cobblestone.
  100. for i = 1,9,1 do
  101. tempnum = turtle.getItemCount(i)
  102. if tempnum > highestcount then
  103. slotwithmost = i
  104. highestcount = tempnum
  105. end
  106. end
  107.  
  108. -- double check that there
  109. -- are any blocks to use.
  110. -- If yes, place one.
  111. turtle.select(slotwithmost)
  112. if highestcount > 0 then
  113. turtle.placeDown()
  114. else
  115. return
  116. end
  117. end
  118. end
  119.  
  120. -- Move the turtle in a stair
  121. -- mining pattern, digging a
  122. -- ceiling 4 blocks high and
  123. -- calling digxsides as needed
  124. function digstair()
  125. digxsides()
  126. digup()
  127. turtle.digDown()
  128. turtle.up()
  129. digxsides()
  130. digup()
  131. turtle.up()
  132. digxsides()
  133. turtle.down()
  134. turtle.down()
  135. turtle.down()
  136. putblockifneeded()
  137. digxsides()
  138. end
  139.  
  140.  
  141. -- user input is not faulty,
  142. -- so begin mining stairs
  143. -- <length> blocks deep
  144. print("Mining stairs . . .")
  145. for i = 1,length,1 do
  146. digfront()
  147. turtle.forward()
  148. digstair()
  149. print("Mined "..i.." stairs")
  150. end
  151.  
  152. -- That's all, folks!
  153. return
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement