ToaLetan

Mining Turtle - Stairs

Feb 17th, 2020 (edited)
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.41 KB | None | 0 0
  1. local width = 1
  2. local depth = 1
  3. local height = 4
  4. local upDown = ''
  5.  
  6. --Handy movement functions
  7. local function upBy(num)
  8. for i=1, num do
  9. turtle.up()
  10. end
  11. end
  12. local function downBy(num)
  13. for i=1, num do
  14. turtle.down()
  15. end
  16. end
  17. local function leftBy(num)
  18. turtle.turnLeft()
  19. for i=1, num do
  20. turtle.forward()
  21. end
  22. turtle.turnRight()
  23. end
  24. local function rightBy(num)
  25. turtle.turnRight()
  26. for i=1, num do
  27. turtle.forward()
  28. end
  29. turtle.turnLeft()
  30. end
  31.  
  32. local function digHeight()
  33. for i=1, height do
  34. turtle.dig()
  35. turtle.digUp()
  36. turtle.up()
  37. end
  38. end
  39.  
  40. local function stairsDown()
  41. print("Witness me make a fine staircase that's " .. width .. " tiles wide, " .. height+1 .. " tiles tall, and goes down for " .. depth .. " levels");
  42. for d=1, depth do
  43. digHeight()
  44. downBy(height)
  45. -- Dig the horizontal width
  46. for i=1, width-1 do
  47. turtle.turnRight()
  48. turtle.dig()
  49. turtle.forward()
  50. turtle.turnLeft()
  51. turtle.dig()
  52. digHeight()
  53. downBy(height)
  54. end
  55. turtle.forward()
  56. -- Dig blocks beneath the horizontal width
  57. for j=1, width do
  58. turtle.digDown()
  59. turtle.turnLeft()
  60. turtle.forward()
  61. turtle.turnRight()
  62. end
  63. turtle.down()
  64. end
  65. end
  66.  
  67. local function stairsUp()
  68. print("Witness me make a fine staircase that's " .. width .. " tiles wide, " .. height+1 .. " tiles tall, and goes up for " .. depth .. " levels");
  69. for d=1, depth do
  70. digHeight()
  71. downBy(height)
  72. -- Dig the horizontal width
  73. for i=1, width-1 do
  74. turtle.turnRight()
  75. turtle.dig()
  76. turtle.forward()
  77. turtle.turnLeft()
  78. turtle.dig()
  79. digHeight()
  80. downBy(height)
  81. end
  82. turtle.forward()
  83. -- Dig blocks beneath the horizontal width
  84. for j=1, width do
  85. turtle.digUp()
  86. turtle.turnLeft()
  87. turtle.forward()
  88. turtle.turnRight()
  89. end
  90. turtle.up()
  91. end
  92. end
  93.  
  94. function main()
  95. if turtle.getFuelLevel() <= 0 then
  96. print("WARNING: Fuel is empty!")
  97. end
  98.  
  99. print("Enter staircase width:")
  100. width = tonumber(read())
  101. print("Enter staircase height:")
  102. height = tonumber(read())
  103. print("Enter staircase depth:")
  104. depth = tonumber(read())
  105. print("Stairs up or down? (U/D)")
  106. upDown = tostring(read())
  107.  
  108. if string.find(upDown, 'u') or string.find(upDown, 'U') then
  109. stairsUp()
  110. elseif string.find(upDown, 'd') or string.find(upDown, 'D') then
  111. stairsDown()
  112. else
  113. print("ERROR: Invalid input, cancelling mining operation.")
  114. end
  115.  
  116. end
  117. main()
Advertisement
Add Comment
Please, Sign In to add comment